diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fixtures/extended-tests.json | 6 | ||||
-rw-r--r-- | tests/test_from_fixtures.py | 5 | ||||
-rw-r--r-- | tests/test_uritemplate.py | 68 |
3 files changed, 63 insertions, 16 deletions
diff --git a/tests/fixtures/extended-tests.json b/tests/fixtures/extended-tests.json index fd69744..ad43ad6 100644 --- a/tests/fixtures/extended-tests.json +++ b/tests/fixtures/extended-tests.json @@ -11,7 +11,7 @@ "lang" : "en", "geocode" : ["37.76","-122.427"], "first_name" : "John", - "last.name" : "Doe", + "last.name" : "Doe", "Some%20Thing" : "foo", "number" : 6, "long" : 37.76, @@ -28,7 +28,7 @@ "testcases":[ [ "{/id*}" , "/person" ], - [ "{/id*}{?fields,first_name,last.name,token}" , [ + [ "{/id*}{?fields,first_name,last.name,token}" , [ "/person?fields=id,name,picture&first_name=John&last.name=Doe&token=12345", "/person?fields=id,picture,name&first_name=John&last.name=Doe&token=12345", "/person?fields=picture,name,id&first_name=John&last.name=Doe&token=12345", @@ -68,7 +68,7 @@ "testcases":[ [ "{/id*}" , ["/person/albums","/albums/person"] ], - [ "{/id*}{?fields,token}" , [ + [ "{/id*}{?fields,token}" , [ "/person/albums?fields=id,name,picture&token=12345", "/person/albums?fields=id,picture,name&token=12345", "/person/albums?fields=picture,name,id&token=12345", diff --git a/tests/test_from_fixtures.py b/tests/test_from_fixtures.py index 70d6553..d6c9810 100644 --- a/tests/test_from_fixtures.py +++ b/tests/test_from_fixtures.py @@ -1,3 +1,4 @@ +import io import json import os.path @@ -12,7 +13,7 @@ def fixture_file_path(filename): def load_examples(filename): path = fixture_file_path(filename) - with open(path, 'r') as examples_file: + with io.open(path, 'r', encoding="utf-8") as examples_file: examples = json.load(examples_file) return examples @@ -20,7 +21,7 @@ def load_examples(filename): def expected_set(expected): if isinstance(expected, list): return set(expected) - return set([expected]) + return {expected} class FixtureMixin(object): diff --git a/tests/test_uritemplate.py b/tests/test_uritemplate.py index b1abc96..f67ad26 100644 --- a/tests/test_uritemplate.py +++ b/tests/test_uritemplate.py @@ -464,6 +464,52 @@ class TestURITemplate(RFCTemplateExamples('RFCMeta', (TestCase,), {})): None ) + def test_label_path_expansion_explode_slash(self): + t = URITemplate('{/foo*}') + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [], True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [None], True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [None, None], True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['one'], True, '/'), 'one' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['one', 'two'], True, '/'), 'one/two' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['one', None, 'two'], True, '/'), 'one/two' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', [''], True, '/'), '' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', ['', ''], True, '/'), '/' + ) + + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {}, True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': ''}, True, '/'), 'one=' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': '', 'two': ''}, True, '/'), 'one=/two=' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': None}, True, '/'), None + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': None, 'two': 'two'}, True, '/'), 'two=two' + ) + self.assertEqual(t.variables[0]._label_path_expansion( + 'foo', {'one': None, 'two': None}, True, '/'), None + ) + def test_semi_path_expansion(self): t = URITemplate('{foo}') v = t.variables[0] @@ -544,24 +590,24 @@ class TestURIVariable(TestCase): class TestVariableModule(TestCase): def test_is_list_of_tuples(self): - l = [(1, 2), (3, 4)] - self.assertEqual(variable.is_list_of_tuples(l), (True, l)) + a_list = [(1, 2), (3, 4)] + self.assertEqual(variable.is_list_of_tuples(a_list), (True, a_list)) - l = [1, 2, 3, 4] - self.assertEqual(variable.is_list_of_tuples(l), (False, None)) + a_list = [1, 2, 3, 4] + self.assertEqual(variable.is_list_of_tuples(a_list), (False, None)) def test_list_test(self): - l = [1, 2, 3, 4] - self.assertEqual(variable.list_test(l), True) + a_list = [1, 2, 3, 4] + self.assertEqual(variable.list_test(a_list), True) - l = str([1, 2, 3, 4]) - self.assertEqual(variable.list_test(l), False) + a_list = str([1, 2, 3, 4]) + self.assertEqual(variable.list_test(a_list), False) def test_list_of_tuples_test(self): - l = [(1, 2), (3, 4)] - self.assertEqual(variable.dict_test(l), False) + a_list = [(1, 2), (3, 4)] + self.assertEqual(variable.dict_test(a_list), False) - d = dict(l) + d = dict(a_list) self.assertEqual(variable.dict_test(d), True) |