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

Merge pull request #224 from nuwang/urlfriendlyids

Added a test to make sure obj ids are url friendly
Nuwan Goonasekera 6 éve
szülő
commit
4cf11cd6c8

+ 1 - 1
cloudbridge/providers/azure/provider.py

@@ -1,7 +1,7 @@
 import logging
 import uuid
 
-from deprecation import deprecated
+from deprecated import deprecated
 
 from msrestazure.azure_exceptions import CloudError
 

+ 14 - 0
tests/helpers/standard_interface_tests.py

@@ -7,6 +7,8 @@ This includes:
 """
 import uuid
 
+from six.moves.urllib.parse import quote_plus
+
 import tenacity
 
 from cloudbridge.base import helpers as cb_helpers
@@ -40,6 +42,7 @@ def check_json(test, obj):
 def check_obj_properties(test, obj):
     test.assertEqual(obj, obj, "Object should be equal to itself")
     test.assertFalse(obj != obj, "Object inequality should be false")
+    check_obj_id(test, obj)
     check_obj_name(test, obj)
     check_obj_label(test, obj)
 
@@ -142,6 +145,17 @@ def check_delete(test, service, obj, perform_delete=False):
         % (found_objs, type(service).__name__))
 
 
+def check_obj_id(test, obj):
+    id_property = getattr(type(obj), 'id', None)
+    test.assertIsInstance(id_property, property)
+    test.assertIsNone(id_property.fset, "Id should not have a setter")
+    # Non-url safe characters trip up djcloudbridge or anything that needs to
+    # use the ID in a url so make sure ids do not contain them
+    test.assertEqual(quote_plus(obj.id), obj.id,
+                     "IDs should only contain URL friendly chars that do not "
+                     "require encoding but contains: %s" % (obj.id,))
+
+
 def check_obj_name(test, obj):
     name_property = getattr(type(obj), 'name', None)
     test.assertIsInstance(name_property, property)