mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-28 13:03:45 +03:00
Tweaked some method names to be more clear and added a docstring to the test case class.
Signed-off-by: Kevin Stone <kevinastone@gmail.com>
This commit is contained in:
parent
71bd2faa79
commit
e7916ae0b1
|
@ -13,12 +13,15 @@ from rest_framework.urlpatterns import format_suffix_patterns
|
||||||
URLTestPath = namedtuple('URLTestPath', ['path', 'args', 'kwargs'])
|
URLTestPath = namedtuple('URLTestPath', ['path', 'args', 'kwargs'])
|
||||||
|
|
||||||
|
|
||||||
def test_view(request, *args, **kwargs):
|
def dummy_view(request, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class FormatSuffixTests(TestCase):
|
class FormatSuffixTests(TestCase):
|
||||||
def _test_urlpatterns(self, urlpatterns, test_paths):
|
"""
|
||||||
|
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 = RequestFactory()
|
factory = RequestFactory()
|
||||||
try:
|
try:
|
||||||
urlpatterns = format_suffix_patterns(urlpatterns)
|
urlpatterns = format_suffix_patterns(urlpatterns)
|
||||||
|
@ -37,31 +40,31 @@ class FormatSuffixTests(TestCase):
|
||||||
def test_format_suffix(self):
|
def test_format_suffix(self):
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
url(r'^test$', test_view),
|
url(r'^test$', dummy_view),
|
||||||
)
|
)
|
||||||
test_paths = [
|
test_paths = [
|
||||||
URLTestPath('/test', (), {}),
|
URLTestPath('/test', (), {}),
|
||||||
URLTestPath('/test.api', (), {'format': 'api'}),
|
URLTestPath('/test.api', (), {'format': 'api'}),
|
||||||
URLTestPath('/test.asdf', (), {'format': 'asdf'}),
|
URLTestPath('/test.asdf', (), {'format': 'asdf'}),
|
||||||
]
|
]
|
||||||
self._test_urlpatterns(urlpatterns, test_paths)
|
self._resolve_urlpatterns(urlpatterns, test_paths)
|
||||||
|
|
||||||
def test_default_args(self):
|
def test_default_args(self):
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
url(r'^test$', test_view, {'foo': 'bar'}),
|
url(r'^test$', dummy_view, {'foo': 'bar'}),
|
||||||
)
|
)
|
||||||
test_paths = [
|
test_paths = [
|
||||||
URLTestPath('/test', (), {'foo': 'bar', }),
|
URLTestPath('/test', (), {'foo': 'bar', }),
|
||||||
URLTestPath('/test.api', (), {'foo': 'bar', 'format': 'api'}),
|
URLTestPath('/test.api', (), {'foo': 'bar', 'format': 'api'}),
|
||||||
URLTestPath('/test.asdf', (), {'foo': 'bar', 'format': 'asdf'}),
|
URLTestPath('/test.asdf', (), {'foo': 'bar', 'format': 'asdf'}),
|
||||||
]
|
]
|
||||||
self._test_urlpatterns(urlpatterns, test_paths)
|
self._resolve_urlpatterns(urlpatterns, test_paths)
|
||||||
|
|
||||||
def test_included_urls(self):
|
def test_included_urls(self):
|
||||||
nested_patterns = patterns(
|
nested_patterns = patterns(
|
||||||
'',
|
'',
|
||||||
url(r'^path$', test_view)
|
url(r'^path$', dummy_view)
|
||||||
)
|
)
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
|
@ -72,4 +75,4 @@ class FormatSuffixTests(TestCase):
|
||||||
URLTestPath('/test/path.api', (), {'foo': 'bar', 'format': 'api'}),
|
URLTestPath('/test/path.api', (), {'foo': 'bar', 'format': 'api'}),
|
||||||
URLTestPath('/test/path.asdf', (), {'foo': 'bar', 'format': 'asdf'}),
|
URLTestPath('/test/path.asdf', (), {'foo': 'bar', 'format': 'asdf'}),
|
||||||
]
|
]
|
||||||
self._test_urlpatterns(urlpatterns, test_paths)
|
self._resolve_urlpatterns(urlpatterns, test_paths)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user