@@ -33,16 +33,6 @@ def post(self, request, *args, **kwargs):
33
33
raise APIException
34
34
35
35
36
- class NonAtomicAPIExceptionView (APIView ):
37
- @method_decorator (transaction .non_atomic_requests )
38
- def dispatch (self , * args , ** kwargs ):
39
- return super (NonAtomicAPIExceptionView , self ).dispatch (* args , ** kwargs )
40
-
41
- def post (self , request , * args , ** kwargs ):
42
- BasicModel .objects .create ()
43
- raise PermissionDenied
44
-
45
-
46
36
@skipUnless (connection .features .uses_savepoints ,
47
37
"'atomic' requires transactions and savepoints." )
48
38
class DBTransactionTests (TestCase ):
@@ -125,6 +115,16 @@ def test_api_exception_rollback_transaction(self):
125
115
"'atomic' requires transactions and savepoints." )
126
116
class NonAtomicDBTransactionAPIExceptionTests (TestCase ):
127
117
def setUp (self ):
118
+ # only Django >= 1.6 provides @transaction.non_atomic_requests
119
+ class NonAtomicAPIExceptionView (APIView ):
120
+ @method_decorator (transaction .non_atomic_requests )
121
+ def dispatch (self , * args , ** kwargs ):
122
+ return super (NonAtomicAPIExceptionView , self ).dispatch (* args , ** kwargs )
123
+
124
+ def post (self , request , * args , ** kwargs ):
125
+ BasicModel .objects .create ()
126
+ raise PermissionDenied
127
+
128
128
self .view = NonAtomicAPIExceptionView .as_view ()
129
129
connections .databases ['default' ]['ATOMIC_REQUESTS' ] = True
130
130
0 commit comments