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
2448cc8e
Commit
2448cc8e
authored
Dec 19, 2014
by
tanwanirahul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated tests to use url_path attribute in list and detail decorators
parent
92ebeaa0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
tests/test_routers.py
+6
-6
No files found.
tests/test_routers.py
View file @
2448cc8e
...
@@ -261,11 +261,11 @@ class DynamicListAndDetailViewSet(viewsets.ViewSet):
...
@@ -261,11 +261,11 @@ class DynamicListAndDetailViewSet(viewsets.ViewSet):
def
detail_route_get
(
self
,
request
,
*
args
,
**
kwargs
):
def
detail_route_get
(
self
,
request
,
*
args
,
**
kwargs
):
return
Response
({
'method'
:
'link2'
})
return
Response
({
'method'
:
'link2'
})
@list_route
(
custom_method_name
=
"list_custom-route"
)
@list_route
(
url_path
=
"list_custom-route"
)
def
list_custom_route_get
(
self
,
request
,
*
args
,
**
kwargs
):
def
list_custom_route_get
(
self
,
request
,
*
args
,
**
kwargs
):
return
Response
({
'method'
:
'link1'
})
return
Response
({
'method'
:
'link1'
})
@detail_route
(
custom_method_name
=
"detail_custom-route"
)
@detail_route
(
url_path
=
"detail_custom-route"
)
def
detail_custom_route_get
(
self
,
request
,
*
args
,
**
kwargs
):
def
detail_custom_route_get
(
self
,
request
,
*
args
,
**
kwargs
):
return
Response
({
'method'
:
'link2'
})
return
Response
({
'method'
:
'link2'
})
...
@@ -278,7 +278,7 @@ class TestDynamicListAndDetailRouter(TestCase):
...
@@ -278,7 +278,7 @@ class TestDynamicListAndDetailRouter(TestCase):
routes
=
self
.
router
.
get_routes
(
DynamicListAndDetailViewSet
)
routes
=
self
.
router
.
get_routes
(
DynamicListAndDetailViewSet
)
decorator_routes
=
[
r
for
r
in
routes
if
not
(
r
.
name
.
endswith
(
'-list'
)
or
r
.
name
.
endswith
(
'-detail'
))]
decorator_routes
=
[
r
for
r
in
routes
if
not
(
r
.
name
.
endswith
(
'-list'
)
or
r
.
name
.
endswith
(
'-detail'
))]
MethodNamesMap
=
namedtuple
(
'MethodNamesMap'
,
'method_name
custom_method_name
'
)
MethodNamesMap
=
namedtuple
(
'MethodNamesMap'
,
'method_name
url_path
'
)
# Make sure all these endpoints exist and none have been clobbered
# Make sure all these endpoints exist and none have been clobbered
for
i
,
endpoint
in
enumerate
([
MethodNamesMap
(
'list_custom_route_get'
,
'list_custom-route'
),
for
i
,
endpoint
in
enumerate
([
MethodNamesMap
(
'list_custom_route_get'
,
'list_custom-route'
),
MethodNamesMap
(
'list_route_get'
,
'list_route_get'
),
MethodNamesMap
(
'list_route_get'
,
'list_route_get'
),
...
@@ -290,14 +290,14 @@ class TestDynamicListAndDetailRouter(TestCase):
...
@@ -290,14 +290,14 @@ class TestDynamicListAndDetailRouter(TestCase):
route
=
decorator_routes
[
i
]
route
=
decorator_routes
[
i
]
# check url listing
# check url listing
method_name
=
endpoint
.
method_name
method_name
=
endpoint
.
method_name
custom_method_name
=
endpoint
.
custom_method_name
url_path
=
endpoint
.
url_path
if
method_name
.
startswith
(
'list_'
):
if
method_name
.
startswith
(
'list_'
):
self
.
assertEqual
(
route
.
url
,
self
.
assertEqual
(
route
.
url
,
'^{{prefix}}/{0}{{trailing_slash}}$'
.
format
(
custom_method_name
))
'^{{prefix}}/{0}{{trailing_slash}}$'
.
format
(
url_path
))
else
:
else
:
self
.
assertEqual
(
route
.
url
,
self
.
assertEqual
(
route
.
url
,
'^{{prefix}}/{{lookup}}/{0}{{trailing_slash}}$'
.
format
(
custom_method_name
))
'^{{prefix}}/{{lookup}}/{0}{{trailing_slash}}$'
.
format
(
url_path
))
# check method to function mapping
# check method to function mapping
if
method_name
.
endswith
(
'_post'
):
if
method_name
.
endswith
(
'_post'
):
method_map
=
'post'
method_map
=
'post'
...
...
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