Commits

Olemis Lang committed d628078

BH RPC : All test cases for product RPC CRUD ops working ok on all supported scopes

  • Participants
  • Parent commits 8804fc0

Comments (0)

Files changed (2)

File trunk/bhrpc/tests/product.py

     while initializing product with the same product prefix even if created
     for another test case.
     """
+    scope = 'p'
+    scope_label = '[PRODUCT]'
+
+    @property
+    def prefix(self):
+        return '%s_%s' % (self.scope, self._testMethodName)
+
+    def shortDescription(self):
+        sd = BloodhoundRpcTestCase.shortDescription(self)
+        return self.scope_label + ' ' + sd if sd else sd
+
     def setUp(self):
         BloodhoundRpcTestCase.setUp(self)
         self.anon = xmlrpclib.ServerProxy(rpc_testenv.url_anon)
     def test_create(self):
         """test saving new Product"""
 
-        self.admin.product.create('test_create', 'new', 'new')
+        self.admin.product.create(self.prefix, 'new', 'new')
 
         check_products = self.admin.product.getAll()
 
-        self.assertEqual(['@', 'test_create'], sorted(check_products))
-        self.assertEqual(['test_create', 'new', 'new', 'admin'],
-                         self.admin.product.get('test_create'))
+        self.assertEqual(['@', self.prefix], sorted(check_products))
+        self.assertEqual([self.prefix, 'new', 'new', 'admin'],
+                         self.admin.product.get(self.prefix))
 
     def test_create_duplicate_key(self):
         """test attempted saving of Product with existing key fails"""
 
-        self.admin.product.create('test_create_duplicate_key', 'original',
-                                  'first product')
+        self.admin.product.create(self.prefix, 'original', 'first product')
 
         with self.assertRaises(xmlrpclib.Fault) as test_cm:
-            self.admin.product.create('test_create_duplicate_key', 'dupe',
-                                      'dupe primary key')
+            self.admin.product.create(self.prefix, 'dupe', 'dupe primary key')
         self.assertEqual(1, test_cm.exception.faultCode)
-        self.assertEquals("'Product prefix='test_create_duplicate_key' already "
+        self.assertEquals("'Product prefix='%(prefix)s' already "
                           "exists {'name': 'dupe', "
-                          "'prefix': 'test_create_duplicate_key', 'owner': "
-                          "'admin', 'description': 'dupe primary key'}' while "
-                          "executing 'product.create()'", 
+                          "'prefix': '%(prefix)s', 'owner': 'admin', "
+                          "'description': 'dupe primary key'}' while executing"
+                          " 'product.create()'" % {'prefix' : self.prefix}, 
                           test_cm.exception.faultString)
 
         with self.assertRaises(xmlrpclib.Fault) as test_cm:
-            self.admin.product.create('test_create_duplicate_key1', 'original',
+            self.admin.product.create(self.prefix + '1', 'original',
                                       'dupe unique field')
         self.assertEqual(1, test_cm.exception.faultCode)
         self.assertEquals("'Product name='original' already exists"
-                          " {'name': 'original', "
-                          "'prefix': 'test_create_duplicate_key1', "
+                          " {'name': 'original', 'prefix': '%(prefix)s', "
                           "'owner': 'admin', 'description': 'dupe unique field'}'"
-                          " while executing 'product.create()'", 
+                          " while executing 'product.create()'" %
+                                {'prefix' : self.prefix + '1'}, 
                           test_cm.exception.faultString)
     
     def test_create_no_owner(self):
         """test saving new Product when owner is missing"""
 
-        # Grant anonymous user with TRAC_ADMIN permission
-        rpc_testenv._tracadmin('permission', 'add', 
-                               'anonymous', 'TRAC_ADMIN')
+        is_global_scope = self.scope != 'p'
+        # Grant anonymous user with required permissions
+        rpc_testenv._tracadmin('permission', 'add', 'anonymous', 'TRAC_ADMIN', 
+                               globalenv=is_global_scope)
+        rpc_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',
-                        'anonymous', 'TRAC_ADMIN')
+                        'anonymous', 'TRAC_ADMIN', globalenv=is_global_scope)
 
         with self.assertRaises(xmlrpclib.Fault) as test_cm:
-            self.anon.product.create('test_create_no_owner1', 'test product',
+            self.anon.product.create(self.prefix + '1', 'test product',
                                      'no owner')
         self.assertEqual(1, test_cm.exception.faultCode)
         self.assertEquals("'Product owner must be specified' while executing "
                           "'product.create()'",
                           test_cm.exception.faultString)
 
-        self.anon.product.create('test_create_no_owner2', 'test product', 'with owner', 'user')
+        self.anon.product.create(self.prefix + '2', 'test product', 'with owner', 'user')
         
-        self.assertEqual(['@', 'test_create_no_owner2'], 
+        self.assertEqual(['@', self.prefix + '2'], 
                          sorted(self.user.product.getAll()))
-        self.assertEqual(['test_create_no_owner2', 'test product', 'with owner', 'user'],
-                         self.user.product.get('test_create_no_owner2'))
+        self.assertEqual([self.prefix + '2', 'test product', 'with owner', 'user'],
+                         self.user.product.get(self.prefix + '2'))
 
     def test_get_missing(self):
         """tests that get will not fail for missing products"""
     def test_update(self):
         """tests that we can use update to push data to the database"""
 
-        self.admin.product.create('test_update', 'test project', 
+        self.admin.product.create(self.prefix, 'test project', 
                                   'a test project')
 
-        product = self.admin.product.get('test_update')
+        product = self.admin.product.get(self.prefix)
         self.assertEqual('test project', product[1])
 
-        self.admin.product.update('test_update', {'name' : 'updated', 
+        self.admin.product.update(self.prefix, {'name' : 'updated', 
                                          'description' : 'nothing'})
-        comp_product = self.admin.product.get('test_update')
-        self.assertEqual(['test_update', 'updated', 'nothing', 'admin'], 
+        comp_product = self.admin.product.get(self.prefix)
+        self.assertEqual([self.prefix, 'updated', 'nothing', 'admin'], 
                          comp_product)
 
     def test_field_set(self):
         """tests that we can update a single field data"""
 
-        self.admin.product.create('test_field_set', 'test project', 
+        self.admin.product.create(self.prefix, 'test project', 
                                   'a test project')
 
-        product = self.admin.product.get('test_field_set')
+        product = self.admin.product.get(self.prefix)
         self.assertEqual('a test project', product[2])
 
-        self.admin.product.update('test_field_set', 
+        self.admin.product.update(self.prefix, 
                                   {'description' : 'test change of description', 
                                    'whatever' : 'ignore'})
-        comp_product = self.admin.product.get('test_field_set')
-        self.assertEqual(['test_field_set', 'test project', 'test change of description', 
+        comp_product = self.admin.product.get(self.prefix)
+        self.assertEqual([self.prefix, 'test project', 'test change of description', 
                           'admin'], comp_product)
 
 class RpcGlobalProductTestCase(RpcProductTestCase):
     """Test product API in global scope
     """
+    scope = 'g'
+    scope_label = '[GLOBAL]'
+
     def setUp(self):
-        raise NotImplementedError()
-#        TracRpcTestCase.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)
-#
-#    def tearDown(self):
-#        RpcProductApiTestCase.tearDown(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)
 
 
 def test_suite():

File trunk/tracrpc/tests/__init__.py

             self._tracadmin('permission', 'add', 'anonymous', 'XML_RPC')
             print "Created test environment: %s" % self.dirname
             parts = urllib2.urlparse.urlsplit(self.url)
+
+            # --------------------------
+            # Global URLs
+            # --------------------------
+            # Regular URIs
+            self.url_global_anon = '%s://%s/rpc' % (parts[0], parts[1])
+            self.url_global_auth = '%s://%s/login/rpc' % (parts[0], parts[1])
+            # URIs with user:pass as part of URL
+            self.url_global_user = '%s://user:user@%s/login/xmlrpc' % \
+                                (parts[0], parts[1])
+            self.url_global_admin = '%s://admin:admin@%s/login/xmlrpc' % \
+                                (parts[0], parts[1])
+
+            # --------------------------
+            # Product URLs
+            # --------------------------
             # Regular URIs
             self.url_anon = '%s://%s/products/%s/rpc' % (parts[0], parts[1],
                                                         default_product)
                                 (parts[0], parts[1], default_product)
             self.url_admin = '%s://admin:admin@%s/products/%s/login/xmlrpc' % \
                                 (parts[0], parts[1], default_product)
+
             SvnFunctionalTestEnvironment.post_create(self, env)
             print "Starting web server: %s" % self.url
             self.restart()