diff options
Diffstat (limited to 'common/src/leap/soledad/common/tests/util.py')
-rw-r--r-- | common/src/leap/soledad/common/tests/util.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/common/src/leap/soledad/common/tests/util.py b/common/src/leap/soledad/common/tests/util.py index fe43986c..daa9c558 100644 --- a/common/src/leap/soledad/common/tests/util.py +++ b/common/src/leap/soledad/common/tests/util.py @@ -31,13 +31,14 @@ import subprocess import time import re import traceback -from uuid import uuid4 +from uuid import uuid4 from mock import Mock from urlparse import urljoin from StringIO import StringIO from pysqlcipher import dbapi2 +from u1db import sync from u1db.errors import DatabaseDoesNotExist from u1db.remote import http_database @@ -55,20 +56,23 @@ from leap.soledad.client import Soledad from leap.soledad.client import http_target from leap.soledad.client import auth from leap.soledad.client.crypto import decrypt_doc_dict +from leap.soledad.client.sqlcipher import SQLCipherDatabase +from leap.soledad.client.sqlcipher import SQLCipherOptions from leap.soledad.server import SoledadApp from leap.soledad.server.auth import SoledadTokenAuthMiddleware -from leap.soledad.client.sqlcipher import ( - SQLCipherDatabase, - SQLCipherOptions, -) - PASSWORD = '123456' ADDRESS = 'leap@leap.se' +def make_local_db_and_target(test): + db = test.create_database('test') + st = db.get_sync_target() + return db, st + + def make_sqlcipher_database_for_test(test, replica_uid): db = SQLCipherDatabase( SQLCipherOptions(':memory:', PASSWORD)) @@ -154,6 +158,15 @@ def copy_token_http_database_for_test(test, db): return http_db +def sync_via_synchronizer(test, db_source, db_target, trace_hook=None, + trace_hook_shallow=None): + target = db_target.get_sync_target() + trace_hook = trace_hook or trace_hook_shallow + if trace_hook: + target._set_trace_hook(trace_hook) + return sync.Synchronizer(db_source, target).sync() + + class MockedSharedDBTest(object): def get_default_shared_mock(self, put_doc_side_effect=None, |