def test_undeclared_api_path_parameters_are_skipped(): """ Test that parameters that are declared in the path string but do not appear in the parameter definitions are ignored. """ path = '/get/{username}/posts/{id}/' parameters = parameters_validator([ID_IN_PATH]) pattern = path_to_pattern(path, parameters) assert pattern == '^/get/\{username\}/posts/(?P<id>.+)/$'
def test_params_do_not_match_across_slashes(): path = '/get/{username}/posts/{id}' parameters = parameters_validator([USERNAME_IN_PATH, ID_IN_PATH]) pattern = path_to_pattern(path, parameters) assert re.match(pattern, '/get/simon/posts/123') # {id} should not expand to "/123/unread". assert not re.match(pattern, '/get/simon/posts/123/unread')
def test_undeclared_api_path_parameters_are_skipped(): """ Test that parameters that are declared in the path string but do not appear in the parameter definitions are ignored. """ path = '/get/{username}/posts/{id}/' parameters = parameters_validator([ID_IN_PATH]) pattern = path_to_pattern(path, parameters) assert pattern == '^/get/\{username\}/posts/(?P<id>[^/]+)/$'
def test_path_to_pattern_with_multiple_parameters(): input_ = '/get/{first_id}/then/{second_id}/' expected = '^/get/(?P<first_id>[^/]+)/then/(?P<second_id>[^/]+)/$' parameters = parameters_validator([ {'required': True, 'name': 'first_id', 'in': 'path', 'type': STRING}, {'required': True, 'name': 'second_id', 'in': 'path', 'type': STRING}, ]) actual = path_to_pattern(input_, parameters=parameters) assert actual == expected
def test_path_to_pattern_with_single_parameter(): input_ = '/get/{id}' expected = '^/get/(?P<id>[^/]+)$' parameters = parameters_validator([{ 'required': True, 'type': STRING, 'name': 'id', 'in': 'path', }]) actual = path_to_pattern(input_, parameters=parameters) assert actual == expected
def test_undeclared_api_path_parameters_are_skipped(): """ Test that parameters that are declared in the path string but do not appear in the parameter definitions are ignored. """ path = '/get/{username}/posts/{id}/' serializer = ParameterSerializer(many=True, data=[ ID_IN_PATH, ]) assert serializer.is_valid(), serializer.errors parameters = serializer.object pattern = path_to_pattern(path, parameters) assert pattern == '^/get/\{username\}/posts/(?P<id>.+)/$'