Commits

Olemis Lang  committed 4d997cb

BH RPC : Test cases for tracrpc.tests.json_rpc ... ok

  • Participants
  • Parent commits c71e724

Comments (0)

Files changed (2)

File trunk/tracrpc/tests/__init__.py

 else :
     __unittest = 1          # Do not show this module in tracebacks
     #FIXME: Apparently redundant inheritance
-    class TracRpcTestCase(FunctionalTestCaseSetup, unittest.TestCase):
+    class TracRpcTestCase(FunctionalTestCaseSetup, unittest.TestCase,
+                          functional.MultiproductFunctionalTestCase):
         def setUp(self):
             super(TracRpcTestCase, self).setUp()
             log = self._testenv.get_trac_environment().log

File trunk/tracrpc/tests/json_rpc.py

             return json.loads(resp.read())
 
         def _auth_req(self, data, user='user'):
-            password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
-            handler = urllib2.HTTPBasicAuthHandler(password_mgr)
-            password_mgr.add_password(realm=None,
-                          uri=self.url_auth,
-                          user=user,
-                          passwd=user)
             req = urllib2.Request(self.url_auth,
                         headers={'Content-Type': 'application/json'})
             req.data = json.dumps(data)
-            resp = urllib2.build_opener(handler).open(req)
+            opener = self._tester.build_opener(self.url_auth, user=user)
+            resp = opener.open(req)
             return json.loads(resp.read())
 
         def setUp(self):
             self.assertEquals('JSONRPCError', items[3]['error']['name'])
 
         def test_datetime(self):
-            # read and write datetime values
-            from datetime import datetime
-            from trac.util.datefmt import utc
-            dt_str = "2009-06-19T16:46:00"
-            dt_dt = datetime(2009, 06, 19, 16, 46, 00, tzinfo=utc)
-            data = {'method': 'ticket.milestone.update',
-                'params': ['milestone1', {'due': {'__jsonclass__':
-                    ['datetime', dt_str]}}]}
-            result = self._auth_req(data, user='admin')
-            self.assertEquals(None, result['error'])
-            result = self._auth_req({'method': 'ticket.milestone.get',
-                'params': ['milestone1']}, user='admin')
-            self.assertTrue(result['result'])
-            self.assertEquals(dt_str,
-                        result['result']['due']['__jsonclass__'][1])
+            # Execute in default product context if appropriate
+            with self.in_product():
+                # read and write datetime values
+                from datetime import datetime
+                from trac.util.datefmt import utc
+                dt_str = "2009-06-19T16:46:00"
+                dt_dt = datetime(2009, 06, 19, 16, 46, 00, tzinfo=utc)
+                data = {'method': 'ticket.milestone.update',
+                    'params': ['milestone1', {'due': {'__jsonclass__':
+                        ['datetime', dt_str]}}]}
+                result = self._auth_req(data, user='admin')
+                self.assertEquals(None, result['error'])
+                result = self._auth_req({'method': 'ticket.milestone.get',
+                    'params': ['milestone1']}, user='admin')
+                self.assertTrue(result['result'])
+                self.assertEquals(dt_str,
+                            result['result']['due']['__jsonclass__'][1])
 
         def test_binary(self):
             # read and write binaries values