summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2015-08-11 11:40:34 -0300
committerBruno Wagner <bwgpro@gmail.com>2015-08-12 17:17:20 -0300
commit91828a5270ce6fbf43ed3a8cb46e5a017e1b0c7f (patch)
tree24fd15d00b3fe2dceb4f4e6c574f11b6deeb2519
parent9f9ef4198b71b0396c35822b549346cda5795bc8 (diff)
[bug] fix several things on tests
* redefine the BaseLeapTest class so it inherits from twisted.trial.unittest.TestCase. * allow passing the source_replica_uid when creating the sync target. This is needed because the SoledadHTTPSyncTarget needs to be instantiated with the source_replica_uid passed as a parameter. * close the sync target in tests that use it. * raise and U1DBError instead of an Exception on failure_and_retry test, because otherwise the u1db http app server will re-raise the Exception and twisted's WSGI server will raise the exception * set defer_decryption=False in some sync_exchange() calls so the call is consistent with soledad instantiation in tests and the new signature of that method. * yield get_sync_info() in tests that use this method.
-rw-r--r--common/src/leap/soledad/common/tests/test_sync_target.py39
-rw-r--r--common/src/leap/soledad/common/tests/util.py11
2 files changed, 35 insertions, 15 deletions
diff --git a/common/src/leap/soledad/common/tests/test_sync_target.py b/common/src/leap/soledad/common/tests/test_sync_target.py
index ecf3fc5a..8f9e6b34 100644
--- a/common/src/leap/soledad/common/tests/test_sync_target.py
+++ b/common/src/leap/soledad/common/tests/test_sync_target.py
@@ -147,15 +147,18 @@ class TestSoledadParseReceivedDocResponse(SoledadWithCouchServerMixin):
#
-def make_local_db_and_soledad_target(test, path='test'):
+def make_local_db_and_soledad_target(test, path='test',
+ source_replica_uid=uuid4().hex):
test.startTwistedServer()
db = test.request_state._create_database(os.path.basename(path))
- st = soledad_sync_target(test, path)
+ st = soledad_sync_target(test, path, source_replica_uid)
return db, st
-def make_local_db_and_token_soledad_target(test):
- db, st = make_local_db_and_soledad_target(test, 'test')
+def make_local_db_and_token_soledad_target(test,
+ source_replica_uid=uuid4().hex):
+ db, st = make_local_db_and_soledad_target(test, path='test',
+ source_replica_uid=source_replica_uid)
st.set_token_credentials('user-uuid', 'auth-token')
return db, st
@@ -174,10 +177,10 @@ class TestSoledadSyncTarget(
'sync_target': soledad_sync_target}),
]
- def getSyncTarget(self, path=None):
+ def getSyncTarget(self, path=None, source_replica_uid=uuid4().hex):
if self.port is None:
self.startTwistedServer()
- return self.sync_target(self, path)
+ return self.sync_target(self, path, source_replica_uid)
def setUp(self):
TestWithScenarios.setUp(self)
@@ -215,6 +218,7 @@ class TestSoledadSyncTarget(
self.assertEqual(1, new_gen)
self.assertGetEncryptedDoc(
db, 'doc-here', 'replica:1', '{"value": "here"}', False)
+ remote_target.close()
@defer.inlineCallbacks
def test_sync_exchange_send_failure_and_retry_scenario(self):
@@ -236,7 +240,7 @@ class TestSoledadSyncTarget(
replica_trans_id=None, number_of_docs=None,
doc_idx=None, sync_id=None):
if doc.doc_id in trigger_ids:
- raise Exception
+ raise u1db.errors.U1DBError
return _put_doc_if_newer(doc, save_conflict=save_conflict,
replica_uid=replica_uid,
replica_gen=replica_gen,
@@ -246,7 +250,9 @@ class TestSoledadSyncTarget(
from leap.soledad.common.tests.test_couch import IndexedCouchDatabase
self.patch(
IndexedCouchDatabase, '_put_doc_if_newer', bomb_put_doc_if_newer)
- remote_target = self.getSyncTarget('test')
+ remote_target = self.getSyncTarget(
+ 'test',
+ source_replica_uid='replica')
other_changes = []
def receive_doc(doc, gen, trans_id):
@@ -257,13 +263,15 @@ class TestSoledadSyncTarget(
doc2 = self.make_document('doc-here2', 'replica:1',
'{"value": "here2"}')
- with self.assertRaises(u1db.errors.HTTPError):
+ with self.assertRaises(u1db.errors.U1DBError):
yield remote_target.sync_exchange(
[(doc1, 10, 'T-sid'), (doc2, 11, 'T-sud')],
'replica',
last_known_generation=0,
last_known_trans_id=None,
- insert_doc_cb=receive_doc)
+ insert_doc_cb=receive_doc,
+ defer_decryption=False)
+
self.assertGetEncryptedDoc(
db, 'doc-here', 'replica:1', '{"value": "here"}',
False)
@@ -274,7 +282,8 @@ class TestSoledadSyncTarget(
trigger_ids = []
new_gen, trans_id = yield remote_target.sync_exchange(
[(doc2, 11, 'T-sud')], 'replica', last_known_generation=0,
- last_known_trans_id=None, insert_doc_cb=receive_doc)
+ last_known_trans_id=None, insert_doc_cb=receive_doc,
+ defer_decryption=False)
self.assertGetEncryptedDoc(
db, 'doc-here2', 'replica:1', '{"value": "here2"}',
False)
@@ -284,6 +293,7 @@ class TestSoledadSyncTarget(
self.assertEqual(
('doc-here', 'replica:1', '{"value": "here"}', 1),
other_changes[0][:-1])
+ remote_target.close()
@defer.inlineCallbacks
def test_sync_exchange_send_ensure_callback(self):
@@ -313,6 +323,7 @@ class TestSoledadSyncTarget(
self.assertEqual(db._replica_uid, replica_uid_box[0])
self.assertGetEncryptedDoc(
db, 'doc-here', 'replica:1', '{"value": "here"}', False)
+ remote_target.close()
def test_sync_exchange_in_stream_error(self):
# we bypass this test because our sync_exchange process does not
@@ -377,7 +388,8 @@ class SoledadDatabaseSyncTargetTests(
last_trans_id = self.getLastTransId(self.db)
self.assertEqual(([], 1, last_trans_id),
(self.other_changes, new_gen, last_trans_id))
- self.assertEqual(10, self.st.get_sync_info('replica')[3])
+ sync_info = yield self.st.get_sync_info('replica')
+ self.assertEqual(10, sync_info[3])
@defer.inlineCallbacks
def test_sync_exchange_push_many(self):
@@ -403,7 +415,8 @@ class SoledadDatabaseSyncTargetTests(
last_trans_id = self.getLastTransId(self.db)
self.assertEqual(([], 2, last_trans_id),
(self.other_changes, new_gen, trans_id))
- self.assertEqual(11, self.st.get_sync_info('replica')[3])
+ sync_info = yield self.st.get_sync_info('replica')
+ self.assertEqual(11, sync_info[3])
@defer.inlineCallbacks
def test_sync_exchange_returns_many_new_docs(self):
diff --git a/common/src/leap/soledad/common/tests/util.py b/common/src/leap/soledad/common/tests/util.py
index 9800078d..5506d789 100644
--- a/common/src/leap/soledad/common/tests/util.py
+++ b/common/src/leap/soledad/common/tests/util.py
@@ -175,19 +175,26 @@ class MockedSharedDBTest(object):
return defaultMockSharedDB
-def soledad_sync_target(test, path):
+def soledad_sync_target(test, path, source_replica_uid=uuid4().hex):
creds = {'token': {
'uuid': 'user-uuid',
'token': 'auth-token',
}}
return http_target.SoledadHTTPSyncTarget(
test.getURL(path),
- uuid4().hex,
+ source_replica_uid,
creds,
test._soledad._crypto,
None)
+# redefine the base leap test class so it inherits from twisted trial's
+# TestCase. This is needed so trial knows that it has to manage a reactor and
+# wait for deferreds returned by tests to be fired.
+BaseLeapTest = type(
+ 'BaseLeapTest', (unittest.TestCase,), dict(BaseLeapTest.__dict__))
+
+
class BaseSoledadTest(BaseLeapTest, MockedSharedDBTest):
"""