Просмотр исходного кода

Unit Tests for Bucket Find and Create added.
Unit test get SG tweaked with get_found and get_not_found for maximum code coverage.

jatin 9 лет назад
Родитель
Сommit
b1aafb4258

+ 20 - 2
cloudbridge/cloud/providers/azure/mock_azure_client.py

@@ -1,5 +1,5 @@
 from azure.mgmt.network.models import NetworkSecurityGroup
-
+from azure.storage.blob.models import Container
 
 class MockAzureClient:
     sec_gr1 = NetworkSecurityGroup()
@@ -13,6 +13,12 @@ class MockAzureClient:
     sec_gr3.id = "sg3"
     security_groups = [sec_gr1, sec_gr2, sec_gr3]
 
+    container1 = Container()
+    container1.name = "container1"
+    container2 = Container()
+    container2.name = "container2"
+    containers = [container1, container2]
+
     def __init__(self, provider):
         self._provider = provider
 
@@ -23,4 +29,16 @@ class MockAzureClient:
         return 'Cloudbridge'
 
     def create_resource_group(self, resource_group_name, params):
-        return resource_group_name
+        return resource_group_name
+
+    def get_container(self, container_name):
+        for container in self.containers:
+            if container.name == container_name:
+                return container
+        return None
+
+    def create_container(self, container_name):
+        new_container = Container()
+        new_container.name = "newContainerCreate"
+        return None
+

+ 34 - 0
test/test_azure_object_store_service.py

@@ -0,0 +1,34 @@
+import json
+import unittest
+import uuid
+
+from cloudbridge.cloud.interfaces import TestMockHelperMixin
+
+from test.helpers import ProviderTestBase
+import test.helpers as helpers
+
+class AzureObjectStoreServiceTestCase(ProviderTestBase):
+    def __init__(self, methodName, provider):
+        super(AzureObjectStoreServiceTestCase, self).__init__(
+            methodName=methodName, provider=provider)
+
+    @helpers.skipIfNoService(['object_store'])
+    def test_azure_bucket_create(self):
+        container = self.provider.object_store.create("container3")
+        print(container)
+        self.assertTrue(
+            container == None,
+            "Object create returned value should be None")
+
+    @helpers.skipIfNoService(['object_store'])
+    def test_azure_bucket_find(self):
+        container = self.provider.object_store.find("container1")
+        print(str(container))
+        self.assertTrue(
+            str(container) == "[<CB-AzureBucket: container1>]",
+            "Object find returned value should be container1")
+
+
+    @helpers.skipIfNoService(['object_store'])
+    def test_azure_bucket_get(self):
+        pass

+ 15 - 5
test/test_azure_security_service.py

@@ -14,18 +14,28 @@ class AzureSecurityServiceTestCase(ProviderTestBase):
 
     @helpers.skipIfNoService(['security.security_groups'])
     def test_azure_security_group_list(self):
-        print(self.provider)
         sgl = self.provider.security.security_groups.list()
         found_sg = [g.name for g in sgl]
-        print("List( " + "Name-" + sgl[0].name + "  Id-" + sgl[0].id + " )")
+        for group in sgl:
+            print("List( " + "Name-" + group.name + "  Id-" + group.id + " Rules - " + " )")
         self.assertTrue(
             len(sgl) == 3,
-            "Security group {0} should have been deleted but still exists.")
+            "Count should be 3")
 
     @helpers.skipIfNoService(['security.security_groups'])
-    def test_azure_security_group_get(self):
+    def test_azure_security_group_get_found(self):
         sgl = self.provider.security.security_groups.get("sg2")
         print("Get ( " + "Name - " + sgl.name + "  Id - " + sgl.id + " )")
         self.assertTrue(
             sgl.name == "sec_group2",
-            "Security group {0} should have been deleted but still exists.")
+            "SG name should be sec_group2")
+
+    @helpers.skipIfNoService(['security.security_groups'])
+    def test_azure_security_group_get_not_found(self):
+        sgl = self.provider.security.security_groups.get("sg4")
+        print(str(sgl))
+        self.assertTrue(
+            sgl == None,
+            "Security group does not exist. Should return None.")
+
+