[Zope-Checkins]
SVN: Zope/branches/2.10/lib/python/OFS/tests/testApplication.py
Add some tests for OFS.Application.
Tres Seaver
tseaver at palladion.com
Tue Sep 25 10:04:06 EDT 2007
Log message for revision 80006:
Add some tests for OFS.Application.
Changed:
U Zope/branches/2.10/lib/python/OFS/tests/testApplication.py
-=-
Modified: Zope/branches/2.10/lib/python/OFS/tests/testApplication.py
===================================================================
--- Zope/branches/2.10/lib/python/OFS/tests/testApplication.py 2007-09-25 13:42:23 UTC (rev 80005)
+++ Zope/branches/2.10/lib/python/OFS/tests/testApplication.py 2007-09-25 14:04:06 UTC (rev 80006)
@@ -1,19 +1,113 @@
import unittest
-class TestApplication(unittest.TestCase):
+class ApplicationTests(unittest.TestCase):
- def test_z3interfaces(self):
+ def _getTargetClass(self):
+ from OFS.Application import Application
+ return Application
+
+ def _makeOne(self):
+ return self._getTargetClass()()
+
+ def test_class_provides_IApplication(self):
from OFS.interfaces import IApplication
- from OFS.Application import Application
from zope.interface.verify import verifyClass
- verifyClass(IApplication, Application)
+ verifyClass(IApplication, self._getTargetClass())
+ def test_instance_conforms_to_IApplication(self):
+ from OFS.interfaces import IApplication
+ from zope.interface.verify import verifyObject
+ verifyObject(IApplication, self._makeOne())
+
+ def test_instance_attributes(self):
+ app = self._makeOne()
+ self.failUnless(app.isTopLevelPrincipiaApplicationObject)
+ self.assertEqual(app.title, 'Zope')
+
+ def test_id_no_request(self):
+ app = self._makeOne()
+ self.assertEqual(app.id(), 'Zope')
+
+ def test_id_w_request_no_SCRIPT_NAME(self):
+ app = self._makeOne()
+ app.REQUEST = {}
+ self.assertEqual(app.id(), 'Zope')
+
+ def test_id_w_request_w_SCRIPT_NAME(self):
+ app = self._makeOne()
+ app.REQUEST = {'SCRIPT_NAME': '/Dummy'}
+ self.assertEqual(app.id(), 'Dummy')
+
+ def test_title_and_id_plus_title_or_id(self):
+ app = self._makeOne()
+ app.title = 'Other'
+ self.assertEqual(app.title_and_id(), 'Other')
+ self.assertEqual(app.title_or_id(), 'Other')
+
+ def test___bobo_traverse__attribute_hit(self):
+ app = self._makeOne()
+ app.NAME = 'attribute'
+ app._getOb = lambda x, y: x
+ request = {}
+ self.assertEqual(app.__bobo_traverse__(request, 'NAME'), 'attribute')
+
+ def test___bobo_traverse__attribute_miss_key_hit(self):
+ app = self._makeOne()
+ app._getOb = lambda x, y: x
+ request = {}
+ self.assertEqual(app.__bobo_traverse__(request, 'OTHER'), 'OTHER')
+
+ def test___bobo_traverse__attribute_key_miss_R_M_default_real_request(self):
+ from UserDict import UserDict
+ request = UserDict()
+
+ class _Response:
+ def notFoundError(self, msg):
+ 1/0
+
+ request.RESPONSE = _Response()
+ app = self._makeOne()
+ app._getOb = _noWay
+
+ self.assertRaises(ZeroDivisionError,
+ app.__bobo_traverse__, request, 'NONESUCH')
+
+ def test___bobo_traverse__attribute_key_miss_R_M_default_fake_request(self):
+ app = self._makeOne()
+
+ app._getOb = _noWay
+ request = {}
+ self.assertRaises(KeyError, app.__bobo_traverse__, request, 'NONESUCH')
+
+ def test___bobo_traverse__attribute_key_miss_R_M_is_GET(self):
+ app = self._makeOne()
+
+ app._getOb = _noWay
+ request = {'REQUEST_METHOD': 'GET'}
+ self.assertRaises(KeyError, app.__bobo_traverse__, request, 'NONESUCH')
+
+ def test___bobo_traverse__attribute_key_miss_R_M_not_GET_POST(self):
+ from Acquisition import aq_inner, aq_parent
+ from webdav.NullResource import NullResource
+
+ app = self._makeOne()
+ app._getOb = _noWay
+ request = {'REQUEST_METHOD': 'GOOFY'}
+
+ result = app.__bobo_traverse__(request, 'OTHER')
+
+ self.failUnless(isinstance(result, NullResource))
+ self.failUnless(aq_parent(aq_inner(result)) is app)
+
+def _noWay(self, key, default=None):
+ raise KeyError(key)
+
def test_suite():
return unittest.TestSuite((
- unittest.makeSuite(TestApplication),
+ unittest.makeSuite(ApplicationTests),
))
if __name__ == '__main__':
More information about the Zope-Checkins
mailing list