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

Chapter 34. Implementing TALES Namespaces > Step 3: Testing the Namespace

Step 3: Testing the Namespace

At this point you are only going to test whether the namespace works by itself; you are not checking whether the namespace will work correctly in TALES because that should be tested in the TALES implementation. The tricky part of this test is to create a sufficient Engine object so that the code can access the request instance. Here is the complete test code that you should place in tests.py:

01 import unittest
02 from datetime import datetime
03 from zope.publisher.browser import TestRequest
04 from zope.testing.doctestunit import DocTestSuite
05 from book.formatns import FormatTalesAPI
06
07 class Engine:
08     vars = {'request': TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})}
09
10 def getFormatNamespace(context):
11     ns = FormatTalesAPI(context)
12     ns.setEngine(Engine())
13     return ns
14
15 def fullDate():
16     """
17     >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
18     >>> ns.fullDate()
19     u'Tuesday, September 16, 2003'
20     """
21
22 def fullTime():
23     """
24     >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
25     >>> ns.fullTime()
26     u'4:51:01 PM +000'
27     """
28
29 def fullDateTime():
30     """
31     >>> ns = getFormatNamespace(datetime(2003, 9, 16, 16, 51, 01))
32     >>> ns.fullDateTime()
33     u'Tuesday, September 16, 2003 4:51:01 PM +000'
34     """
35
36 def test_suite():
37     return DocTestSuite()
38
39 if __name__ == '__main__':
40     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