Merge lp:~pedronis/u1db/more-freedom-for-backends into lp:u1db

Proposed by Samuele Pedroni
Status: Merged
Approved by: Samuele Pedroni
Approved revision: 344
Merged at revision: 342
Proposed branch: lp:~pedronis/u1db/more-freedom-for-backends
Merge into: lp:u1db
Diff against target: 171 lines (+76/-61)
2 files modified
u1db/tests/__init__.py (+5/-0)
u1db/tests/test_backends.py (+71/-61)
To merge this branch: bzr merge lp:~pedronis/u1db/more-freedom-for-backends
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Review via email: mp+113308@code.launchpad.net

Commit message

more freedom for backends reusing the ref tests:
- split out the tests for *validate* methods which are partly internal details
- support setting accept_fixed_trans_id on DatabaseBaseTests subclasses to allow a backend to always use '' for trans_ids as checked by assertTransactionLog,

Description of the change

more freedom for backends reusing the reftests:

- split out the tests for *validate* methods which are partly internal details

- support setting accept_fixed_trans_id on DatabaseBaseTests subclasses to allow a backend to always use '' for trans_ids as checked by assertTransactionLog,

to test the latter: apply locally the diff

=== modified file 'u1db/tests/test_backends.py'
--- u1db/tests/test_backends.py 2012-07-03 21:34:14 +0000
+++ u1db/tests/test_backends.py 2012-07-03 21:42:44 +0000
@@ -476,6 +476,12 @@
             self.db._get_replica_gen_and_trans_id('other-db'))

     def test_put_updates_transaction_log(self):
+ if 'InMemory' in self.db.__class__.__name__:
+ def fixed():
+ print "FIXED"
+ return ''
+ self.db._allocate_transaction_id = fixed
+ self.accept_fixed_trans_id = True
         doc = self.db.create_doc(simple_doc)
         self.assertTransactionLog([doc.doc_id], self.db)
         doc.set_json('{"something": "else"}')

make check should still pass printing FIXED twice

To post a comment you must log in.
344. By Samuele Pedroni

rename test with wrong/repeated name

Revision history for this message
Eric Casteleijn (thisfred) wrote :

