summaryrefslogtreecommitdiff
path: root/common/src/leap/soledad
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-09-11 19:45:12 -0300
committerVictor Shyba <victor.shyba@gmail.com>2015-09-11 20:03:09 -0300
commit83a59cb5c29695f321354d2d0f1c0097ff34693d (patch)
treeb4baefb29bf90cdfe54bc61c2e6656d11f424fce /common/src/leap/soledad
parentf578b9b931858f3d95588f1a982fc77275853cda (diff)
[tests] simplify make_app and getTarget code
It was hardcoded for 'test', but the database name is now random. What is useful for test code is the replica_uid, database name for the SyncTarget is now coming from database name.
Diffstat (limited to 'common/src/leap/soledad')
-rw-r--r--common/src/leap/soledad/common/tests/test_sqlcipher_sync.py31
-rw-r--r--common/src/leap/soledad/common/tests/test_sync.py13
-rw-r--r--common/src/leap/soledad/common/tests/test_sync_deferred.py14
-rw-r--r--common/src/leap/soledad/common/tests/test_sync_target.py17
4 files changed, 25 insertions, 50 deletions
diff --git a/common/src/leap/soledad/common/tests/test_sqlcipher_sync.py b/common/src/leap/soledad/common/tests/test_sqlcipher_sync.py
index ead4ee5f..343b915c 100644
--- a/common/src/leap/soledad/common/tests/test_sqlcipher_sync.py
+++ b/common/src/leap/soledad/common/tests/test_sqlcipher_sync.py
@@ -731,28 +731,23 @@ class SQLCipherDatabaseSyncTests(
errors.InvalidTransactionId, self.sync, self.db1, self.db2_copy)
-def _make_local_db_and_token_http_target(test, path='test'):
+def make_local_db_and_soledad_target(
+ test, path='test',
+ source_replica_uid=uuid4().hex):
test.startTwistedServer()
- # ensure remote db exists before syncing
- db = couch.CouchDatabase.open_database(
- urljoin(test.couch_url, 'test'),
- create=True,
- replica_uid='test',
- ensure_ddocs=True)
-
- replica_uid = test._soledad._dbpool.replica_uid
+ db = test.request_state._create_database(replica_uid=os.path.basename(path))
sync_db = test._soledad._sync_db
sync_enc_pool = test._soledad._sync_enc_pool
st = soledad_sync_target(
- test, path,
- source_replica_uid=replica_uid,
+ test, db._dbname,
+ source_replica_uid=source_replica_uid,
sync_db=sync_db,
sync_enc_pool=sync_enc_pool)
return db, st
target_scenarios = [
('leap', {
- 'create_db_and_target': _make_local_db_and_token_http_target,
+ 'create_db_and_target': make_local_db_and_soledad_target,
'make_app_with_state': make_soledad_app,
'do_sync': sync_via_synchronizer_and_soledad}),
]
@@ -761,8 +756,8 @@ target_scenarios = [
class SQLCipherSyncTargetTests(
TestWithScenarios,
tests.DatabaseBaseTests,
- tests.TestCaseWithServer,
- SoledadWithCouchServerMixin):
+ SoledadWithCouchServerMixin,
+ tests.TestCaseWithServer):
# TODO: implement _set_trace_hook(_shallow) in SoledadHTTPSyncTarget so
# skipped tests can be succesfully executed.
@@ -773,13 +768,13 @@ class SQLCipherSyncTargetTests(
whitebox = False
def setUp(self):
- super(tests.DatabaseBaseTests, self).setUp()
+ super(SQLCipherSyncTargetTests, self).setUp()
self.db, self.st = self.create_db_and_target(self)
self.addCleanup(self.st.close)
self.other_changes = []
def tearDown(self):
- super(tests.DatabaseBaseTests, self).tearDown()
+ super(SQLCipherSyncTargetTests, self).setUp()
def assertLastExchangeLog(self, db, expected):
log = getattr(db, '_last_exchange_log', None)
@@ -791,10 +786,6 @@ class SQLCipherSyncTargetTests(
self.other_changes.append(
(doc.doc_id, doc.rev, doc.get_json(), gen, trans_id))
- def make_app(self):
- self.request_state = couch.CouchServerState(self.couch_url)
- return self.make_app_with_state(self.request_state)
-
def set_trace_hook(self, callback, shallow=False):
setter = (self.st._set_trace_hook if not shallow else
self.st._set_trace_hook_shallow)
diff --git a/common/src/leap/soledad/common/tests/test_sync.py b/common/src/leap/soledad/common/tests/test_sync.py
index 04e8b163..1041367b 100644
--- a/common/src/leap/soledad/common/tests/test_sync.py
+++ b/common/src/leap/soledad/common/tests/test_sync.py
@@ -147,8 +147,8 @@ class InterruptableSyncTestCase(
class TestSoledadDbSync(
TestWithScenarios,
- tests.TestCaseWithServer,
- SoledadWithCouchServerMixin):
+ SoledadWithCouchServerMixin,
+ tests.TestCaseWithServer):
"""
Test db.sync remote sync shortcut
@@ -165,10 +165,6 @@ class TestSoledadDbSync(
oauth = False
token = False
- def make_app(self):
- self.request_state = couch.CouchServerState(self.couch_url)
- return self.make_app_with_state(self.request_state)
-
def setUp(self):
"""
Need to explicitely invoke inicialization on all bases.
@@ -182,11 +178,10 @@ class TestSoledadDbSync(
"""
Need to explicitely invoke destruction on all bases.
"""
- self.db2.delete_database()
SoledadWithCouchServerMixin.tearDown(self)
# tests.TestCaseWithServer.tearDown(self)
- def do_sync(self, target_name):
+ def do_sync(self):
"""
Perform sync using SoledadSynchronizer, SoledadSyncTarget
and Token auth.
@@ -210,7 +205,7 @@ class TestSoledadDbSync(
doc1 = self.db.create_doc_from_json(tests.simple_doc)
doc2 = self.db2.create_doc_from_json(tests.nested_doc)
- local_gen_before_sync = yield self.do_sync('test')
+ local_gen_before_sync = yield self.do_sync()
gen, _, changes = self.db.whats_changed(local_gen_before_sync)
self.assertEqual(1, len(changes))
self.assertEqual(doc2.doc_id, changes[0][0])
diff --git a/common/src/leap/soledad/common/tests/test_sync_deferred.py b/common/src/leap/soledad/common/tests/test_sync_deferred.py
index a07be66f..90b00670 100644
--- a/common/src/leap/soledad/common/tests/test_sync_deferred.py
+++ b/common/src/leap/soledad/common/tests/test_sync_deferred.py
@@ -59,6 +59,7 @@ class BaseSoledadDeferredEncTest(SoledadWithCouchServerMixin):
def setUp(self):
SoledadWithCouchServerMixin.setUp(self)
+ self.startTwistedServer()
# config info
self.db1_file = os.path.join(self.tempdir, "db1.u1db")
os.unlink(self.db1_file)
@@ -103,8 +104,8 @@ class SyncTimeoutError(Exception):
class TestSoledadDbSyncDeferredEncDecr(
TestWithScenarios,
- tests.TestCaseWithServer,
- BaseSoledadDeferredEncTest):
+ BaseSoledadDeferredEncTest,
+ tests.TestCaseWithServer):
"""
Test db.sync remote sync shortcut.
@@ -122,17 +123,12 @@ class TestSoledadDbSyncDeferredEncDecr(
oauth = False
token = True
- def make_app(self):
- self.request_state = couch.CouchServerState(self.couch_url)
- return self.make_app_with_state(self.request_state)
-
def setUp(self):
"""
Need to explicitely invoke inicialization on all bases.
"""
BaseSoledadDeferredEncTest.setUp(self)
self.server = self.server_thread = None
- self.startTwistedServer()
self.syncer = None
def tearDown(self):
@@ -144,7 +140,7 @@ class TestSoledadDbSyncDeferredEncDecr(
dbsyncer.close()
BaseSoledadDeferredEncTest.tearDown(self)
- def do_sync(self, target_name):
+ def do_sync(self):
"""
Perform sync using SoledadSynchronizer, SoledadSyncTarget
and Token auth.
@@ -184,7 +180,7 @@ class TestSoledadDbSyncDeferredEncDecr(
"""
doc1 = self.db1.create_doc_from_json(tests.simple_doc)
doc2 = self.db2.create_doc_from_json(tests.nested_doc)
- local_gen_before_sync = yield self.do_sync('test')
+ local_gen_before_sync = yield self.do_sync()
gen, _, changes = self.db1.whats_changed(local_gen_before_sync)
self.assertEqual(1, len(changes))
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 da4ff034..ba556ea4 100644
--- a/common/src/leap/soledad/common/tests/test_sync_target.py
+++ b/common/src/leap/soledad/common/tests/test_sync_target.py
@@ -268,7 +268,6 @@ class TestSoledadSyncTarget(
self.patch(
IndexedCouchDatabase, '_put_doc_if_newer', bomb_put_doc_if_newer)
remote_target = self.getSyncTarget(
- 'test',
source_replica_uid='replica')
other_changes = []
@@ -318,7 +317,7 @@ class TestSoledadSyncTarget(
This test was adapted to decrypt remote content before assert.
"""
- remote_target = self.getSyncTarget('test')
+ remote_target = self.getSyncTarget()
other_docs = []
replica_uid_box = []
@@ -347,10 +346,9 @@ class TestSoledadSyncTarget(
@defer.inlineCallbacks
def test_get_sync_info(self):
- db = self.request_state._create_database('test')
+ db = self.db2
db._set_replica_gen_and_trans_id('other-id', 1, 'T-transid')
remote_target = self.getSyncTarget(
- 'test',
source_replica_uid='other-id')
sync_info = yield remote_target.get_sync_info('other-id')
self.assertEqual(
@@ -360,7 +358,6 @@ class TestSoledadSyncTarget(
@defer.inlineCallbacks
def test_record_sync_info(self):
remote_target = self.getSyncTarget(
- 'test',
source_replica_uid='other-id')
yield remote_target.record_sync_info('other-id', 2, 'T-transid')
self.assertEqual(
@@ -370,7 +367,7 @@ class TestSoledadSyncTarget(
def test_sync_exchange_receive(self):
db = self.db2
doc = db.create_doc_from_json('{"value": "there"}')
- remote_target = self.getSyncTarget('test')
+ remote_target = self.getSyncTarget()
other_changes = []
def receive_doc(doc, gen, trans_id):
@@ -423,10 +420,10 @@ class SoledadDatabaseSyncTargetTests(
self.db, self.st = make_local_db_and_soledad_target(self)
def tearDown(self):
- tests.TestCaseWithServer.tearDown(self)
- SoledadWithCouchServerMixin.tearDown(self)
self.db.close()
self.st.close()
+ tests.TestCaseWithServer.tearDown(self)
+ SoledadWithCouchServerMixin.tearDown(self)
def set_trace_hook(self, callback, shallow=False):
setter = (self.st._set_trace_hook if not shallow else
@@ -818,10 +815,6 @@ class TestSoledadDbSync(
oauth = False
token = False
- def make_app(self):
- self.request_state = couch.CouchServerState(self.couch_url)
- return self.make_app_with_state(self.request_state)
-
def setUp(self):
"""
Need to explicitely invoke inicialization on all bases.