Skip to content

Commit

Permalink
Merge pull request #224 from nuwang/urlfriendlyids
Browse files Browse the repository at this point in the history
Added a test to make sure obj ids are url friendly
  • Loading branch information
nuwang committed Oct 4, 2019
2 parents b0de7fb + 8c1228f commit 4cf11cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cloudbridge/providers/azure/provider.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import uuid

from deprecation import deprecated
from deprecated import deprecated

from msrestazure.azure_exceptions import CloudError

Expand Down
14 changes: 14 additions & 0 deletions tests/helpers/standard_interface_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"""
import uuid

from six.moves.urllib.parse import quote_plus

import tenacity

from cloudbridge.base import helpers as cb_helpers
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4cf11cd

Please sign in to comment.