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
a9b6c974
Commit
a9b6c974
authored
Nov 30, 2016
by
Asif Saifuddin Auvi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converted asserts of decorators test to pytest
parent
504f4b44
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
16 deletions
+14
-16
tests/test_decorators.py
+14
-16
No files found.
tests/test_decorators.py
View file @
a9b6c974
...
@@ -56,11 +56,11 @@ class DecoratorTestCase(TestCase):
...
@@ -56,11 +56,11 @@ class DecoratorTestCase(TestCase):
request
=
self
.
factory
.
get
(
'/'
)
request
=
self
.
factory
.
get
(
'/'
)
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
assert
response
.
status_code
==
status
.
HTTP_200_OK
request
=
self
.
factory
.
post
(
'/'
)
request
=
self
.
factory
.
post
(
'/'
)
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
assert
response
.
status_code
==
status
.
HTTP_405_METHOD_NOT_ALLOWED
def
test_calling_put_method
(
self
):
def
test_calling_put_method
(
self
):
...
@@ -70,11 +70,11 @@ class DecoratorTestCase(TestCase):
...
@@ -70,11 +70,11 @@ class DecoratorTestCase(TestCase):
request
=
self
.
factory
.
put
(
'/'
)
request
=
self
.
factory
.
put
(
'/'
)
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
assert
response
.
status_code
==
status
.
HTTP_200_OK
request
=
self
.
factory
.
post
(
'/'
)
request
=
self
.
factory
.
post
(
'/'
)
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
assert
response
.
status_code
==
status
.
HTTP_405_METHOD_NOT_ALLOWED
def
test_calling_patch_method
(
self
):
def
test_calling_patch_method
(
self
):
...
@@ -84,11 +84,11 @@ class DecoratorTestCase(TestCase):
...
@@ -84,11 +84,11 @@ class DecoratorTestCase(TestCase):
request
=
self
.
factory
.
patch
(
'/'
)
request
=
self
.
factory
.
patch
(
'/'
)
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
assert
response
.
status_code
==
status
.
HTTP_200_OK
request
=
self
.
factory
.
post
(
'/'
)
request
=
self
.
factory
.
post
(
'/'
)
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
assert
response
.
status_code
==
status
.
HTTP_405_METHOD_NOT_ALLOWED
def
test_renderer_classes
(
self
):
def
test_renderer_classes
(
self
):
...
@@ -99,16 +99,15 @@ class DecoratorTestCase(TestCase):
...
@@ -99,16 +99,15 @@ class DecoratorTestCase(TestCase):
request
=
self
.
factory
.
get
(
'/'
)
request
=
self
.
factory
.
get
(
'/'
)
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertTrue
(
isinstance
(
response
.
accepted_renderer
,
JSONRenderer
)
)
assert
isinstance
(
response
.
accepted_renderer
,
JSONRenderer
)
def
test_parser_classes
(
self
):
def
test_parser_classes
(
self
):
@api_view
([
'GET'
])
@api_view
([
'GET'
])
@parser_classes
([
JSONParser
])
@parser_classes
([
JSONParser
])
def
view
(
request
):
def
view
(
request
):
self
.
assertEqual
(
len
(
request
.
parsers
),
1
)
assert
len
(
request
.
parsers
)
==
1
self
.
assertTrue
(
isinstance
(
request
.
parsers
[
0
],
assert
isinstance
(
request
.
parsers
[
0
],
JSONParser
)
JSONParser
))
return
Response
({})
return
Response
({})
request
=
self
.
factory
.
get
(
'/'
)
request
=
self
.
factory
.
get
(
'/'
)
...
@@ -119,9 +118,8 @@ class DecoratorTestCase(TestCase):
...
@@ -119,9 +118,8 @@ class DecoratorTestCase(TestCase):
@api_view
([
'GET'
])
@api_view
([
'GET'
])
@authentication_classes
([
BasicAuthentication
])
@authentication_classes
([
BasicAuthentication
])
def
view
(
request
):
def
view
(
request
):
self
.
assertEqual
(
len
(
request
.
authenticators
),
1
)
assert
len
(
request
.
authenticators
)
==
1
self
.
assertTrue
(
isinstance
(
request
.
authenticators
[
0
],
assert
isinstance
(
request
.
authenticators
[
0
],
BasicAuthentication
)
BasicAuthentication
))
return
Response
({})
return
Response
({})
request
=
self
.
factory
.
get
(
'/'
)
request
=
self
.
factory
.
get
(
'/'
)
...
@@ -136,7 +134,7 @@ class DecoratorTestCase(TestCase):
...
@@ -136,7 +134,7 @@ class DecoratorTestCase(TestCase):
request
=
self
.
factory
.
get
(
'/'
)
request
=
self
.
factory
.
get
(
'/'
)
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_403_FORBIDDEN
)
assert
response
.
status_code
==
status
.
HTTP_403_FORBIDDEN
def
test_throttle_classes
(
self
):
def
test_throttle_classes
(
self
):
class
OncePerDayUserThrottle
(
UserRateThrottle
):
class
OncePerDayUserThrottle
(
UserRateThrottle
):
...
@@ -149,7 +147,7 @@ class DecoratorTestCase(TestCase):
...
@@ -149,7 +147,7 @@ class DecoratorTestCase(TestCase):
request
=
self
.
factory
.
get
(
'/'
)
request
=
self
.
factory
.
get
(
'/'
)
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
assert
response
.
status_code
==
status
.
HTTP_200_OK
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_429_TOO_MANY_REQUESTS
)
assert
response
.
status_code
==
status
.
HTTP_429_TOO_MANY_REQUESTS
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