• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 35. Changing Traversal Behavior > Step 3: Creating and Running Unit Tes...

Step 3: Creating and Running Unit Tests

You can quickly write unit tests in for the traverser because you can make use of the original container traverser's unit tests and setup. You simply need to open a tests.py file and insert the following test code:

01 import unittest
02 from zope.app.container.tests import test_containertraverser  
03 from book.insensitivefolder import CaseInsensitiveFolderTraverser
04
05 class Container(test_containertraverser.TestContainer):
06
07     def keys(self):
08         return self.__dict__.keys()
09
10     def __getitem__(self, name):
11         return self.__dict__[name]
12
13 class InsensitiveCaseTraverserTest(test_containertraverser.TraverserTest):
14
15     def _getTraverser(self, context, request):
16         return CaseInsensitiveFolderTraverser(context, request)
17
18     def _getContainer(self, **kw):
19         return Container(**kw)
20
21     def test_allLowerCaseItemTraversal(self):
22         self.assertEquals(
23             self.traverser.publishTraverse(self.request, 'foo'),
24             self.foo)
25         self.assertEquals(
26             self.traverser.publishTraverse(self.request, 'foO'),
27             self.foo)
28
29 def test_suite():
30     return unittest.TestSuite((
31         unittest.makeSuite(InsensitiveCaseTraverserTest),
32         ))
33
34 if __name__ == '__main__':
35     unittest.main(defaultTest='test_suite')


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint