From b015ae99e69c1bf8525a6163008a7a760b22c5bf Mon Sep 17 00:00:00 2001 From: hellysmile Date: Mon, 8 Jun 2015 07:39:08 +0300 Subject: [PATCH] Inline @transaction.non_atomic_requests for Django<1.6. --- tests/test_atomic_requests.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test_atomic_requests.py b/tests/test_atomic_requests.py index b4b27cec6..75001e9bf 100644 --- a/tests/test_atomic_requests.py +++ b/tests/test_atomic_requests.py @@ -33,16 +33,6 @@ class APIExceptionView(APIView): raise APIException -class NonAtomicAPIExceptionView(APIView): - @method_decorator(transaction.non_atomic_requests) - def dispatch(self, *args, **kwargs): - return super(NonAtomicAPIExceptionView, self).dispatch(*args, **kwargs) - - def post(self, request, *args, **kwargs): - BasicModel.objects.create() - raise PermissionDenied - - @skipUnless(connection.features.uses_savepoints, "'atomic' requires transactions and savepoints.") class DBTransactionTests(TestCase): @@ -125,6 +115,16 @@ class DBTransactionAPIExceptionTests(TestCase): "'atomic' requires transactions and savepoints.") class NonAtomicDBTransactionAPIExceptionTests(TestCase): def setUp(self): + # only Django >= 1.6 provides @transaction.non_atomic_requests + class NonAtomicAPIExceptionView(APIView): + @method_decorator(transaction.non_atomic_requests) + def dispatch(self, *args, **kwargs): + return super(NonAtomicAPIExceptionView, self).dispatch(*args, **kwargs) + + def post(self, request, *args, **kwargs): + BasicModel.objects.create() + raise PermissionDenied + self.view = NonAtomicAPIExceptionView.as_view() connections.databases['default']['ATOMIC_REQUESTS'] = True