Forráskód Böngészése

Refactored instance type tests

Nuwan Goonasekera 8 éve
szülő
commit
c65b398a62

+ 11 - 0
test/helpers/standard_interface_tests.py

@@ -67,9 +67,19 @@ def check_find_non_existent(test, service):
 def check_get(test, service, obj):
     get_obj = service.get(obj.id)
     test.assertEqual(get_obj, obj)
+    test.assertIsInstance(get_obj, type(obj))
     return get_obj
 
 
+def check_get_non_existent(test, service):
+    # check get
+    get_objs = service.get("random_imagined_obj_id")
+    test.assertIsNone(
+        get_objs,
+        "Get non-existent object for %s returned unexpected objects: %s"
+        % (type(service).__name__, get_objs))
+
+
 def check_delete(test, service, obj, perform_delete=False):
     if perform_delete:
         obj.delete()
@@ -89,6 +99,7 @@ def check_standard_behaviour(test, service, obj):
     objs_find = check_find(test, service, obj)
     check_find_non_existent(test, service)
     obj_get = check_get(test, service, obj)
+    check_get_non_existent(test, service)
 
     test.assertTrue(
         obj == objs_list[0] == objs_iter[0] == objs_find[0] == obj_get,

+ 5 - 37
test/test_instance_types_service.py

@@ -3,21 +3,15 @@ from test import helpers
 from test.helpers import ProviderTestBase
 from test.helpers import standard_interface_tests as sit
 
-from cloudbridge.cloud.interfaces.resources import InstanceType
-
 import six
 
 
 class CloudInstanceTypesServiceTestCase(ProviderTestBase):
 
     @helpers.skipIfNoService(['compute.instance_types'])
-    def test_instance_types(self):
-        instance_types = self.provider.compute.instance_types.list()
-        # Check iteration, keeping the first 50 entries (the .list() default)
-        iter_instance_types = list(self.provider.compute.instance_types)[:50]
-        self.assertListEqual(iter_instance_types, instance_types)
+    def test_instance_type_properties(self):
 
-        for inst_type in instance_types:
+        for inst_type in self.provider.compute.instance_types:
             sit.check_repr(self, inst_type)
             self.assertIsNotNone(
                 inst_type.id,
@@ -66,7 +60,7 @@ class CloudInstanceTypesServiceTestCase(ProviderTestBase):
                 "InstanceType extra_data must be None or a dict")
 
     @helpers.skipIfNoService(['compute.instance_types'])
-    def test_instance_types_find(self):
+    def test_instance_types_standard(self):
         """
         Searching for an instance by name should return an
         InstanceType object and searching for a non-existent
@@ -77,32 +71,6 @@ class CloudInstanceTypesServiceTestCase(ProviderTestBase):
             "instance_type")
         inst_type = self.provider.compute.instance_types.find(
             name=instance_type_name)[0]
-        self.assertTrue(isinstance(inst_type, InstanceType),
-                        "Find must return an InstanceType object")
-
-        self.assertFalse(self.provider.compute.instance_types.find(
-            name="non_existent_instance_type"), "Searching for a non-existent"
-            " instance type must return an empty list")
-
-        with self.assertRaises(TypeError):
-            self.provider.compute.instance_types.find(
-                non_existent_param="random_value")
 
-    @helpers.skipIfNoService(['compute.instance_types'])
-    def test_instance_types_get(self):
-        """
-        Searching for an instance by id should return an
-        InstanceType object and searching for a non-existent
-        object should return None
-        """
-        compute_svc = self.provider.compute
-        instance_type_name = helpers.get_provider_test_data(
-            self.provider,
-            "instance_type")
-        inst_type = self.provider.compute.instance_types.find(
-            name=instance_type_name)[0]
-        self.assertEqual(inst_type,
-                         compute_svc.instance_types.get(inst_type.id))
-        self.assertIsNone(compute_svc.instance_types.get("non_existent_id"),
-                          "Searching for a non-existent instance id must"
-                          " return None")
+        sit.check_standard_behaviour(
+                self, self.provider.compute.instance_types, inst_type)