Back to index

plone3  3.1.7
testUtils.py
Go to the documentation of this file.
00001 from unittest import TestCase
00002 from unittest import TestSuite
00003 from unittest import makeSuite
00004 from plone.protect.utils import protect
00005 
00006 def funcWithoutRequest():
00007     pass
00008 
00009 def funcWithRequest(one, two, REQUEST=None):
00010     return (one, two)
00011 
00012 class DummyChecker:
00013     def __call__(self, request):
00014         self.request=request
00015 
00016 class DecoratorTests(TestCase):
00017     def testFunctionMustHaveRequest(self):
00018         protector=protect()
00019         self.assertRaises(ValueError, protector, funcWithoutRequest)
00020 
00021     def testArgumentsPassed(self):
00022         wrapped=protect()(funcWithRequest)
00023         self.assertEqual(wrapped("one", "two"), ("one", "two"))
00024 
00025     def testKeywordArguments(self):
00026         wrapped=protect()(funcWithRequest)
00027         self.assertEqual(wrapped(one="one", two="two"), ("one", "two"))
00028 
00029     def testMixedArguments(self):
00030         wrapped=protect()(funcWithRequest)
00031         self.assertEqual(wrapped("one", two="two"), ("one", "two"))
00032 
00033     def testRequestPassedToChecker(self):
00034         checker=DummyChecker()
00035         wrapped=protect(checker)(funcWithRequest)
00036         request=[]
00037         wrapped("one", "two", request)
00038         self.failUnless(checker.request is request)
00039 
00040 
00041 
00042 def test_suite():
00043     suite=TestSuite()
00044     suite.addTest(makeSuite(DecoratorTests))
00045     return suite