diff options
| author | Xavier Ordoquy | 2014-04-17 09:53:44 +0200 |
|---|---|---|
| committer | Xavier Ordoquy | 2014-04-17 09:53:44 +0200 |
| commit | 1797a74e828c9fdfbfb46bb4de049100b18db875 (patch) | |
| tree | a91e8f4ff22e8eb63a990a439995632e9198d1c3 /rest_framework/tests/test_urlpatterns.py | |
| parent | 1d404874b3f0f5b16f3b38ba322f31a18c41aad6 (diff) | |
| parent | 971578ca345c3d3bae7fd93b87c41d43483b6f05 (diff) | |
| download | django-rest-framework-1797a74e828c9fdfbfb46bb4de049100b18db875.tar.bz2 | |
Merge remote-tracking branch 'pelme/pytest' into feature/pytest
Conflicts:
.travis.yml
rest_framework/runtests/runtests.py
tests/test_filters.py
tests/test_pagination.py
tox.ini
Diffstat (limited to 'rest_framework/tests/test_urlpatterns.py')
| -rw-r--r-- | rest_framework/tests/test_urlpatterns.py | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/rest_framework/tests/test_urlpatterns.py b/rest_framework/tests/test_urlpatterns.py deleted file mode 100644 index 8132ec4c..00000000 --- a/rest_framework/tests/test_urlpatterns.py +++ /dev/null @@ -1,76 +0,0 @@ -from __future__ import unicode_literals -from collections import namedtuple -from django.core import urlresolvers -from django.test import TestCase -from rest_framework.test import APIRequestFactory -from rest_framework.compat import patterns, url, include -from rest_framework.urlpatterns import format_suffix_patterns - - -# A container class for test paths for the test case -URLTestPath = namedtuple('URLTestPath', ['path', 'args', 'kwargs']) - - -def dummy_view(request, *args, **kwargs): - pass - - -class FormatSuffixTests(TestCase): - """ - Tests `format_suffix_patterns` against different URLPatterns to ensure the URLs still resolve properly, including any captured parameters. - """ - 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 = urlresolvers.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) - - def test_format_suffix(self): - urlpatterns = patterns( - '', - url(r'^test$', dummy_view), - ) - test_paths = [ - URLTestPath('/test', (), {}), - URLTestPath('/test.api', (), {'format': 'api'}), - URLTestPath('/test.asdf', (), {'format': 'asdf'}), - ] - self._resolve_urlpatterns(urlpatterns, test_paths) - - def test_default_args(self): - urlpatterns = patterns( - '', - url(r'^test$', dummy_view, {'foo': 'bar'}), - ) - test_paths = [ - URLTestPath('/test', (), {'foo': 'bar', }), - URLTestPath('/test.api', (), {'foo': 'bar', 'format': 'api'}), - URLTestPath('/test.asdf', (), {'foo': 'bar', 'format': 'asdf'}), - ] - self._resolve_urlpatterns(urlpatterns, test_paths) - - def test_included_urls(self): - nested_patterns = patterns( - '', - url(r'^path$', dummy_view) - ) - urlpatterns = patterns( - '', - url(r'^test/', include(nested_patterns), {'foo': 'bar'}), - ) - test_paths = [ - URLTestPath('/test/path', (), {'foo': 'bar', }), - URLTestPath('/test/path.api', (), {'foo': 'bar', 'format': 'api'}), - URLTestPath('/test/path.asdf', (), {'foo': 'bar', 'format': 'asdf'}), - ] - self._resolve_urlpatterns(urlpatterns, test_paths) |
