Commit 992f73e2 authored by Hanno Schlichting's avatar Hanno Schlichting

flake8

parent bcaeb4ae
This diff is collapsed.
...@@ -773,7 +773,7 @@ class ObjectManager(CopyContainer, ...@@ -773,7 +773,7 @@ class ObjectManager(CopyContainer,
if (request.maybe_webdav_client and if (request.maybe_webdav_client and
method not in ('GET', 'POST')): method not in ('GET', 'POST')):
return NullResource(self, key, request).__of__(self) return NullResource(self, key, request).__of__(self)
raise KeyError, key raise KeyError(key)
def __setitem__(self, key, value): def __setitem__(self, key, value):
return self._setObject(key, value) return self._setObject(key, value)
......
This diff is collapsed.
...@@ -18,6 +18,7 @@ This module can also be used as a simple template for implementing new ...@@ -18,6 +18,7 @@ This module can also be used as a simple template for implementing new
item types. item types.
""" """
import logging
import marshal import marshal
import re import re
import sys import sys
...@@ -59,9 +60,9 @@ from OFS.CopySupport import CopySource ...@@ -59,9 +60,9 @@ from OFS.CopySupport import CopySource
from OFS.role import RoleManager from OFS.role import RoleManager
from OFS.Traversable import Traversable from OFS.Traversable import Traversable
import logging
logger = logging.getLogger() logger = logging.getLogger()
class Item(Base, class Item(Base,
Resource, Resource,
CopySource, CopySource,
......
...@@ -204,7 +204,7 @@ class Traversable: ...@@ -204,7 +204,7 @@ class Traversable:
if name[0] == '_': if name[0] == '_':
# Never allowed in a URL. # Never allowed in a URL.
raise NotFound, name raise NotFound(name)
if name == '..': if name == '..':
next = aq_parent(obj) next = aq_parent(obj)
......
...@@ -42,7 +42,7 @@ the <em>browse</em> button to select a local file to upload. ...@@ -42,7 +42,7 @@ the <em>browse</em> button to select a local file to upload.
<td align="left" valign="top" colspan="2"> <td align="left" valign="top" colspan="2">
<div class="form-element"> <div class="form-element">
<dtml-if wl_isLocked> <dtml-if wl_isLocked>
<em>Locked by WebDAV</em> <em>Locked</em>
<dtml-else> <dtml-else>
<input class="form-element" type="submit" name="SUBMIT" value="Save Changes"> <input class="form-element" type="submit" name="SUBMIT" value="Save Changes">
</dtml-if> </dtml-if>
...@@ -74,7 +74,7 @@ the <em>browse</em> button to select a local file to upload. ...@@ -74,7 +74,7 @@ the <em>browse</em> button to select a local file to upload.
<td align="left" valign="top"> <td align="left" valign="top">
<div class="form-element"> <div class="form-element">
<dtml-if wl_isLocked> <dtml-if wl_isLocked>
<em>Locked by WebDAV</em> <em>Locked</em>
<dtml-else> <dtml-else>
<input class="form-element" type="submit" value="Upload File"> <input class="form-element" type="submit" value="Upload File">
</dtml-if> </dtml-if>
......
...@@ -87,7 +87,7 @@ text type and small enough to be edited in a text area. ...@@ -87,7 +87,7 @@ text type and small enough to be edited in a text area.
<td align="left" valign="top"> <td align="left" valign="top">
<div class="form-element"> <div class="form-element">
<dtml-if wl_isLocked> <dtml-if wl_isLocked>
<em>Locked by WebDAV</em> <em>Locked</em>
<dtml-else> <dtml-else>
<input class="form-element" type="submit" name="manage_edit:method" <input class="form-element" type="submit" name="manage_edit:method"
value="Save Changes"> value="Save Changes">
...@@ -114,7 +114,7 @@ text type and small enough to be edited in a text area. ...@@ -114,7 +114,7 @@ text type and small enough to be edited in a text area.
<td align="left" valign="top"> <td align="left" valign="top">
<div class="form-element"> <div class="form-element">
<dtml-if wl_isLocked> <dtml-if wl_isLocked>
<em>Locked by WebDAV</em> <em>Locked</em>
<dtml-else> <dtml-else>
<input class="form-element" type="submit" name="manage_upload:method" <input class="form-element" type="submit" name="manage_upload:method"
value="Upload"> value="Upload">
......
...@@ -70,7 +70,7 @@ button and click <em>upload</em> to update the contents of the &dtml-kind;. ...@@ -70,7 +70,7 @@ button and click <em>upload</em> to update the contents of the &dtml-kind;.
<td align="left" valign="top"> <td align="left" valign="top">
<div class="form-element"> <div class="form-element">
<dtml-if wl_isLocked> <dtml-if wl_isLocked>
<em>Locked by WebDAV</em> <em>Locked</em>
<dtml-else> <dtml-else>
<input class="form-element" type="submit" name="submit" <input class="form-element" type="submit" name="submit"
value="Save Changes"> value="Save Changes">
...@@ -103,7 +103,7 @@ button and click <em>upload</em> to update the contents of the &dtml-kind;. ...@@ -103,7 +103,7 @@ button and click <em>upload</em> to update the contents of the &dtml-kind;.
<td align="left" valign="top"> <td align="left" valign="top">
<div class="form-element"> <div class="form-element">
<dtml-if wl_isLocked> <dtml-if wl_isLocked>
<em>Locked by WebDAV</em> <em>Locked</em>
<dtml-else> <dtml-else>
<input class="form-element" type="submit" name="submit" <input class="form-element" type="submit" name="submit"
value="Upload"> value="Upload">
......
...@@ -105,8 +105,3 @@ class ApplicationTests(unittest.TestCase): ...@@ -105,8 +105,3 @@ class ApplicationTests(unittest.TestCase):
def _noWay(self, key, default=None): def _noWay(self, key, default=None):
raise KeyError(key) raise KeyError(key)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(ApplicationTests),
))
...@@ -150,7 +150,7 @@ class TestCopySupport(EventTest): ...@@ -150,7 +150,7 @@ class TestCopySupport(EventTest):
) )
def test_5_COPY(self): def test_5_COPY(self):
# Test webdav COPY # Test COPY
req = self.app.REQUEST req = self.app.REQUEST
req.environ['HTTP_DEPTH'] = 'infinity' req.environ['HTTP_DEPTH'] = 'infinity'
req.environ['HTTP_DESTINATION'] = ('%s/subfolder/mydoc' req.environ['HTTP_DESTINATION'] = ('%s/subfolder/mydoc'
...@@ -165,7 +165,7 @@ class TestCopySupport(EventTest): ...@@ -165,7 +165,7 @@ class TestCopySupport(EventTest):
) )
def test_6_MOVE(self): def test_6_MOVE(self):
# Test webdav MOVE # Test MOVE
req = self.app.REQUEST req = self.app.REQUEST
req.environ['HTTP_DEPTH'] = 'infinity' req.environ['HTTP_DEPTH'] = 'infinity'
req.environ['HTTP_DESTINATION'] = ('%s/subfolder/mydoc' req.environ['HTTP_DESTINATION'] = ('%s/subfolder/mydoc'
...@@ -179,7 +179,7 @@ class TestCopySupport(EventTest): ...@@ -179,7 +179,7 @@ class TestCopySupport(EventTest):
) )
def test_7_DELETE(self): def test_7_DELETE(self):
# Test webdav DELETE # Test DELETE
req = self.app.REQUEST req = self.app.REQUEST
req['URL'] = '%s/mydoc' % self.folder.absolute_url() req['URL'] = '%s/mydoc' % self.folder.absolute_url()
self.folder.mydoc.DELETE(req, req.RESPONSE) self.folder.mydoc.DELETE(req, req.RESPONSE)
...@@ -274,7 +274,7 @@ class TestCopySupportSublocation(EventTest): ...@@ -274,7 +274,7 @@ class TestCopySupportSublocation(EventTest):
) )
def test_5_COPY(self): def test_5_COPY(self):
# Test webdav COPY # Test COPY
req = self.app.REQUEST req = self.app.REQUEST
req.environ['HTTP_DEPTH'] = 'infinity' req.environ['HTTP_DEPTH'] = 'infinity'
req.environ['HTTP_DESTINATION'] = ('%s/subfolder/myfolder' req.environ['HTTP_DESTINATION'] = ('%s/subfolder/myfolder'
...@@ -293,7 +293,7 @@ class TestCopySupportSublocation(EventTest): ...@@ -293,7 +293,7 @@ class TestCopySupportSublocation(EventTest):
) )
def test_6_MOVE(self): def test_6_MOVE(self):
# Test webdav MOVE # Test MOVE
req = self.app.REQUEST req = self.app.REQUEST
req.environ['HTTP_DEPTH'] = 'infinity' req.environ['HTTP_DEPTH'] = 'infinity'
req.environ['HTTP_DESTINATION'] = ('%s/subfolder/myfolder' req.environ['HTTP_DESTINATION'] = ('%s/subfolder/myfolder'
...@@ -309,7 +309,7 @@ class TestCopySupportSublocation(EventTest): ...@@ -309,7 +309,7 @@ class TestCopySupportSublocation(EventTest):
) )
def test_7_DELETE(self): def test_7_DELETE(self):
# Test webdav DELETE # Test DELETE
req = self.app.REQUEST req = self.app.REQUEST
req['URL'] = '%s/myfolder' % self.folder.absolute_url() req['URL'] = '%s/myfolder' % self.folder.absolute_url()
self.folder.myfolder.DELETE(req, req.RESPONSE) self.folder.myfolder.DELETE(req, req.RESPONSE)
......
...@@ -148,7 +148,7 @@ class TestCopySupport(HookTest): ...@@ -148,7 +148,7 @@ class TestCopySupport(HookTest):
) )
def test_5_COPY(self): def test_5_COPY(self):
# Test webdav COPY # Test COPY
req = self.app.REQUEST req = self.app.REQUEST
req.environ['HTTP_DEPTH'] = 'infinity' req.environ['HTTP_DEPTH'] = 'infinity'
req.environ['HTTP_DESTINATION'] = '%s/subfolder/mydoc' % self.folder.absolute_url() req.environ['HTTP_DESTINATION'] = '%s/subfolder/mydoc' % self.folder.absolute_url()
...@@ -159,7 +159,7 @@ class TestCopySupport(HookTest): ...@@ -159,7 +159,7 @@ class TestCopySupport(HookTest):
) )
def test_6_MOVE(self): def test_6_MOVE(self):
# Test webdav MOVE # Test MOVE
req = self.app.REQUEST req = self.app.REQUEST
req.environ['HTTP_DEPTH'] = 'infinity' req.environ['HTTP_DEPTH'] = 'infinity'
req.environ['HTTP_DESTINATION'] = '%s/subfolder/mydoc' % self.folder.absolute_url() req.environ['HTTP_DESTINATION'] = '%s/subfolder/mydoc' % self.folder.absolute_url()
...@@ -170,7 +170,7 @@ class TestCopySupport(HookTest): ...@@ -170,7 +170,7 @@ class TestCopySupport(HookTest):
) )
def test_7_DELETE(self): def test_7_DELETE(self):
# Test webdav DELETE # Test DELETE
req = self.app.REQUEST req = self.app.REQUEST
req['URL'] = '%s/mydoc' % self.folder.absolute_url() req['URL'] = '%s/mydoc' % self.folder.absolute_url()
self.folder.mydoc.DELETE(req, req.RESPONSE) self.folder.mydoc.DELETE(req, req.RESPONSE)
...@@ -243,7 +243,7 @@ class TestCopySupportSublocation(HookTest): ...@@ -243,7 +243,7 @@ class TestCopySupportSublocation(HookTest):
) )
def test_5_COPY(self): def test_5_COPY(self):
# Test webdav COPY # Test COPY
req = self.app.REQUEST req = self.app.REQUEST
req.environ['HTTP_DEPTH'] = 'infinity' req.environ['HTTP_DEPTH'] = 'infinity'
req.environ['HTTP_DESTINATION'] = '%s/subfolder/myfolder' % self.folder.absolute_url() req.environ['HTTP_DESTINATION'] = '%s/subfolder/myfolder' % self.folder.absolute_url()
...@@ -256,7 +256,7 @@ class TestCopySupportSublocation(HookTest): ...@@ -256,7 +256,7 @@ class TestCopySupportSublocation(HookTest):
) )
def test_6_MOVE(self): def test_6_MOVE(self):
# Test webdav MOVE # Test MOVE
req = self.app.REQUEST req = self.app.REQUEST
req.environ['HTTP_DEPTH'] = 'infinity' req.environ['HTTP_DEPTH'] = 'infinity'
req.environ['HTTP_DESTINATION'] = '%s/subfolder/myfolder' % self.folder.absolute_url() req.environ['HTTP_DESTINATION'] = '%s/subfolder/myfolder' % self.folder.absolute_url()
...@@ -269,7 +269,7 @@ class TestCopySupportSublocation(HookTest): ...@@ -269,7 +269,7 @@ class TestCopySupportSublocation(HookTest):
) )
def test_7_DELETE(self): def test_7_DELETE(self):
# Test webdav DELETE # Test DELETE
req = self.app.REQUEST req = self.app.REQUEST
req['URL'] = '%s/myfolder' % self.folder.absolute_url() req['URL'] = '%s/myfolder' % self.folder.absolute_url()
self.folder.myfolder.DELETE(req, req.RESPONSE) self.folder.myfolder.DELETE(req, req.RESPONSE)
......
...@@ -2,9 +2,9 @@ import unittest ...@@ -2,9 +2,9 @@ import unittest
import Testing import Testing
import Zope2 import Zope2
Zope2.startup()
import os, sys import os
import sys
import time import time
from cStringIO import StringIO from cStringIO import StringIO
...@@ -35,24 +35,28 @@ except: ...@@ -35,24 +35,28 @@ except:
imagedata = os.path.join(here, 'test.gif') imagedata = os.path.join(here, 'test.gif')
filedata = os.path.join(here, 'test.gif') filedata = os.path.join(here, 'test.gif')
Zope2.startup()
def makeConnection(): def makeConnection():
import ZODB import ZODB
from ZODB.DemoStorage import DemoStorage from ZODB.DemoStorage import DemoStorage
s = DemoStorage() s = DemoStorage()
return ZODB.DB( s ).open() return ZODB.DB(s).open()
def aputrequest(file, content_type): def aputrequest(file, content_type):
resp = HTTPResponse(stdout=sys.stdout) resp = HTTPResponse(stdout=sys.stdout)
environ = {} environ = {}
environ['SERVER_NAME']='foo' environ['SERVER_NAME'] = 'foo'
environ['SERVER_PORT']='80' environ['SERVER_PORT'] = '80'
environ['REQUEST_METHOD'] = 'PUT' environ['REQUEST_METHOD'] = 'PUT'
environ['CONTENT_TYPE'] = content_type environ['CONTENT_TYPE'] = content_type
req = HTTPRequest(stdin=file, environ=environ, response=resp) req = HTTPRequest(stdin=file, environ=environ, response=resp)
return req return req
class DummyCache: class DummyCache:
def __init__(self): def __init__(self):
self.clear() self.clear()
...@@ -71,8 +75,8 @@ class DummyCache: ...@@ -71,8 +75,8 @@ class DummyCache:
self.invalidated = ob self.invalidated = ob
def clear(self): def clear(self):
self.set=None self.set = None
self.get=None self.get = None
self.invalidated = None self.invalidated = None
self.si = None self.si = None
...@@ -80,60 +84,61 @@ class DummyCache: ...@@ -80,60 +84,61 @@ class DummyCache:
self.si = si self.si = si
ADummyCache=DummyCache() ADummyCache = DummyCache()
class DummyCacheManager(SimpleItem): class DummyCacheManager(SimpleItem):
def ZCacheManager_getCache(self): def ZCacheManager_getCache(self):
return ADummyCache return ADummyCache
class EventCatcher(object): class EventCatcher(object):
def __init__(self): def __init__(self):
self.created = [] self.created = []
self.modified = [] self.modified = []
self.setUp() self.setUp()
def setUp(self): def setUp(self):
from zope.component import provideHandler from zope.component import provideHandler
provideHandler(self.handleCreated) provideHandler(self.handleCreated)
provideHandler(self.handleModified) provideHandler(self.handleModified)
def tearDown(self): def tearDown(self):
from zope.component import getSiteManager from zope.component import getSiteManager
getSiteManager().unregisterHandler(self.handleCreated) getSiteManager().unregisterHandler(self.handleCreated)
getSiteManager().unregisterHandler(self.handleModified) getSiteManager().unregisterHandler(self.handleModified)
def reset(self): def reset(self):
self.created = [] self.created = []
self.modified = [] self.modified = []
@adapter(IObjectCreatedEvent) @adapter(IObjectCreatedEvent)
def handleCreated(self, event): def handleCreated(self, event):
if isinstance(event.object, OFS.Image.File): if isinstance(event.object, OFS.Image.File):
self.created.append(event) self.created.append(event)
@adapter(IObjectModifiedEvent) @adapter(IObjectModifiedEvent)
def handleModified(self, event): def handleModified(self, event):
if isinstance(event.object, OFS.Image.File): if isinstance(event.object, OFS.Image.File):
self.modified.append(event) self.modified.append(event)
class FileTests(unittest.TestCase): class FileTests(unittest.TestCase):
data = open(filedata, 'rb').read() data = open(filedata, 'rb').read()
content_type = 'application/octet-stream' content_type = 'application/octet-stream'
factory = 'manage_addFile' factory = 'manage_addFile'
def setUp( self ):
def setUp(self):
self.connection = makeConnection() self.connection = makeConnection()
self.eventCatcher = EventCatcher() self.eventCatcher = EventCatcher()
try: try:
r = self.connection.root() r = self.connection.root()
a = Application() a = Application()
r['Application'] = a r['Application'] = a
self.root = a self.root = a
responseOut = self.responseOut = StringIO() responseOut = self.responseOut = StringIO()
self.app = makerequest( self.root, stdout=responseOut ) self.app = makerequest(self.root, stdout=responseOut)
self.app.dcm = DummyCacheManager() self.app.dcm = DummyCacheManager()
factory = getattr(self.app, self.factory) factory = getattr(self.app, self.factory)
factory('file', factory('file',
...@@ -148,18 +153,20 @@ class FileTests(unittest.TestCase): ...@@ -148,18 +153,20 @@ class FileTests(unittest.TestCase):
self.connection.close() self.connection.close()
raise raise
transaction.begin() transaction.begin()
self.file = getattr( self.app, 'file' ) self.file = getattr(self.app, 'file')
# Since we do the create here, let's test the events here too # Since we do the create here, let's test the events here too
self.assertEquals(1, len(self.eventCatcher.created)) self.assertEquals(1, len(self.eventCatcher.created))
self.assertTrue(aq_base(self.eventCatcher.created[0].object) is aq_base(self.file)) self.assertTrue(
aq_base(self.eventCatcher.created[0].object) is aq_base(self.file))
self.assertEquals(1, len(self.eventCatcher.modified)) self.assertEquals(1, len(self.eventCatcher.modified))
self.assertTrue(aq_base(self.eventCatcher.created[0].object) is aq_base(self.file)) self.assertTrue(
aq_base(self.eventCatcher.created[0].object) is aq_base(self.file))
self.eventCatcher.reset() self.eventCatcher.reset()
def tearDown( self ): def tearDown(self):
del self.file del self.file
transaction.abort() transaction.abort()
self.connection.close() self.connection.close()
...@@ -168,7 +175,6 @@ class FileTests(unittest.TestCase): ...@@ -168,7 +175,6 @@ class FileTests(unittest.TestCase):
del self.root del self.root
del self.connection del self.connection
ADummyCache.clear() ADummyCache.clear()
self.eventCatcher.tearDown() self.eventCatcher.tearDown()
def testViewImageOrFile(self): def testViewImageOrFile(self):
...@@ -227,7 +233,9 @@ class FileTests(unittest.TestCase): ...@@ -227,7 +233,9 @@ class FileTests(unittest.TestCase):
def testIfModSince(self): def testIfModSince(self):
now = time.time() now = time.time()
e = {'SERVER_NAME':'foo', 'SERVER_PORT':'80', 'REQUEST_METHOD':'GET'} e = {'SERVER_NAME': 'foo',
'SERVER_PORT': '80',
'REQUEST_METHOD': 'GET'}
# not modified since # not modified since
t_notmod = rfc1123_date(now) t_notmod = rfc1123_date(now)
...@@ -235,7 +243,7 @@ class FileTests(unittest.TestCase): ...@@ -235,7 +243,7 @@ class FileTests(unittest.TestCase):
out = StringIO() out = StringIO()
resp = HTTPResponse(stdout=out) resp = HTTPResponse(stdout=out)
req = HTTPRequest(sys.stdin, e, resp) req = HTTPRequest(sys.stdin, e, resp)
data = self.file.index_html(req,resp) data = self.file.index_html(req, resp)
self.assertEqual(resp.getStatus(), 304) self.assertEqual(resp.getStatus(), 304)
self.assertEqual(data, '') self.assertEqual(data, '')
...@@ -245,7 +253,7 @@ class FileTests(unittest.TestCase): ...@@ -245,7 +253,7 @@ class FileTests(unittest.TestCase):
out = StringIO() out = StringIO()
resp = HTTPResponse(stdout=out) resp = HTTPResponse(stdout=out)
req = HTTPRequest(sys.stdin, e, resp) req = HTTPRequest(sys.stdin, e, resp)
data = self.file.index_html(req,resp) data = self.file.index_html(req, resp)
self.assertEqual(resp.getStatus(), 200) self.assertEqual(resp.getStatus(), 200)
self.assertEqual(data, str(self.file.data)) self.assertEqual(data, str(self.file.data))
...@@ -271,12 +279,12 @@ class FileTests(unittest.TestCase): ...@@ -271,12 +279,12 @@ class FileTests(unittest.TestCase):
self.assertEqual(str(self.file.data), s) self.assertEqual(str(self.file.data), s)
def testIndexHtmlWithPdata(self): def testIndexHtmlWithPdata(self):
self.file.manage_upload('a' * (2 << 16)) # 128K self.file.manage_upload('a' * (2 << 16)) # 128K
self.file.index_html(self.app.REQUEST, self.app.REQUEST.RESPONSE) self.file.index_html(self.app.REQUEST, self.app.REQUEST.RESPONSE)
self.assert_(self.app.REQUEST.RESPONSE._wrote) self.assert_(self.app.REQUEST.RESPONSE._wrote)
def testIndexHtmlWithString(self): def testIndexHtmlWithString(self):
self.file.manage_upload('a' * 100) # 100 bytes self.file.manage_upload('a' * 100) # 100 bytes
self.file.index_html(self.app.REQUEST, self.app.REQUEST.RESPONSE) self.file.index_html(self.app.REQUEST, self.app.REQUEST.RESPONSE)
self.assert_(not self.app.REQUEST.RESPONSE._wrote) self.assert_(not self.app.REQUEST.RESPONSE._wrote)
...@@ -313,10 +321,11 @@ class FileTests(unittest.TestCase): ...@@ -313,10 +321,11 @@ class FileTests(unittest.TestCase):
def testUnicode(self): def testUnicode(self):
val = u'some unicode string here' val = u'some unicode string here'
self.assertRaises(TypeError, self.file.manage_edit, self.assertRaises(TypeError, self.file.manage_edit,
'foobar', 'text/plain', filedata=val) 'foobar', 'text/plain', filedata=val)
class ImageTests(FileTests): class ImageTests(FileTests):
data = open(filedata, 'rb').read() data = open(filedata, 'rb').read()
content_type = 'image/gif' content_type = 'image/gif'
...@@ -332,19 +341,22 @@ class ImageTests(FileTests): ...@@ -332,19 +341,22 @@ class ImageTests(FileTests):
self.assertTrue(ADummyCache.set) self.assertTrue(ADummyCache.set)
def testStr(self): def testStr(self):
self.assertEqual(str(self.file), self.assertEqual(
('<img src="http://foo/file" alt="" title="" height="16" width="16" />')) str(self.file),
('<img src="http://foo/file" '
'alt="" title="" height="16" width="16" />'))
def testTag(self): def testTag(self):
tag_fmt = '<img src="http://foo/file" alt="%s" title="%s" height="16" width="16" />' tag_fmt = ('<img src="http://foo/file" '
self.assertEqual(self.file.tag(), (tag_fmt % ('',''))) 'alt="%s" title="%s" height="16" width="16" />')
self.assertEqual(self.file.tag(), (tag_fmt % ('', '')))
self.file.manage_changeProperties(title='foo') self.file.manage_changeProperties(title='foo')
self.assertEqual(self.file.tag(), (tag_fmt % ('','foo'))) self.assertEqual(self.file.tag(), (tag_fmt % ('', 'foo')))
self.file.manage_changeProperties(alt='bar') self.file.manage_changeProperties(alt='bar')
self.assertEqual(self.file.tag(), (tag_fmt % ('bar','foo'))) self.assertEqual(self.file.tag(), (tag_fmt % ('bar', 'foo')))
def testViewImageOrFile(self): def testViewImageOrFile(self):
pass # dtml method,screw it pass # dtml method,screw it
def test_interfaces(self): def test_interfaces(self):
from zope.interface.verify import verifyClass from zope.interface.verify import verifyClass
...@@ -355,6 +367,7 @@ class ImageTests(FileTests): ...@@ -355,6 +367,7 @@ class ImageTests(FileTests):
class ImagePublishTests(Testing.ZopeTestCase.FunctionalTestCase): class ImagePublishTests(Testing.ZopeTestCase.FunctionalTestCase):
def testTagSafe(self): def testTagSafe(self):
self.app.manage_addImage("image", "") self.app.manage_addImage("image", "")
res = self.publish( res = self.publish(
...@@ -363,12 +376,4 @@ class ImagePublishTests(Testing.ZopeTestCase.FunctionalTestCase): ...@@ -363,12 +376,4 @@ class ImagePublishTests(Testing.ZopeTestCase.FunctionalTestCase):
"%3E%3Cdiv%20class%3D%22") "%3E%3Cdiv%20class%3D%22")
self.assertFalse( self.assertFalse(
'<script type="text/javascript">alert(\'evil\');</script>' '<script type="text/javascript">alert(\'evil\');</script>'
in res.getBody()) in res.getBody())
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(FileTests),
unittest.makeSuite(ImageTests),
unittest.makeSuite(ImagePublishTests)
))
...@@ -11,9 +11,3 @@ class TestFolder(unittest.TestCase): ...@@ -11,9 +11,3 @@ class TestFolder(unittest.TestCase):
verifyClass(IFolder, Folder) verifyClass(IFolder, Folder)
verifyClass(IWriteLock, Folder) verifyClass(IWriteLock, Folder)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestFolder),
))
...@@ -13,9 +13,3 @@ class TestOrderedFolder(unittest.TestCase): ...@@ -13,9 +13,3 @@ class TestOrderedFolder(unittest.TestCase):
verifyClass(IOrderedContainer, OrderedFolder) verifyClass(IOrderedContainer, OrderedFolder)
verifyClass(IOrderedFolder, OrderedFolder) verifyClass(IOrderedFolder, OrderedFolder)
verifyClass(IWriteLock, OrderedFolder) verifyClass(IWriteLock, OrderedFolder)
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestOrderedFolder),
))
...@@ -17,7 +17,6 @@ import unittest ...@@ -17,7 +17,6 @@ import unittest
class TestPropertyManager(unittest.TestCase): class TestPropertyManager(unittest.TestCase):
"""Property management tests."""
def _getTargetClass(self): def _getTargetClass(self):
from OFS.PropertyManager import PropertyManager from OFS.PropertyManager import PropertyManager
...@@ -33,24 +32,24 @@ class TestPropertyManager(unittest.TestCase): ...@@ -33,24 +32,24 @@ class TestPropertyManager(unittest.TestCase):
verifyClass(IPropertyManager, PropertyManager) verifyClass(IPropertyManager, PropertyManager)
def testLinesPropertyIsTuple( self ): def testLinesPropertyIsTuple(self):
inst = self._makeOne() inst = self._makeOne()
inst._setProperty('prop', ['xxx', 'yyy'], 'lines') inst._setProperty('prop', ['xxx', 'yyy'], 'lines')
self.assertTrue(type(inst.getProperty('prop')) == type(())) self.assertTrue(isinstance(inst.getProperty('prop'), tuple))
self.assertTrue(type(inst.prop) == type(())) self.assertTrue(isinstance(inst.prop, tuple))
inst._setPropValue('prop', ['xxx', 'yyy']) inst._setPropValue('prop', ['xxx', 'yyy'])
self.assertTrue(type(inst.getProperty('prop')) == type(())) self.assertTrue(isinstance(inst.getProperty('prop'), tuple))
self.assertTrue(type(inst.prop) == type(())) self.assertTrue(isinstance(inst.prop, tuple))
inst._updateProperty('prop', ['xxx', 'yyy']) inst._updateProperty('prop', ['xxx', 'yyy'])
self.assertTrue(type(inst.getProperty('prop')) == type(())) self.assertTrue(isinstance(inst.getProperty('prop'), tuple))
self.assertTrue(type(inst.prop) == type(())) self.assertTrue(isinstance(inst.prop, tuple))
inst.manage_addProperty('prop2', ['xxx', 'yyy'], 'lines') inst.manage_addProperty('prop2', ['xxx', 'yyy'], 'lines')
self.assertTrue(type(inst.getProperty('prop2')) == type(())) self.assertTrue(isinstance(inst.getProperty('prop2'), tuple))
self.assertTrue(type(inst.prop2) == type(())) self.assertTrue(isinstance(inst.prop2, tuple))
def test_propertyLabel_no_label_falls_back_to_id(self): def test_propertyLabel_no_label_falls_back_to_id(self):
class NoLabel(self._getTargetClass()): class NoLabel(self._getTargetClass()):
...@@ -88,23 +87,21 @@ class TestPropertyManager(unittest.TestCase): ...@@ -88,23 +87,21 @@ class TestPropertyManager(unittest.TestCase):
class TestPropertySheet(unittest.TestCase): class TestPropertySheet(unittest.TestCase):
"""Property management tests."""
def _makeOne(self, *args, **kw): def _makeOne(self, *args, **kw):
from OFS.PropertySheets import PropertySheet from OFS.PropertySheets import PropertySheet
return PropertySheet(*args, **kw) return PropertySheet(*args, **kw)
def testPropertySheetLinesPropertyIsTuple(self): def testPropertySheetLinesPropertyIsTuple(self):
inst = self._makeOne('foo') inst = self._makeOne('foo')
inst._setProperty('prop', ['xxx', 'yyy'], 'lines') inst._setProperty('prop', ['xxx', 'yyy'], 'lines')
self.assertTrue(type(inst.getProperty('prop')) == type(())) self.assertTrue(isinstance(inst.getProperty('prop'), tuple))
self.assertTrue(type(inst.prop) == type(())) self.assertTrue(isinstance(inst.prop, tuple))
inst._updateProperty('prop', ['xxx', 'yyy']) inst._updateProperty('prop', ['xxx', 'yyy'])
self.assertTrue(type(inst.getProperty('prop')) == type(())) self.assertTrue(isinstance(inst.getProperty('prop'), tuple))
self.assertTrue(type(inst.prop) == type(())) self.assertTrue(isinstance(inst.prop, tuple))
inst.manage_addProperty('prop2', ['xxx', 'yyy'], 'lines') inst.manage_addProperty('prop2', ['xxx', 'yyy'], 'lines')
self.assertTrue(type(inst.getProperty('prop2')) == type(())) self.assertTrue(type(inst.getProperty('prop2')) == type(()))
......
...@@ -109,7 +109,7 @@ class TestRequestRange(unittest.TestCase): ...@@ -109,7 +109,7 @@ class TestRequestRange(unittest.TestCase):
return body + rv return body + rv
def createLastModifiedDate(self, offset=0): def createLastModifiedDate(self, offset=0):
from webdav.common import rfc1123_date from App.Common import rfc1123_date
return rfc1123_date(self.file._p_mtime + offset) return rfc1123_date(self.file._p_mtime + offset)
def expectUnsatisfiable(self, range): def expectUnsatisfiable(self, range):
......
import unittest import unittest
class DTMLDocumentTests(unittest.TestCase): class DTMLDocumentTests(unittest.TestCase):
def _getTargetClass(self): def _getTargetClass(self):
...@@ -36,9 +37,3 @@ class DummyDispatcher: ...@@ -36,9 +37,3 @@ class DummyDispatcher:
def _setObject(self, key, value): def _setObject(self, key, value):
self._set[key] = value self._set[key] = value
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(DTMLDocumentTests),
unittest.makeSuite(FactoryTests),
))
import unittest import unittest
class DTMLMethodTests(unittest.TestCase): class DTMLMethodTests(unittest.TestCase):
def _getTargetClass(self): def _getTargetClass(self):
...@@ -45,10 +46,3 @@ class DummyDispatcher: ...@@ -45,10 +46,3 @@ class DummyDispatcher:
def _setObject(self, key, value): def _setObject(self, key, value):
self._set[key] = value self._set[key] = value
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(DTMLMethodTests),
unittest.makeSuite(FactoryTests),
))
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
<tr> <tr>
<td align="left" valign="top" colspan="4"> <td align="left" valign="top" colspan="4">
<div class="form-element"> <div class="form-element">
<em tal:condition="context/wl_isLocked">Locked by WebDAV</em> <em tal:condition="context/wl_isLocked">Locked</em>
<input tal:condition="not:context/wl_isLocked" <input tal:condition="not:context/wl_isLocked"
class="form-element" type="submit" class="form-element" type="submit"
name="pt_editAction:method" value="Save Changes"/> name="pt_editAction:method" value="Save Changes"/>
...@@ -110,7 +110,7 @@ context</a> to view or download the current text.</p> ...@@ -110,7 +110,7 @@ context</a> to view or download the current text.</p>
<td></td> <td></td>
<td align="left" valign="top"> <td align="left" valign="top">
<div class="form-element"> <div class="form-element">
<em tal:condition="context/wl_isLocked">Locked by WebDAV</em> <em tal:condition="context/wl_isLocked">Locked</em>
<input tal:condition="not:context/wl_isLocked" <input tal:condition="not:context/wl_isLocked"
class="form-element" type="submit" value="Upload File" /> class="form-element" type="submit" value="Upload File" />
</div> </div>
......
...@@ -40,7 +40,7 @@ probably need to manage Zope using its raw IP address to fix things. ...@@ -40,7 +40,7 @@ probably need to manage Zope using its raw IP address to fix things.
<td align="left" valign="top" colspan="2"> <td align="left" valign="top" colspan="2">
<div class="form-element"> <div class="form-element">
<dtml-if wl_isLocked> <dtml-if wl_isLocked>
<em>Locked by WebDAV</em> <em>Locked</em>
<dtml-else> <dtml-else>
<input class="form-element" type="submit" name="SUBMIT" value="Save Changes"> <input class="form-element" type="submit" name="SUBMIT" value="Save Changes">
</dtml-if> </dtml-if>
......
...@@ -132,7 +132,7 @@ class TestFunctional(ZopeTestCase.FunctionalTestCase): ...@@ -132,7 +132,7 @@ class TestFunctional(ZopeTestCase.FunctionalTestCase):
self.assertEqual(self.folder.index_html(), 'foo') self.assertEqual(self.folder.index_html(), 'foo')
def testPUTNew(self): def testPUTNew(self):
# Create a new object via FTP or WebDAV # Create a new object via PUT
self.setPermissions([add_documents_images_and_files]) self.setPermissions([add_documents_images_and_files])
put_data = StringIO('foo') put_data = StringIO('foo')
......
...@@ -34,7 +34,8 @@ from zope.publisher.interfaces.browser import IBrowserPublisher ...@@ -34,7 +34,8 @@ from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.traversing.namespace import namespaceLookup from zope.traversing.namespace import namespaceLookup
from zope.traversing.namespace import nsParse from zope.traversing.namespace import nsParse
UNSPECIFIED_ROLES='' UNSPECIFIED_ROLES = ''
def quote(text): def quote(text):
# quote url path segments, but leave + and @ intact # quote url path segments, but leave + and @ intact
......
import base64
import unittest import unittest
import Zope2
Zope2.startup() import transaction
from Products.SiteAccess.VirtualHostMonster import VirtualHostMonster from Products.SiteAccess.VirtualHostMonster import VirtualHostMonster
from Testing.makerequest import makerequest from Testing.makerequest import makerequest
import transaction import Zope2
import base64
auth_info = 'Basic %s' % base64.encodestring('manager:secret').rstrip() auth_info = 'Basic %s' % base64.encodestring('manager:secret').rstrip()
Zope2.startup()
class TestPUTFactory(unittest.TestCase): class TestPUTFactory(unittest.TestCase):
...@@ -46,25 +48,29 @@ class TestPUTFactory(unittest.TestCase): ...@@ -46,25 +48,29 @@ class TestPUTFactory(unittest.TestCase):
def testSimpleVirtualHosting(self): def testSimpleVirtualHosting(self):
request = self.app.REQUEST request = self.app.REQUEST
put = request.traverse('/VirtualHostBase/http/foo.com:80/VirtualHostRoot/folder/doc') put = request.traverse('/VirtualHostBase/http/foo.com:80/'
'VirtualHostRoot/folder/doc')
put(request, request.RESPONSE) put(request, request.RESPONSE)
self.assertTrue('doc' in self.folder.objectIds()) self.assertTrue('doc' in self.folder.objectIds())
def testSubfolderVirtualHosting(self): def testSubfolderVirtualHosting(self):
request = self.app.REQUEST request = self.app.REQUEST
put = request.traverse('/VirtualHostBase/http/foo.com:80/folder/VirtualHostRoot/doc') put = request.traverse('/VirtualHostBase/http/foo.com:80/'
'folder/VirtualHostRoot/doc')
put(request, request.RESPONSE) put(request, request.RESPONSE)
self.assertTrue('doc' in self.folder.objectIds()) self.assertTrue('doc' in self.folder.objectIds())
def testInsideOutVirtualHosting(self): def testInsideOutVirtualHosting(self):
request = self.app.REQUEST request = self.app.REQUEST
put = request.traverse('/VirtualHostBase/http/foo.com:80/VirtualHostRoot/_vh_foo/folder/doc') put = request.traverse('/VirtualHostBase/http/foo.com:80/'
'VirtualHostRoot/_vh_foo/folder/doc')
put(request, request.RESPONSE) put(request, request.RESPONSE)
self.assertTrue('doc' in self.folder.objectIds()) self.assertTrue('doc' in self.folder.objectIds())
def testSubfolderInsideOutVirtualHosting(self): def testSubfolderInsideOutVirtualHosting(self):
request = self.app.REQUEST request = self.app.REQUEST
put = request.traverse('/VirtualHostBase/http/foo.com:80/folder/VirtualHostRoot/_vh_foo/doc') put = request.traverse('/VirtualHostBase/http/foo.com:80/'
'folder/VirtualHostRoot/_vh_foo/doc')
put(request, request.RESPONSE) put(request, request.RESPONSE)
self.assertTrue('doc' in self.folder.objectIds()) self.assertTrue('doc' in self.folder.objectIds())
...@@ -79,13 +85,7 @@ class TestPUTFactory(unittest.TestCase): ...@@ -79,13 +85,7 @@ class TestPUTFactory(unittest.TestCase):
put = request.traverse('/A/B/a') put = request.traverse('/A/B/a')
put(request, request.RESPONSE) put(request, request.RESPONSE)
# PUT should no acquire A.a # PUT should no acquire A.a
self.assertEqual(str(self.app.A.a), 'I am file a', 'PUT factory should not acquire content') self.assertEqual(str(self.app.A.a), 'I am file a',
'PUT factory should not acquire content')
# check for the newly created file # check for the newly created file
self.assertEqual(str(self.app.A.B.a), 'bar') self.assertEqual(str(self.app.A.B.a), 'bar')
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestPUTFactory),
))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment