Commit a5c920e2 authored by Stefan H. Holek's avatar Stefan H. Holek

Merged Zope 2.8 branch r41693:41694 into the trunk.

ZPublisher.BaseRequest: The publisher would happily publish attributes
of type 'bool' and 'complex'.
parent f326e88a
...@@ -574,7 +574,8 @@ itypes = {} ...@@ -574,7 +574,8 @@ itypes = {}
for name in ('NoneType', 'IntType', 'LongType', 'FloatType', 'StringType', for name in ('NoneType', 'IntType', 'LongType', 'FloatType', 'StringType',
'BufferType', 'TupleType', 'ListType', 'DictType', 'XRangeType', 'BufferType', 'TupleType', 'ListType', 'DictType', 'XRangeType',
'SliceType', 'EllipsisType', 'UnicodeType', 'CodeType', 'SliceType', 'EllipsisType', 'UnicodeType', 'CodeType',
'TracebackType', 'FrameType', 'DictProxyType'): 'TracebackType', 'FrameType', 'DictProxyType', 'BooleanType',
'ComplexType'):
if hasattr(types, name): if hasattr(types, name):
itypes[getattr(types, name)] = 0 itypes[getattr(types, name)] = 0
......
...@@ -16,6 +16,22 @@ class DummyObjectBasic(Implicit): ...@@ -16,6 +16,22 @@ class DummyObjectBasic(Implicit):
"""Attribute with docstring.""" """Attribute with docstring."""
return 'view content' return 'view content'
def noview(self):
# Attribute without docstring.
return 'unpublishable'
class DummyObjectWithoutDocstring(Implicit):
""
def view(self):
"""Attribute with docstring."""
return 'view content'
def noview(self):
# Attribute without docstring.
return 'unpublishable'
class DummyObjectWithDefault(DummyObjectBasic): class DummyObjectWithDefault(DummyObjectBasic):
"""Dummy class with docstring.""" """Dummy class with docstring."""
...@@ -68,6 +84,7 @@ class DummyObjectWithBDBBT(DummyObjectWithBD): ...@@ -68,6 +84,7 @@ class DummyObjectWithBDBBT(DummyObjectWithBD):
return getattr(self, name) return getattr(self, name)
raise AttributeError, name raise AttributeError, name
class TestBaseRequest(TestCase): class TestBaseRequest(TestCase):
def setUp(self): def setUp(self):
...@@ -80,6 +97,11 @@ class TestBaseRequest(TestCase): ...@@ -80,6 +97,11 @@ class TestBaseRequest(TestCase):
self.f1._setObject('objWithBD', DummyObjectWithBD() ) self.f1._setObject('objWithBD', DummyObjectWithBD() )
self.f1._setObject('objWithBBT', DummyObjectWithBBT() ) self.f1._setObject('objWithBBT', DummyObjectWithBBT() )
self.f1._setObject('objWithBDBBT', DummyObjectWithBDBBT() ) self.f1._setObject('objWithBDBBT', DummyObjectWithBDBBT() )
self.f1._setObject('objWithoutDocstring', DummyObjectWithoutDocstring() )
self.f1.simpleString = 'foo'
self.f1.simpleList = []
self.f1.simpleBoolean = True
self.f1.simpleComplex = complex(1)
def makeBaseRequest(self): def makeBaseRequest(self):
response = HTTPResponse() response = HTTPResponse()
...@@ -183,6 +205,40 @@ class TestBaseRequest(TestCase): ...@@ -183,6 +205,40 @@ class TestBaseRequest(TestCase):
self.assertEqual(r.URL, '/index_html') self.assertEqual(r.URL, '/index_html')
self.assertEqual(r.response.base, '') self.assertEqual(r.response.base, '')
def test_traverse_attribute_with_docstring(self):
r = self.makeBaseRequest()
r.traverse('folder/objBasic/view')
self.assertEqual(r.URL, '/folder/objBasic/view')
self.assertEqual(r.response.base, '')
def test_traverse_attribute_without_docstring(self):
from ZPublisher import NotFound
r = self.makeBaseRequest()
self.assertRaises(NotFound, r.traverse, 'folder/objBasic/noview')
def test_traverse_class_without_docstring(self):
from ZPublisher import NotFound
r = self.makeBaseRequest()
self.assertRaises(NotFound, r.traverse, 'folder/objWithoutDocstring')
def test_traverse_attribute_of_class_without_docstring(self):
from ZPublisher import NotFound
r = self.makeBaseRequest()
self.assertRaises(NotFound, r.traverse, 'folder/objWithoutDocstring/view')
def test_traverse_attribute_and_class_without_docstring(self):
from ZPublisher import NotFound
r = self.makeBaseRequest()
self.assertRaises(NotFound, r.traverse, 'folder/objWithoutDocstring/noview')
def test_traverse_simple_type(self):
from ZPublisher import NotFound
r = self.makeBaseRequest()
self.assertRaises(NotFound, r.traverse, 'folder/simpleString')
self.assertRaises(NotFound, r.traverse, 'folder/simpleList')
self.assertRaises(NotFound, r.traverse, 'folder/simpleBoolean')
self.assertRaises(NotFound, r.traverse, 'folder/simpleComplex')
def test_suite(): def test_suite():
return TestSuite( ( makeSuite(TestBaseRequest), ) ) return TestSuite( ( makeSuite(TestBaseRequest), ) )
......
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