Works as advertised. Code looks good, with the duplicate test remained (sorry, my fault)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'u1db/tests/__init__.py'
2--- u1db/tests/__init__.py 2012-06-29 16:18:14 +0000
3+++ u1db/tests/__init__.py 2012-07-03 22:26:17 +0000
4@@ -162,6 +162,9 @@
5
6 class DatabaseBaseTests(TestCase):
7
8+ accept_fixed_trans_id = False # set to True assertTransactionLog
9+ # is happy with all trans ids = ''
10+
11 scenarios = LOCAL_DATABASES_SCENARIOS
12
13 def create_database(self, replica_uid):
14@@ -185,6 +188,8 @@
15 just_ids.append(doc_id)
16 self.assertIsNot(None, transaction_id,
17 "Transaction id should not be None")
18+ if transaction_id == '' and self.accept_fixed_trans_id:
19+ continue
20 self.assertNotEqual('', transaction_id,
21 "Transaction id should be a unique string")
22 self.assertTrue(transaction_id.startswith('T-'))
23
24=== modified file 'u1db/tests/test_backends.py'
25--- u1db/tests/test_backends.py 2012-07-03 13:50:27 +0000
26+++ u1db/tests/test_backends.py 2012-07-03 22:26:17 +0000
27@@ -437,67 +437,6 @@
28 self.db._put_doc_if_newer, doc, save_conflict=False,
29 replica_uid='other', replica_gen=1, replica_trans_id='T-sad')
30
31- def test_validate_gen_and_trans_id(self):
32- self.db.create_doc(simple_doc)
33- gen, trans_id = self.db._get_generation_info()
34- self.db.validate_gen_and_trans_id(gen, trans_id)
35-
36- def test_validate_gen_and_trans_id_invalid_txid(self):
37- self.db.create_doc(simple_doc)
38- gen, _ = self.db._get_generation_info()
39- self.assertRaises(
40- errors.InvalidTransactionId,
41- self.db.validate_gen_and_trans_id, gen, 'wrong')
42-
43- def test_validate_gen_and_trans_id_invalid_txid(self):
44- self.db.create_doc(simple_doc)
45- gen, trans_id = self.db._get_generation_info()
46- self.assertRaises(
47- errors.InvalidGeneration,
48- self.db.validate_gen_and_trans_id, gen + 1, trans_id)
49-
50- def test_validate_source_gen_and_trans_id_same(self):
51- self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
52- v1 = vectorclock.VectorClockRev('other:1|self:1')
53- v2 = vectorclock.VectorClockRev('other:1|self:1')
54- self.assertEqual(
55- 'superseded',
56- self.db._validate_source('other', 1, 'T-sid', v1, v2))
57-
58- def test_validate_source_gen_newer(self):
59- self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
60- v1 = vectorclock.VectorClockRev('other:1|self:1')
61- v2 = vectorclock.VectorClockRev('other:2|self:2')
62- self.assertEqual(
63- 'ok',
64- self.db._validate_source('other', 2, 'T-whatevs', v1, v2))
65-
66- def test_validate_source_wrong_txid(self):
67- self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
68- v1 = vectorclock.VectorClockRev('other:1|self:1')
69- v2 = vectorclock.VectorClockRev('other:2|self:2')
70- self.assertRaises(
71- errors.InvalidTransactionId,
72- self.db._validate_source, 'other', 1, 'T-sad', v1, v2)
73-
74- def test_validate_source_gen_older_and_vcr_older(self):
75- self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
76- self.db._set_replica_gen_and_trans_id('other', 2, 'T-sod')
77- v1 = vectorclock.VectorClockRev('other:1|self:1')
78- v2 = vectorclock.VectorClockRev('other:2|self:2')
79- self.assertEqual(
80- 'superseded',
81- self.db._validate_source('other', 1, 'T-sid', v2, v1))
82-
83- def test_validate_source_gen_older_vcr_newer(self):
84- self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
85- self.db._set_replica_gen_and_trans_id('other', 2, 'T-sod')
86- v1 = vectorclock.VectorClockRev('other:1|self:1')
87- v2 = vectorclock.VectorClockRev('other:2|self:2')
88- self.assertRaises(
89- errors.InvalidGeneration,
90- self.db._validate_source, 'other', 1, 'T-sid', v1, v2)
91-
92 def test_put_doc_if_newer_replica_uid(self):
93 doc1 = self.db.create_doc(simple_doc)
94 self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
95@@ -588,6 +527,77 @@
96 self.db.whats_changed(2))
97
98
99+class LocalDatabaseValidateGenNTransIdTests(tests.DatabaseBaseTests):
100+
101+ scenarios = tests.LOCAL_DATABASES_SCENARIOS + tests.C_DATABASE_SCENARIOS
102+
103+ def test_validate_gen_and_trans_id(self):
104+ self.db.create_doc(simple_doc)
105+ gen, trans_id = self.db._get_generation_info()
106+ self.db.validate_gen_and_trans_id(gen, trans_id)
107+
108+ def test_validate_gen_and_trans_id_invalid_txid(self):
109+ self.db.create_doc(simple_doc)
110+ gen, _ = self.db._get_generation_info()
111+ self.assertRaises(
112+ errors.InvalidTransactionId,
113+ self.db.validate_gen_and_trans_id, gen, 'wrong')
114+
115+ def test_validate_gen_and_trans_id_invalid_gen(self):
116+ self.db.create_doc(simple_doc)
117+ gen, trans_id = self.db._get_generation_info()
118+ self.assertRaises(
119+ errors.InvalidGeneration,
120+ self.db.validate_gen_and_trans_id, gen + 1, trans_id)
121+
122+
123+class LocalDatabaseValidateSourceGenTests(tests.DatabaseBaseTests):
124+
125+ scenarios = tests.LOCAL_DATABASES_SCENARIOS + tests.C_DATABASE_SCENARIOS
126+
127+ def test_validate_source_gen_and_trans_id_same(self):
128+ self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
129+ v1 = vectorclock.VectorClockRev('other:1|self:1')
130+ v2 = vectorclock.VectorClockRev('other:1|self:1')
131+ self.assertEqual(
132+ 'superseded',
133+ self.db._validate_source('other', 1, 'T-sid', v1, v2))
134+
135+ def test_validate_source_gen_newer(self):
136+ self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
137+ v1 = vectorclock.VectorClockRev('other:1|self:1')
138+ v2 = vectorclock.VectorClockRev('other:2|self:2')
139+ self.assertEqual(
140+ 'ok',
141+ self.db._validate_source('other', 2, 'T-whatevs', v1, v2))
142+
143+ def test_validate_source_wrong_txid(self):
144+ self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
145+ v1 = vectorclock.VectorClockRev('other:1|self:1')
146+ v2 = vectorclock.VectorClockRev('other:2|self:2')
147+ self.assertRaises(
148+ errors.InvalidTransactionId,
149+ self.db._validate_source, 'other', 1, 'T-sad', v1, v2)
150+
151+ def test_validate_source_gen_older_and_vcr_older(self):
152+ self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
153+ self.db._set_replica_gen_and_trans_id('other', 2, 'T-sod')
154+ v1 = vectorclock.VectorClockRev('other:1|self:1')
155+ v2 = vectorclock.VectorClockRev('other:2|self:2')
156+ self.assertEqual(
157+ 'superseded',
158+ self.db._validate_source('other', 1, 'T-sid', v2, v1))
159+
160+ def test_validate_source_gen_older_vcr_newer(self):
161+ self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
162+ self.db._set_replica_gen_and_trans_id('other', 2, 'T-sod')
163+ v1 = vectorclock.VectorClockRev('other:1|self:1')
164+ v2 = vectorclock.VectorClockRev('other:2|self:2')
165+ self.assertRaises(
166+ errors.InvalidGeneration,
167+ self.db._validate_source, 'other', 1, 'T-sid', v1, v2)
168+
169+
170 class LocalDatabaseWithConflictsTests(tests.DatabaseBaseTests):
171 # test supporting/functionality around storing conflicts
172

Subscribers

People subscribed via source and target branches