def test_trailing_slash(self): factory = APIRequestFactory() urlpatterns = format_suffix_patterns([ url(r'^test/$', dummy_view), ]) resolver = RegexURLResolver(r'^/', urlpatterns) test_paths = [ (URLTestPath('/test.api', (), {'format': 'api'}), True), (URLTestPath('/test/.api', (), {'format': 'api'}), False), (URLTestPath('/test.api/', (), {'format': 'api'}), True), ] for test_path, expected_resolved in test_paths: request = factory.get(test_path.path) try: callback, callback_args, callback_kwargs = resolver.resolve(request.path_info) except Resolver404: callback, callback_args, callback_kwargs = (None, None, None) if not expected_resolved: assert callback is None continue assert callback_args == test_path.args assert callback_kwargs == test_path.kwargs
def test_trailing_slash(self): factory = APIRequestFactory() urlpatterns = format_suffix_patterns([ url(r'^test/$', dummy_view), ]) resolver = RegexURLResolver(r'^/', urlpatterns) test_paths = [ (URLTestPath('/test.api', (), {'format': 'api'}), True), (URLTestPath('/test/.api', (), {'format': 'api'}), False), (URLTestPath('/test.api/', (), {'format': 'api'}), True), ] for test_path, expected_resolved in test_paths: request = factory.get(test_path.path) try: callback, callback_args, callback_kwargs = resolver.resolve( request.path_info) except Resolver404: callback, callback_args, callback_kwargs = (None, None, None) if not expected_resolved: assert callback is None continue assert callback_args == test_path.args assert callback_kwargs == test_path.kwargs
def _resolve_urlpatterns(self, urlpatterns, test_paths): factory = APIRequestFactory() try: urlpatterns = format_suffix_patterns(urlpatterns) except Exception: self.fail("Failed to apply `format_suffix_patterns` on the supplied urlpatterns") resolver = RegexURLResolver(r'^/', urlpatterns) for test_path in test_paths: request = factory.get(test_path.path) try: callback, callback_args, callback_kwargs = resolver.resolve(request.path_info) except Exception: self.fail("Failed to resolve URL: %s" % request.path_info) assert callback_args == test_path.args assert callback_kwargs == test_path.kwargs
def _resolve_urlpatterns(self, urlpatterns, test_paths): factory = APIRequestFactory() try: urlpatterns = format_suffix_patterns(urlpatterns) except Exception: self.fail("Failed to apply `format_suffix_patterns` on the supplied urlpatterns") resolver = RegexURLResolver(r'^/', urlpatterns) for test_path in test_paths: request = factory.get(test_path.path) try: callback, callback_args, callback_kwargs = resolver.resolve(request.path_info) except Exception: self.fail("Failed to resolve URL: %s" % request.path_info) self.assertEqual(callback_args, test_path.args) self.assertEqual(callback_kwargs, test_path.kwargs)