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
973860d9
Commit
973860d9
authored
May 28, 2017
by
이동환
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added: test for list_route and detail_route with regex url_path
parent
e6c9f89a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
tests/test_routers.py
+33
-0
No files found.
tests/test_routers.py
View file @
973860d9
...
...
@@ -65,6 +65,19 @@ class EmptyPrefixViewSet(viewsets.ModelViewSet):
return
self
.
queryset
[
index
]
class
RegexUrlPathViewSet
(
viewsets
.
ViewSet
):
@list_route
(
url_path
=
'list/(?P<kwarg>[0-9]{4})'
)
def
regex_url_path_list
(
self
,
request
,
*
args
,
**
kwargs
):
kwarg
=
self
.
kwargs
.
get
(
'kwarg'
,
''
)
return
Response
({
'kwarg'
:
kwarg
})
@detail_route
(
url_path
=
'detail/(?P<kwarg>[0-9]{4})'
)
def
regex_url_path_detail
(
self
,
request
,
*
args
,
**
kwargs
):
pk
=
self
.
kwargs
.
get
(
'pk'
,
''
)
kwarg
=
self
.
kwargs
.
get
(
'kwarg'
,
''
)
return
Response
({
'pk'
:
pk
,
'kwarg'
:
kwarg
})
notes_router
=
SimpleRouter
()
notes_router
.
register
(
r'notes'
,
NoteViewSet
)
...
...
@@ -80,6 +93,9 @@ empty_prefix_urls = [
url
(
r'^'
,
include
(
empty_prefix_router
.
urls
)),
]
regex_url_path_router
=
SimpleRouter
()
regex_url_path_router
.
register
(
r''
,
RegexUrlPathViewSet
,
base_name
=
'regex'
)
urlpatterns
=
[
url
(
r'^non-namespaced/'
,
include
(
namespaced_router
.
urls
)),
url
(
r'^namespaced/'
,
include
(
namespaced_router
.
urls
,
namespace
=
'example'
,
app_name
=
'example'
)),
...
...
@@ -87,6 +103,7 @@ urlpatterns = [
url
(
r'^example2/'
,
include
(
kwarged_notes_router
.
urls
)),
url
(
r'^empty-prefix/'
,
include
(
empty_prefix_urls
)),
url
(
r'^regex/'
,
include
(
regex_url_path_router
.
urls
))
]
...
...
@@ -402,3 +419,19 @@ class TestEmptyPrefix(TestCase):
response
=
self
.
client
.
get
(
'/empty-prefix/1/'
)
assert
response
.
status_code
==
200
assert
json
.
loads
(
response
.
content
.
decode
(
'utf-8'
))
==
{
'uuid'
:
'111'
,
'text'
:
'First'
}
@override_settings
(
ROOT_URLCONF
=
'tests.test_routers'
)
class
TestRegexUrlPath
(
TestCase
):
def
test_regex_url_path_list
(
self
):
kwarg
=
'1234'
response
=
self
.
client
.
get
(
'/regex/list/{}/'
.
format
(
kwarg
))
assert
response
.
status_code
==
200
assert
json
.
loads
(
response
.
content
.
decode
(
'utf-8'
))
==
{
'kwarg'
:
kwarg
}
def
test_regex_url_path_detail
(
self
):
pk
=
'1'
kwarg
=
'1234'
response
=
self
.
client
.
get
(
'/regex/{}/detail/{}/'
.
format
(
pk
,
kwarg
))
assert
response
.
status_code
==
200
assert
json
.
loads
(
response
.
content
.
decode
(
'utf-8'
))
==
{
'pk'
:
pk
,
'kwarg'
:
kwarg
}
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