summaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
Diffstat (limited to 'common/src')
-rw-r--r--common/src/leap/soledad/common/tests/test_sync_deferred.py81
-rw-r--r--common/src/leap/soledad/common/tests/test_sync_target.py3
-rw-r--r--common/src/leap/soledad/common/tests/util.py8
3 files changed, 38 insertions, 54 deletions
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 126e9b7b..ffb8a4ae 100644
--- a/common/src/leap/soledad/common/tests/test_sync_deferred.py
+++ b/common/src/leap/soledad/common/tests/test_sync_deferred.py
@@ -24,12 +24,13 @@ import shutil
from urlparse import urljoin
+from twisted.internet import defer
+
from leap.soledad.common import couch
-from leap.soledad.client.sqlcipher import (
- SQLCipherOptions,
- SQLCipherDatabase,
- SQLCipherU1DBSync,
-)
+
+from leap.soledad.client import sync
+from leap.soledad.client.sqlcipher import SQLCipherOptions
+from leap.soledad.client.sqlcipher import SQLCipherDatabase
from testscenarios import TestWithScenarios
@@ -37,6 +38,7 @@ from leap.soledad.common.tests import u1db_tests as tests
from leap.soledad.common.tests.util import ADDRESS
from leap.soledad.common.tests.util import SoledadWithCouchServerMixin
from leap.soledad.common.tests.util import make_soledad_app
+from leap.soledad.common.tests.util import soledad_sync_target
# Just to make clear how this test is different... :)
@@ -136,7 +138,7 @@ class TestSoledadDbSyncDeferredEncDecr(
"""
BaseSoledadDeferredEncTest.setUp(self)
self.server = self.server_thread = None
- self.startServer()
+ self.startTwistedServer()
self.syncer = None
def tearDown(self):
@@ -153,27 +155,18 @@ class TestSoledadDbSyncDeferredEncDecr(
Perform sync using SoledadSynchronizer, SoledadSyncTarget
and Token auth.
"""
- if self.token:
- creds = {'token': {
- 'uuid': 'user-uuid',
- 'token': 'auth-token',
- }}
- target_url = self.getURL(target_name)
-
- # get a u1db syncer
- crypto = self._soledad._crypto
- replica_uid = self.db1._replica_uid
- dbsyncer = SQLCipherU1DBSync(
- self.opts,
- crypto,
- replica_uid,
- None,
- defer_encryption=True)
- self.dbsyncer = dbsyncer
- return dbsyncer.sync(
- target_url,
- creds=creds,
- defer_decryption=DEFER_DECRYPTION)
+ replica_uid = self._soledad._dbpool.replica_uid
+ sync_db = self._soledad._sync_db
+ sync_enc_pool = self._soledad._sync_enc_pool
+ target = soledad_sync_target(
+ self, target_name,
+ source_replica_uid=replica_uid,
+ sync_db=sync_db,
+ sync_enc_pool=sync_enc_pool)
+ self.addCleanup(target.close)
+ return sync.SoledadSynchronizer(
+ self.db1,
+ target).sync(defer_decryption=True)
def wait_for_sync(self):
"""
@@ -188,6 +181,7 @@ class TestSoledadDbSyncDeferredEncDecr(
if wait >= MAX_WAIT:
raise SyncTimeoutError
+ @defer.inlineCallbacks
def test_db_sync(self):
"""
Test sync.
@@ -196,30 +190,15 @@ class TestSoledadDbSyncDeferredEncDecr(
"""
doc1 = self.db1.create_doc_from_json(tests.simple_doc)
doc2 = self.db2.create_doc_from_json(tests.nested_doc)
- d = self.do_sync('test')
-
- def _assert_successful_sync(results):
- import time
- # need to give time to the encryption to proceed
- # TODO should implement a defer list to subscribe to the
- # all-decrypted event
- time.sleep(2)
- local_gen_before_sync = results
- self.wait_for_sync()
-
- gen, _, changes = self.db1.whats_changed(local_gen_before_sync)
- self.assertEqual(1, len(changes))
-
- self.assertEqual(doc2.doc_id, changes[0][0])
- self.assertEqual(1, gen - local_gen_before_sync)
+ local_gen_before_sync = yield self.do_sync('test')
- self.assertGetEncryptedDoc(
- self.db2, doc1.doc_id, doc1.rev, tests.simple_doc, False)
- self.assertGetEncryptedDoc(
- self.db1, doc2.doc_id, doc2.rev, tests.nested_doc, False)
+ gen, _, changes = self.db1.whats_changed(local_gen_before_sync)
+ self.assertEqual(1, len(changes))
- d.addCallback(_assert_successful_sync)
- return d
+ self.assertEqual(doc2.doc_id, changes[0][0])
+ self.assertEqual(1, gen - local_gen_before_sync)
- def test_db_sync_autocreate(self):
- pass
+ self.assertGetEncryptedDoc(
+ self.db2, doc1.doc_id, doc1.rev, tests.simple_doc, False)
+ self.assertGetEncryptedDoc(
+ self.db1, doc2.doc_id, doc2.rev, tests.nested_doc, False)
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 587debcb..931e8ba6 100644
--- a/common/src/leap/soledad/common/tests/test_sync_target.py
+++ b/common/src/leap/soledad/common/tests/test_sync_target.py
@@ -152,7 +152,8 @@ def make_local_db_and_soledad_target(
source_replica_uid=uuid4().hex):
test.startTwistedServer()
db = test.request_state._create_database(os.path.basename(path))
- st = soledad_sync_target(test, path, source_replica_uid)
+ st = soledad_sync_target(
+ test, path, source_replica_uid=source_replica_uid)
return db, st
diff --git a/common/src/leap/soledad/common/tests/util.py b/common/src/leap/soledad/common/tests/util.py
index d42edf18..910a8d54 100644
--- a/common/src/leap/soledad/common/tests/util.py
+++ b/common/src/leap/soledad/common/tests/util.py
@@ -175,7 +175,9 @@ class MockedSharedDBTest(object):
return defaultMockSharedDB
-def soledad_sync_target(test, path, source_replica_uid=uuid4().hex):
+def soledad_sync_target(
+ test, path, source_replica_uid=uuid4().hex,
+ sync_db=None, sync_enc_pool=None):
creds = {'token': {
'uuid': 'user-uuid',
'token': 'auth-token',
@@ -185,7 +187,9 @@ def soledad_sync_target(test, path, source_replica_uid=uuid4().hex):
source_replica_uid,
creds,
test._soledad._crypto,
- None)
+ None, # cert_file
+ sync_db=sync_db,
+ sync_enc_pool=sync_enc_pool)
# redefine the base leap test class so it inherits from twisted trial's