You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2013/10/03 10:22:54 UTC

[3/3] git commit: Refactor Rackspace tests and remove duplicated code.

Refactor Rackspace tests and remove duplicated code.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/0d057251
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/0d057251
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/0d057251

Branch: refs/heads/trunk
Commit: 0d057251a8c934a016b7186dfbae33dc4609ffa4
Parents: 32f59e9
Author: Tomaz Muraus <to...@apache.org>
Authored: Thu Oct 3 09:18:08 2013 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Thu Oct 3 09:20:12 2013 +0100

----------------------------------------------------------------------
 libcloud/test/compute/test_rackspace.py | 68 +++++++++-------------------
 1 file changed, 22 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/0d057251/libcloud/test/compute/test_rackspace.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_rackspace.py b/libcloud/test/compute/test_rackspace.py
index c232f05..601a529 100644
--- a/libcloud/test/compute/test_rackspace.py
+++ b/libcloud/test/compute/test_rackspace.py
@@ -84,7 +84,7 @@ class RackspaceNovaMockHttp(OpenStack_1_1_MockHttp):
             method = methods1[name]
             new_name = name.replace('_v1_1_slug_', '_v2_1337_')
             setattr(self, new_name, method_type(method, self,
-                RackspaceNovaMockHttp))
+                                                RackspaceNovaMockHttp))
 
 
 class RackspaceNovaLonMockHttp(RackspaceNovaMockHttp):
@@ -95,57 +95,45 @@ class RackspaceNovaLonMockHttp(RackspaceNovaMockHttp):
                 httplib.responses[httplib.OK])
 
 
+class BaseRackspaceNovaTestCase(OpenStack_1_1_Tests):
+    conn_classes = (RackspaceNovaMockHttp, RackspaceNovaMockHttp)
+    auth_url = 'https://auth.api.example.com/v2.0/'
 
-class RackspaceNovaDfwTests(OpenStack_1_1_Tests):
-
-    driver_klass = RackspaceNodeDriver
-    driver_type = RackspaceNodeDriver
-    driver_args = RACKSPACE_NOVA_PARAMS
-    driver_kwargs = {'region': 'dfw'}
-
-    @classmethod
     def create_driver(self):
         return self.driver_type(*self.driver_args, **self.driver_kwargs)
 
     def setUp(self):
-        self.driver_klass.connectionCls.conn_classes = (RackspaceNovaMockHttp,
-                                                        RackspaceNovaMockHttp)
-        self.driver_klass.connectionCls.auth_url = \
-                'https://auth.api.example.com/v2.0/'
+        self.driver_klass.connectionCls.conn_classes = self.conn_classes
+        self.driver_klass.connectionCls.auth_url = self.auth_url
+        self.conn_classes[0].type = None
+        self.conn_classes[1].type = None
         self.driver = self.create_driver()
         # normally authentication happens lazily, but we force it here
         self.driver.connection._populate_hosts_and_request_paths()
         clear_pricing_data()
         self.node = self.driver.list_nodes()[1]
 
+
+class RackspaceNovaDfwTests(BaseRackspaceNovaTestCase):
+
+    driver_klass = RackspaceNodeDriver
+    driver_type = RackspaceNodeDriver
+    driver_args = RACKSPACE_NOVA_PARAMS
+    driver_kwargs = {'region': 'dfw'}
+
     def test_service_catalog(self):
         self.assertEqual(
-                'https://dfw.servers.api.rackspacecloud.com/v2/1337',
-                self.driver.connection.get_endpoint())
+            'https://dfw.servers.api.rackspacecloud.com/v2/1337',
+            self.driver.connection.get_endpoint())
 
 
-class RackspaceNovaOrdTests(OpenStack_1_1_Tests):
+class RackspaceNovaOrdTests(BaseRackspaceNovaTestCase):
 
     driver_klass = RackspaceNodeDriver
     driver_type = RackspaceNodeDriver
     driver_args = RACKSPACE_NOVA_PARAMS
     driver_kwargs = {'region': 'ord'}
 
-    @classmethod
-    def create_driver(self):
-        return self.driver_type(*self.driver_args, **self.driver_kwargs)
-
-    def setUp(self):
-        self.driver_klass.connectionCls.conn_classes = (RackspaceNovaMockHttp,
-                                                        RackspaceNovaMockHttp)
-        self.driver_klass.connectionCls.auth_url = \
-                'https://auth.api.example.com/v2.0/'
-        self.driver = self.create_driver()
-        # normally authentication happens lazily, but we force it here
-        self.driver.connection._populate_hosts_and_request_paths()
-        clear_pricing_data()
-        self.node = self.driver.list_nodes()[1]
-
     def test_list_sizes_pricing(self):
         sizes = self.driver.list_sizes()
 
@@ -158,27 +146,15 @@ class RackspaceNovaOrdTests(OpenStack_1_1_Tests):
                          self.driver.connection.get_endpoint())
 
 
-class RackspaceNovaLonTests(OpenStack_1_1_Tests):
+class RackspaceNovaLonTests(BaseRackspaceNovaTestCase):
 
     driver_klass = RackspaceNodeDriver
     driver_type = RackspaceNodeDriver
     driver_args = RACKSPACE_NOVA_PARAMS
     driver_kwargs = {'region': 'lon'}
 
-    @classmethod
-    def create_driver(self):
-        return self.driver_type(*self.driver_args, **self.driver_kwargs)
-
-    def setUp(self):
-        self.driver_klass.connectionCls.conn_classes = \
-                (RackspaceNovaLonMockHttp, RackspaceNovaLonMockHttp)
-        self.driver_klass.connectionCls.auth_url = \
-                'https://lon.auth.api.example.com/v2.0/'
-        self.driver = self.create_driver()
-        # normally authentication happens lazily, but we force it here
-        self.driver.connection._populate_hosts_and_request_paths()
-        clear_pricing_data()
-        self.node = self.driver.list_nodes()[1]
+    conn_classes = (RackspaceNovaLonMockHttp, RackspaceNovaLonMockHttp)
+    auth_url = 'https://lon.auth.api.example.com/v2.0/'
 
     def test_list_sizes_pricing(self):
         sizes = self.driver.list_sizes()