Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
778b0ddd
Commit
778b0ddd
authored
Jan 21, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #602 from kevinastone/master
TestCase for `format_suffix_patterns`
parents
98bffa68
e7916ae0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
+78
-0
rest_framework/tests/urlpatterns.py
+78
-0
No files found.
rest_framework/tests/urlpatterns.py
0 → 100644
View file @
778b0ddd
from
collections
import
namedtuple
from
django.core
import
urlresolvers
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
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
=
RequestFactory
()
try
:
urlpatterns
=
format_suffix_patterns
(
urlpatterns
)
except
:
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
:
self
.
fail
(
"Failed to resolve URL:
%
s"
%
request
.
path_info
)
self
.
assertEquals
(
callback_args
,
test_path
.
args
)
self
.
assertEquals
(
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment