File tree 3 files changed +23
-2
lines changed
3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ ChangeLog
5
5
master (unreleased)
6
6
===================
7
7
8
- - Nothing changed yet.
8
+ - Use an atomic transaction in FormidableSerialize.save() (#220)
9
9
10
10
Release 0.9.0 (2017-04-11)
11
11
==========================
Original file line number Diff line number Diff line change 4
4
import copy
5
5
from functools import reduce
6
6
7
- from django .test import TestCase
7
+ from django .db import connection
8
+ from django .test import TestCase , TransactionTestCase
9
+ from django .test .utils import CaptureQueriesContext
8
10
import django_perf_rec
9
11
10
12
from formidable import constants
@@ -859,6 +861,20 @@ def test_create_sepa(self):
859
861
self .assertTrue (qs .exists ())
860
862
861
863
864
+ class CreateSerializerTransactionTestCase (TransactionTestCase ):
865
+
866
+ def test_unique_transaction (self ):
867
+ data = copy .deepcopy (CreateSerializerTestCase .data )
868
+ data ['fields' ] = CreateSerializerTestCase .fields_with_items
869
+ serializer = FormidableSerializer (data = data )
870
+ self .assertTrue (serializer .is_valid (), serializer .errors )
871
+ with CaptureQueriesContext (connection ) as capture :
872
+ serializer .save ()
873
+ begin_count = sum (1 for query in capture .captured_queries
874
+ if query ['sql' ] == 'BEGIN' )
875
+ self .assertEqual (begin_count , 1 )
876
+
877
+
862
878
class UpdateFormTestCase (TestCase ):
863
879
864
880
data = {
Original file line number Diff line number Diff line change 3
3
from __future__ import unicode_literals
4
4
5
5
from django .core .exceptions import ValidationError
6
+ from django .db import transaction
6
7
7
8
from formidable .models import Formidable
8
9
from formidable .serializers import fields
@@ -59,6 +60,10 @@ def check_presets_cohesion(self, data):
59
60
)
60
61
return data
61
62
63
+ def save (self , * args , ** kwargs ):
64
+ with transaction .atomic ():
65
+ return super (FormidableSerializer , self ).save (* args , ** kwargs )
66
+
62
67
63
68
class ContextFormSerializer (serializers .ModelSerializer ):
64
69
You can’t perform that action at this time.
0 commit comments