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
cbfce931
Commit
cbfce931
authored
Jun 08, 2015
by
hellysmile
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fitx TestCase due Django interals.
parent
b015ae99
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
13 deletions
+18
-13
tests/test_atomic_requests.py
+18
-13
No files found.
tests/test_atomic_requests.py
View file @
cbfce931
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.conf.urls
import
patterns
,
url
from
django.db
import
connection
,
connections
,
transaction
from
django.db
import
connection
,
connections
,
transaction
from
django.test
import
TestCase
from
django.test
import
TestCase
,
TransactionTestCase
from
django.http
import
Http404
from
django.utils.decorators
import
method_decorator
from
django.utils.decorators
import
method_decorator
from
django.utils.unittest
import
skipUnless
from
django.utils.unittest
import
skipUnless
from
rest_framework
import
status
from
rest_framework
import
status
from
rest_framework.exceptions
import
APIException
,
PermissionDenied
from
rest_framework.exceptions
import
APIException
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.test
import
APIRequestFactory
from
rest_framework.test
import
APIRequestFactory
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
...
@@ -113,30 +115,33 @@ class DBTransactionAPIExceptionTests(TestCase):
...
@@ -113,30 +115,33 @@ class DBTransactionAPIExceptionTests(TestCase):
@skipUnless
(
connection
.
features
.
uses_savepoints
,
@skipUnless
(
connection
.
features
.
uses_savepoints
,
"'atomic' requires transactions and savepoints."
)
"'atomic' requires transactions and savepoints."
)
class
NonAtomicDBTransactionAPIExceptionTests
(
TestCase
):
class
NonAtomicDBTransactionAPIExceptionTests
(
T
ransactionT
estCase
):
def
setUp
(
self
):
@property
# only Django >= 1.6 provides @transaction.non_atomic_requests
def
urls
(
self
):
class
NonAtomicAPIExceptionView
(
APIView
):
class
NonAtomicAPIExceptionView
(
APIView
):
@method_decorator
(
transaction
.
non_atomic_requests
)
@method_decorator
(
transaction
.
non_atomic_requests
)
def
dispatch
(
self
,
*
args
,
**
kwargs
):
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
NonAtomicAPIExceptionView
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
return
super
(
NonAtomicAPIExceptionView
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
BasicModel
.
objects
.
create
()
BasicModel
.
objects
.
all
()
raise
PermissionDenied
raise
Http404
return
patterns
(
''
,
url
(
r'^$'
,
NonAtomicAPIExceptionView
.
as_view
())
)
self
.
view
=
NonAtomicAPIExceptionView
.
as_view
()
def
setUp
(
self
):
connections
.
databases
[
'default'
][
'ATOMIC_REQUESTS'
]
=
True
connections
.
databases
[
'default'
][
'ATOMIC_REQUESTS'
]
=
True
def
tearDown
(
self
):
def
tearDown
(
self
):
connections
.
databases
[
'default'
][
'ATOMIC_REQUESTS'
]
=
False
connections
.
databases
[
'default'
][
'ATOMIC_REQUESTS'
]
=
False
def
test_api_exception_rollback_transaction_non_atomic_view
(
self
):
def
test_api_exception_rollback_transaction_non_atomic_view
(
self
):
request
=
factory
.
post
(
'/'
)
response
=
self
.
client
.
get
(
'/'
)
response
=
self
.
view
(
request
)
# without checking connection.in_atomic_block view raises 500
# without checking connection.in_atomic_block view raises 500
# due attempt to rollback without transaction
# due attempt to rollback without transaction
self
.
assertEqual
(
response
.
status_code
,
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_40
3_FORBIDDEN
)
status
.
HTTP_40
4_NOT_FOUND
)
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