source: products/quintagroup.gauth/trunk/quintagroup/gauth/tests.py @ 2604

Last change on this file since 2604 was 2604, checked in by mylan, 14 years ago

Added SafeQuery? class, which provide safeQuery method with automatic relogin in case of expired token

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1import unittest
2
3#from zope.testing import doctestunit
4#from zope.component import testing
5from Testing import ZopeTestCase as ztc
6
7from Products.Five import fiveconfigure
8from Products.PloneTestCase import PloneTestCase as ptc
9from Products.PloneTestCase.layer import PloneSite
10ptc.setupPloneSite()
11
12import quintagroup.gauth
13
14
15class TestCase(ptc.PloneTestCase):
16
17    class layer(PloneSite):
18
19        @classmethod
20        def setUp(cls):
21            fiveconfigure.debug_mode = True
22            ztc.installPackage(quintagroup.gauth)
23            fiveconfigure.debug_mode = False
24
25        @classmethod
26        def tearDown(cls):
27            pass
28
29
30# class SafeQuery(object):
31#     def safeCall(self, serv, meth, methargs=[], methkwargs={}):
32#         print "safecall %s: serv: %s, meth: %s, methargs: %s, methkwargs: %s" % (
33#             self, serv, meth, methargs, methkwargs)
34#         try:
35#             return meth(*methargs, **methkwargs)
36#         except gdata.service.RequestError, e:
37#             print "Token Expired -> Update it."
38#             logException("Token Expired -> Update it.")
39#             serv.ProgrammaticLogin()
40#             return meth(*methargs, **methkwargs)
41# counter = 0
42# class DummyServ:
43#     def ProgrammaticLogin(self, captcha_token=None, captcha_response=None):
44#         print "for '%s' called ProgrammaticLogin" % str(self)
45#     def Query(self, *args, **kwargs):
46#         global counter
47#         if counter > 3:
48#             counter = 0
49#             raise gdata.service.RequestError("Some Problem in Query")
50#         print "for '%s' called Query with args: %s, kwargs: %s" % tuple(
51#             map(str,[self,args,kwargs]))
52#         counter += 1
53# class C(SafeQuery):
54#     serv = None
55#     def __init__(self):
56#         self.serv = DummyServ()
57#     def operation(self, a):
58#         for i in range(5):
59#             self.safeCall(self.serv, self.serv.Query, [i,], {"q": i*i})
60
61
62
63
64
65
66def test_suite():
67    return unittest.TestSuite([
68
69        # Unit tests
70        #doctestunit.DocFileSuite(
71        #    'README.txt', package='quintagroup.gauth',
72        #    setUp=testing.setUp, tearDown=testing.tearDown),
73
74        #doctestunit.DocTestSuite(
75        #    module='quintagroup.gauth.mymodule',
76        #    setUp=testing.setUp, tearDown=testing.tearDown),
77
78
79        # Integration tests that use PloneTestCase
80        #ztc.ZopeDocFileSuite(
81        #    'README.txt', package='quintagroup.gauth',
82        #    test_class=TestCase),
83
84        #ztc.FunctionalDocFileSuite(
85        #    'browser.txt', package='quintagroup.gauth',
86        #    test_class=TestCase),
87
88        ])
89
90if __name__ == '__main__':
91    unittest.main(defaultTest='test_suite')
Note: See TracBrowser for help on using the repository browser.