Commits

Olemis Lang  committed bb947b3

BH RPC : Upgrade Product RPC test cases to work with functional testers and RPC URL

Important: Test result for a single test case reported twice and not always the same.

  • Participants
  • Parent commits b22a6a5

Comments (0)

Files changed (2)

File trunk/bhrpc/tests/__init__.py

 __author__ = 'Olemis Lang <olemis+trac@gmail.com>'
 __license__ = 'BSD'
 
-from tracrpc.tests import rpc_testenv, TracRpcTestCase, unittest
+from tracrpc.tests import TracRpcTestCase, unittest
 
 class BloodhoundRpcTestCase(TracRpcTestCase):
     def setUp(self):
         TracRpcTestCase.setUp(self)
-        rpc_testenv.global_env.config.set('components', 'bhrpc.*', 'enabled')
-        rpc_testenv.global_env.config.save()
-        rpc_testenv.env.config.set('components', 'bhrpc.*', 'enabled')
-        rpc_testenv.env.config.save()
+        self._testenv.env.config.set('components', 'bhrpc.*', 'enabled')
+        self._testenv.env.config.save()
 
     def tearDown(self):
-        rpc_testenv.global_env.config.remove('components', 'bhrpc.*')
-        rpc_testenv.global_env.config.save()
-        rpc_testenv.env.config.remove('components', 'bhrpc.*')
-        rpc_testenv.env.config.save()
+        self._testenv.env.config.remove('components', 'bhrpc.*')
+        self._testenv.env.config.save()
         TracRpcTestCase.tearDown(self)
 
     def failUnlessRaises(self, excClass, callableObj=None, *args, **kwargs):

File trunk/bhrpc/tests/product.py

 
 import xmlrpclib
 
-from multiproduct.api import DEFAULT_PRODUCT
-
 from bhrpc.tests import BloodhoundRpcTestCase
-from tracrpc.tests import rpc_testenv, unittest
+from tracrpc.tests import unittest
 
 class RpcProductTestCase(BloodhoundRpcTestCase):
     """Test product API in product scope
         sd = BloodhoundRpcTestCase.shortDescription(self)
         return self.scope_label + ' ' + sd if sd else sd
 
+    @property
+    def DEFAULT_PRODUCT(self):
+        return self._testenv._default_product()
+
     def setUp(self):
         BloodhoundRpcTestCase.setUp(self)
-        self.anon = xmlrpclib.ServerProxy(rpc_testenv.url_anon)
-        self.user = xmlrpclib.ServerProxy(rpc_testenv.url_user)
-        self.admin = xmlrpclib.ServerProxy(rpc_testenv.url_admin)
+        self.anon = xmlrpclib.ServerProxy(self.url_anon)
+        self.user = xmlrpclib.ServerProxy(self.url_user)
+        self.admin = xmlrpclib.ServerProxy(self.url_admin)
 
     def tearDown(self):
-        rpc_testenv.global_env.db_transaction('DELETE FROM bloodhound_product'
-                                              ' WHERE prefix <> %s', 
-                                              DEFAULT_PRODUCT)
+        # FIXME: Keep all products (update prefix + name ?)
+        self._testenv.env.db_transaction('DELETE FROM bloodhound_product'
+                                                     ' WHERE prefix <> %s', 
+                                                self.DEFAULT_PRODUCT)
         BloodhoundRpcTestCase.tearDown(self)
 
     def test_create(self):
 
         check_products = self.admin.product.getAll()
 
-        self.assertEqual([DEFAULT_PRODUCT, self.prefix], sorted(check_products))
+        self.assertEqual([self.DEFAULT_PRODUCT, self.prefix],
+                         sorted(check_products))
         self.assertEqual([self.prefix, 'new', 'new', 'admin'],
                          self.admin.product.get(self.prefix))
 
 
         is_global_scope = self.scope != 'p'
         # Grant anonymous user with required permissions
-        rpc_testenv._tracadmin('permission', 'add', 'anonymous', 'TRAC_ADMIN', 
+        self._testenv._tracadmin('permission', 'add', 'anonymous', 'TRAC_ADMIN', 
                                globalenv=is_global_scope)
-        rpc_testenv._tracadmin('permission', 'add', 'anonymous', 'XML_RPC', 
+        self._testenv._tracadmin('permission', 'add', 'anonymous', 'XML_RPC', 
                                globalenv=is_global_scope)
         # Ensure anonymous super-user access will be reverted after this test
-        self.addCleanup(rpc_testenv._tracadmin, 'permission', 'remove',
+        self.addCleanup(self._testenv._tracadmin, 'permission', 'remove',
                         'anonymous', 'TRAC_ADMIN', globalenv=is_global_scope)
 
         with self.assertRaises(xmlrpclib.Fault) as test_cm:
 
         self.anon.product.create(self.prefix + '2', 'test product', 'with owner', 'user')
         
-        self.assertEqual([DEFAULT_PRODUCT, self.prefix + '2'], 
+        self.assertEqual([self.DEFAULT_PRODUCT, self.prefix + '2'], 
                          sorted(self.user.product.getAll()))
         self.assertEqual([self.prefix + '2', 'test product', 'with owner', 'user'],
                          self.user.product.get(self.prefix + '2'))
 
         self.admin.product.create(self.prefix, 'owned by user', 'transfer', 
                                   'user')
-        self.assertEqual([DEFAULT, self.prefix], self.admin.product.getAll())
+        self.assertEqual([self.DEFAULT_PRODUCT, self.prefix], 
+                         self.admin.product.getAll())
 
         self.user.product.chown(self.prefix, 'somebody')
         self.assertEqual([self.prefix, 'owned by user', 'transfer', 'somebody'],
 
     def setUp(self):
         BloodhoundRpcTestCase.setUp(self)
-        self.anon = xmlrpclib.ServerProxy(rpc_testenv.url_global_anon)
-        self.user = xmlrpclib.ServerProxy(rpc_testenv.url_global_user)
-        self.admin = xmlrpclib.ServerProxy(rpc_testenv.url_global_admin)
+        self.anon = self._tester.server_proxy(self.url_anon)
+        self.user = self._tester.server_proxy(self.url_auth, user='user')
+        self.admin = self._tester.server_proxy(self.url_auth, user='admin')
 
 
-def test_suite():
-    test_suite = unittest.TestSuite()
-    test_suite.addTest(unittest.makeSuite(RpcProductTestCase))
-    test_suite.addTest(unittest.makeSuite(RpcGlobalProductTestCase))
-    return test_suite
+def test_suite(suite=None):
+    if suite is None:
+        from tracrpc.tests import functionalSuite
+        suite = functionalSuite()
+    # FIXME: Improve
+    for ts in [unittest.makeSuite(RpcProductTestCase),
+               unittest.makeSuite(RpcGlobalProductTestCase)]:
+        for test in ts._tests:
+            suite.addTest(test)
+    return suite
+
 
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')