diff options
author | Bruno Wagner <bwgpro@gmail.com> | 2015-07-23 14:45:14 -0300 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2015-07-24 11:39:51 -0400 |
commit | 0ad34468bb736220b5c7b88f7d7c7fc8b4900b29 (patch) | |
tree | b220573d74b8dd0a5f12861617ff80ddd2dbd514 /common/src/leap/soledad/common | |
parent | e1750446e834f41548f8e141a5ca291184138c27 (diff) |
[style] fixed pep8 warnings on soledad common
Diffstat (limited to 'common/src/leap/soledad/common')
22 files changed, 174 insertions, 151 deletions
diff --git a/common/src/leap/soledad/common/__init__.py b/common/src/leap/soledad/common/__init__.py index 1e52e3a7..1ba6ab89 100644 --- a/common/src/leap/soledad/common/__init__.py +++ b/common/src/leap/soledad/common/__init__.py @@ -15,6 +15,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +from leap.common.check import leap_assert as soledad_assert +from leap.common.check import leap_assert_type as soledad_assert_type + +from ._version import get_versions """ Soledad routines common to client and server. @@ -34,11 +38,6 @@ USER_DB_PREFIX = 'user-' # Global functions # -from leap.common.check import leap_assert as soledad_assert -from leap.common.check import leap_assert_type as soledad_assert_type - - -from ._version import get_versions __version__ = get_versions()['version'] del get_versions diff --git a/common/src/leap/soledad/common/_version.py b/common/src/leap/soledad/common/_version.py index 7d4262b5..538b829d 100644 --- a/common/src/leap/soledad/common/_version.py +++ b/common/src/leap/soledad/common/_version.py @@ -1,5 +1,3 @@ - -IN_LONG_VERSION_PY = True # This file helps to compute a version number in source trees obtained from # git-archive tarball (such as those provided by githubs download-from-tag # feature). Distribution tarballs (build by setup.py sdist) and build @@ -10,12 +8,15 @@ IN_LONG_VERSION_PY = True # versioneer-0.7+ (https://github.com/warner/python-versioneer) # these strings will be replaced by git during git-archive -git_refnames = "$Format:%d$" -git_full = "$Format:%H$" - - import subprocess import sys +import re +import os.path + +IN_LONG_VERSION_PY = True + +git_refnames = "$Format:%d$" +git_full = "$Format:%H$" def run_command(args, cwd=None, verbose=False): @@ -37,9 +38,6 @@ def run_command(args, cwd=None, verbose=False): return None return stdout -import re -import os.path - def get_expanded_variables(versionfile_source): # the code embedded in _version.py can just fetch the value of these @@ -85,7 +83,7 @@ def versions_from_expanded_variables(variables, tag_prefix, verbose=False): # "stabilization", as well as "HEAD" and "master". tags = set([r for r in refs if re.search(r'\d', r)]) if verbose: - print("discarding '%s', no digits" % ",".join(refs-tags)) + print("discarding '%s', no digits" % ",".join(refs - tags)) if verbose: print("likely tags: %s" % ",".join(sorted(tags))) for ref in sorted(tags): diff --git a/common/src/leap/soledad/common/tests/test_async.py b/common/src/leap/soledad/common/tests/test_async.py index 03b8c553..5f273e08 100644 --- a/common/src/leap/soledad/common/tests/test_async.py +++ b/common/src/leap/soledad/common/tests/test_async.py @@ -91,7 +91,7 @@ class ASyncSQLCipherRetryTestCase(BaseSoledadTest): def _errback(e): if e.value[0].getErrorMessage() == "database is locked": adbapi.SQLCIPHER_CONNECTION_TIMEOUT = old_timeout - adbapi.SQLCIPHER_MAX_RETRIES = old_max_retries + adbapi.SQLCIPHER_MAX_RETRIES = old_max_retries return defer.succeed("") raise Exception @@ -131,7 +131,6 @@ class ASyncSQLCipherRetryTestCase(BaseSoledadTest): deferreds.append(d) return defer.gatherResults(deferreds, consumeErrors=True) - def _count_docs(results): _, docs = results if self.NUM_DOCS == len(docs): diff --git a/common/src/leap/soledad/common/tests/test_couch.py b/common/src/leap/soledad/common/tests/test_couch.py index d2aef9bb..48f0f51b 100644 --- a/common/src/leap/soledad/common/tests/test_couch.py +++ b/common/src/leap/soledad/common/tests/test_couch.py @@ -35,20 +35,23 @@ from leap.soledad.common.tests import u1db_tests as tests from leap.soledad.common.tests.u1db_tests import test_backends from leap.soledad.common.tests.u1db_tests import test_sync from leap.soledad.common.tests.util import CouchDBTestCase +from u1db.backends.inmemory import InMemoryIndex -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_common_backend`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- class TestCouchBackendImpl(CouchDBTestCase): def test__allocate_doc_id(self): db = couch.CouchDatabase.open_database( urljoin( - 'http://localhost:' + str(self.wrapper.port), 'u1db_tests'), - create=True, - ensure_ddocs=True) + 'http://localhost:' + str(self.wrapper.port), + 'u1db_tests' + ), + create=True, + ensure_ddocs=True) doc_id1 = db._allocate_doc_id() self.assertTrue(doc_id1.startswith('D-')) self.assertEqual(34, len(doc_id1)) @@ -56,9 +59,9 @@ class TestCouchBackendImpl(CouchDBTestCase): self.assertNotEqual(doc_id1, db._allocate_doc_id()) -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_backends`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- def make_couch_database_for_test(test, replica_uid): port = str(test.wrapper.port) @@ -151,7 +154,9 @@ class CouchTests( class CouchDatabaseTests( - TestWithScenarios, test_backends.LocalDatabaseTests, CouchDBTestCase): + TestWithScenarios, + test_backends.LocalDatabaseTests, + CouchDBTestCase): scenarios = COUCH_SCENARIOS @@ -160,8 +165,10 @@ class CouchDatabaseTests( test_backends.LocalDatabaseTests.tearDown(self) -class CouchValidateGenNTransIdTests(TestWithScenarios, - test_backends.LocalDatabaseValidateGenNTransIdTests, CouchDBTestCase): +class CouchValidateGenNTransIdTests( + TestWithScenarios, + test_backends.LocalDatabaseValidateGenNTransIdTests, + CouchDBTestCase): scenarios = COUCH_SCENARIOS @@ -170,8 +177,10 @@ class CouchValidateGenNTransIdTests(TestWithScenarios, test_backends.LocalDatabaseValidateGenNTransIdTests.tearDown(self) -class CouchValidateSourceGenTests(TestWithScenarios, - test_backends.LocalDatabaseValidateSourceGenTests, CouchDBTestCase): +class CouchValidateSourceGenTests( + TestWithScenarios, + test_backends.LocalDatabaseValidateSourceGenTests, + CouchDBTestCase): scenarios = COUCH_SCENARIOS @@ -180,31 +189,33 @@ class CouchValidateSourceGenTests(TestWithScenarios, test_backends.LocalDatabaseValidateSourceGenTests.tearDown(self) -class CouchWithConflictsTests(TestWithScenarios, - test_backends.LocalDatabaseWithConflictsTests, CouchDBTestCase): +class CouchWithConflictsTests( + TestWithScenarios, + test_backends.LocalDatabaseWithConflictsTests, + CouchDBTestCase): - scenarios = COUCH_SCENARIOS + scenarios = COUCH_SCENARIOS - def tearDown(self): - self.db.delete_database() - test_backends.LocalDatabaseWithConflictsTests.tearDown(self) + def tearDown(self): + self.db.delete_database() + test_backends.LocalDatabaseWithConflictsTests.tearDown(self) # Notice: the CouchDB backend does not have indexing capabilities, so we do # not test indexing now. -#class CouchIndexTests(test_backends.DatabaseIndexTests, CouchDBTestCase): +# class CouchIndexTests(test_backends.DatabaseIndexTests, CouchDBTestCase): # -# scenarios = COUCH_SCENARIOS +# scenarios = COUCH_SCENARIOS # -# def tearDown(self): -# self.db.delete_database() -# test_backends.DatabaseIndexTests.tearDown(self) +# def tearDown(self): +# self.db.delete_database() +# test_backends.DatabaseIndexTests.tearDown(self) -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_sync`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- target_scenarios = [ ('local', {'create_db_and_target': test_sync._make_local_db_and_target}), ] @@ -243,8 +254,6 @@ class CouchDatabaseSyncTargetTests( # The following tests need that the database have an index, so we fake one. -from u1db.backends.inmemory import InMemoryIndex - class IndexedCouchDatabase(couch.CouchDatabase): @@ -350,13 +359,18 @@ class CouchDatabaseSyncTests( test_sync.DatabaseSyncTests.setUp(self) def tearDown(self): - for db in [self.db, self.db1, self.db2, self.db3, self.db1_copy, - self.db2_copy]: + for db in [ + self.db, self.db1, self.db2, + self.db3, self.db1_copy, self.db2_copy + ]: if db is not None: db.delete_database() db.close() - for replica_uid, dbname in [('test1_copy', 'source'), - ('test2_copy', 'target'), ('test3', 'target')]: + for replica_uid, dbname in [ + ('test1_copy', 'source'), + ('test2_copy', 'target'), + ('test3', 'target') + ]: db = self.create_database(replica_uid, dbname) db.delete_database() # cleanup connections to avoid leaking of file descriptors diff --git a/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py b/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py index 3de4da1c..32f676ad 100644 --- a/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py +++ b/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py @@ -114,7 +114,7 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): docs = [doc.doc_id] for i in range(0, REPEAT_TIMES): self.assertEqual( - i+1, len(self.db._get_transaction_log())) + i + 1, len(self.db._get_transaction_log())) doc.content['ops'] += 1 self.db.put_doc(doc) docs.append(doc.doc_id) @@ -122,13 +122,13 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): # assert length of transaction_log transaction_log = self.db._get_transaction_log() self.assertEqual( - REPEAT_TIMES+1, len(transaction_log)) + REPEAT_TIMES + 1, len(transaction_log)) # assert that all entries in the log belong to the same doc - self.assertEqual(REPEAT_TIMES+1, len(docs)) + self.assertEqual(REPEAT_TIMES + 1, len(docs)) for doc_id in docs: self.assertEqual( - REPEAT_TIMES+1, + REPEAT_TIMES + 1, len(filter(lambda t: t[0] == doc_id, transaction_log))) def test_correct_transaction_log_after_sequential_deletes(self): @@ -140,16 +140,16 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): for i in range(0, REPEAT_TIMES): doc = self.db.create_doc({'ops': 0}) self.assertEqual( - 2*i+1, len(self.db._get_transaction_log())) + 2 * i + 1, len(self.db._get_transaction_log())) docs.append(doc.doc_id) self.db.delete_doc(doc) self.assertEqual( - 2*i+2, len(self.db._get_transaction_log())) + 2 * i + 2, len(self.db._get_transaction_log())) # assert length of transaction_log transaction_log = self.db._get_transaction_log() self.assertEqual( - 2*REPEAT_TIMES, len(transaction_log)) + 2 * REPEAT_TIMES, len(transaction_log)) # assert that each doc appears twice in the transaction_log self.assertEqual(REPEAT_TIMES, len(docs)) @@ -176,7 +176,7 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): def _assert_transaction_and_sync_logs(results, sync_idx): # assert sizes of transaction and sync logs self.assertEqual( - sync_idx*REPEAT_TIMES, + sync_idx * REPEAT_TIMES, len(self.db._get_transaction_log())) self.assertEqual( 1 if sync_idx > 0 else 0, @@ -184,10 +184,10 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): def _assert_sync(results, sync_idx): gen, docs = results - self.assertEqual((sync_idx+1)*REPEAT_TIMES, gen) - self.assertEqual((sync_idx+1)*REPEAT_TIMES, len(docs)) + self.assertEqual((sync_idx + 1) * REPEAT_TIMES, gen) + self.assertEqual((sync_idx + 1) * REPEAT_TIMES, len(docs)) # assert sizes of transaction and sync logs - self.assertEqual((sync_idx+1)*REPEAT_TIMES, + self.assertEqual((sync_idx + 1) * REPEAT_TIMES, len(self.db._get_transaction_log())) sync_log_rows = self.db._database.view('syncs/log').rows sync_log = sync_log_rows[0].value @@ -203,7 +203,7 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): sol_gen, sol_trans_id = conn._get_generation_info() self.assertEqual(sol_gen, known_gen) self.assertEqual(sol_trans_id, known_trans_id) - + # create some documents d = _create_docs(None) @@ -253,7 +253,6 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): self._params['docs'].append(doc.doc_id) pool.release() - for i in range(0, REPEAT_TIMES): thread = self._WorkerThread( {'docs': docs, 'db': self.db}, @@ -306,7 +305,7 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer): # assert transaction log transaction_log = self.db._get_transaction_log() self.assertEqual( - 2*REPEAT_TIMES, len(transaction_log)) + 2 * REPEAT_TIMES, len(transaction_log)) # assert that each doc appears twice in the transaction_log self.assertEqual(REPEAT_TIMES, len(docs)) for doc_id in docs: diff --git a/common/src/leap/soledad/common/tests/test_http.py b/common/src/leap/soledad/common/tests/test_http.py index 1f661b77..bedd1868 100644 --- a/common/src/leap/soledad/common/tests/test_http.py +++ b/common/src/leap/soledad/common/tests/test_http.py @@ -23,9 +23,9 @@ from leap.soledad.client import auth from leap.soledad.common.tests.u1db_tests import test_http_database -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_http_database`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- class _HTTPDatabase(http_database.HTTPDatabase, auth.TokenBasedAuth): """ diff --git a/common/src/leap/soledad/common/tests/test_http_client.py b/common/src/leap/soledad/common/tests/test_http_client.py index db731c32..fcf5f75e 100644 --- a/common/src/leap/soledad/common/tests/test_http_client.py +++ b/common/src/leap/soledad/common/tests/test_http_client.py @@ -28,9 +28,9 @@ from leap.soledad.common.tests.u1db_tests import test_http_client from leap.soledad.server.auth import SoledadTokenAuthMiddleware -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_http_client`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- class TestSoledadClientBase( TestWithScenarios, diff --git a/common/src/leap/soledad/common/tests/test_https.py b/common/src/leap/soledad/common/tests/test_https.py index 6907e3ed..93619515 100644 --- a/common/src/leap/soledad/common/tests/test_https.py +++ b/common/src/leap/soledad/common/tests/test_https.py @@ -46,13 +46,13 @@ LEAP_SCENARIOS = [ ] -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_https`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- def token_leap_https_sync_target(test, host, path, cert_file=None): _, port = test.server.server_address - #source_replica_uid = test._soledad._dbpool.replica_uid + # source_replica_uid = test._soledad._dbpool.replica_uid creds = {'token': {'uuid': 'user-uuid', 'token': 'auth-token'}} if not cert_file: cert_file = test.cacert_pem @@ -121,10 +121,11 @@ class TestSoledadHTTPSyncTargetHttpsSupport( remote_target = self.getSyncTarget('localhost', 'test') d = remote_target.record_sync_info('other-id', 2, 'T-id') d.addCallback(lambda _: - self.assertEqual( - (2, 'T-id'), db._get_replica_gen_and_trans_id('other-id'))) - d.addCallback(lambda _: - remote_target.close()) + self.assertEqual( + (2, 'T-id'), + db._get_replica_gen_and_trans_id('other-id') + )) + d.addCallback(lambda _: remote_target.close()) return d def test_host_mismatch(self): diff --git a/common/src/leap/soledad/common/tests/test_server.py b/common/src/leap/soledad/common/tests/test_server.py index a8012e08..47cbf4d1 100644 --- a/common/src/leap/soledad/common/tests/test_server.py +++ b/common/src/leap/soledad/common/tests/test_server.py @@ -374,7 +374,7 @@ class EncryptedSyncTestCase( def _db1CreateDocs(results): deferreds = [] for i in xrange(number_of_docs): - content = binascii.hexlify(os.urandom(doc_size/2)) + content = binascii.hexlify(os.urandom(doc_size / 2)) deferreds.append(sol1.create_doc({'data': content})) return defer.DeferredList(deferreds) @@ -456,7 +456,7 @@ class EncryptedSyncTestCase( """ Test if Soledad can sync very large files. """ - length = 100*(10**6) # 100 MB + length = 100 * (10**6) # 100 MB return self._test_encrypted_sym_sync(doc_size=length, number_of_docs=1) def test_sync_many_small_files(self): diff --git a/common/src/leap/soledad/common/tests/test_soledad_app.py b/common/src/leap/soledad/common/tests/test_soledad_app.py index 6efae1d6..07ad00a0 100644 --- a/common/src/leap/soledad/common/tests/test_soledad_app.py +++ b/common/src/leap/soledad/common/tests/test_soledad_app.py @@ -32,9 +32,9 @@ from leap.soledad.common.tests.util import copy_token_http_database_for_test from leap.soledad.common.tests.u1db_tests import test_backends -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_backends`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- LEAP_SCENARIOS = [ ('http', { diff --git a/common/src/leap/soledad/common/tests/test_soledad_doc.py b/common/src/leap/soledad/common/tests/test_soledad_doc.py index 4a67f80a..df9fd09e 100644 --- a/common/src/leap/soledad/common/tests/test_soledad_doc.py +++ b/common/src/leap/soledad/common/tests/test_soledad_doc.py @@ -24,9 +24,9 @@ from leap.soledad.common.tests.util import BaseSoledadTest from leap.soledad.common.tests.util import make_soledad_document_for_test -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_document`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- class TestSoledadDocument( TestWithScenarios, diff --git a/common/src/leap/soledad/common/tests/test_sqlcipher.py b/common/src/leap/soledad/common/tests/test_sqlcipher.py index ceb095b8..e1b92fb4 100644 --- a/common/src/leap/soledad/common/tests/test_sqlcipher.py +++ b/common/src/leap/soledad/common/tests/test_sqlcipher.py @@ -62,9 +62,9 @@ def sqlcipher_open(path, passphrase, create=True, document_factory=None): SQLCipherOptions(path, passphrase, create=create)) -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_common_backend`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- class TestSQLCipherBackendImpl(tests.TestCase): @@ -78,9 +78,9 @@ class TestSQLCipherBackendImpl(tests.TestCase): db.close() -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_backends`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- def make_document_for_test(test, doc_id, rev, content, has_conflicts=False): return SoledadDocument(doc_id, rev, content, has_conflicts=has_conflicts) @@ -102,19 +102,19 @@ class SQLCipherDatabaseTests(TestWithScenarios, test_backends.LocalDatabaseTests class SQLCipherValidateGenNTransIdTests( - TestWithScenarios, + TestWithScenarios, test_backends.LocalDatabaseValidateGenNTransIdTests): scenarios = SQLCIPHER_SCENARIOS class SQLCipherValidateSourceGenTests( - TestWithScenarios, + TestWithScenarios, test_backends.LocalDatabaseValidateSourceGenTests): scenarios = SQLCIPHER_SCENARIOS class SQLCipherWithConflictsTests( - TestWithScenarios, + TestWithScenarios, test_backends.LocalDatabaseWithConflictsTests): scenarios = SQLCIPHER_SCENARIOS @@ -124,9 +124,9 @@ class SQLCipherIndexTests( scenarios = SQLCIPHER_SCENARIOS -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_sqlite_backend`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- class TestSQLCipherDatabase(TestWithScenarios, test_sqlite_backend.TestSQLiteDatabase): @@ -280,7 +280,7 @@ class TestSQLCipherPartialExpandDatabase( pass def test_open_database_with_factory(self): - # SQLCipherDatabase's constructor has no factory parameter. + # SQLCipherDatabase's constructor has no factory parameter. pass def test_open_database_create(self): @@ -322,9 +322,9 @@ class TestSQLCipherPartialExpandDatabase( self.assertEqual(True, self.db.get_doc(doc.doc_id).syncable) -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_open`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- class SQLCipherOpen(test_open.TestU1DBOpen): @@ -344,7 +344,7 @@ class SQLCipherOpen(test_open.TestU1DBOpen): def test_open_with_factory(self): db = sqlcipher_open(self.db_path, PASSWORD, create=True, - document_factory=TestAlternativeDocument) + document_factory=TestAlternativeDocument) self.addCleanup(db.close) doc = db.create_doc({}) self.assertTrue(isinstance(doc, SoledadDocument)) @@ -367,9 +367,9 @@ class SQLCipherOpen(test_open.TestU1DBOpen): self.assertIsInstance(db2, SQLCipherDatabase) -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # Tests for actual encryption of the database -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- class SQLCipherEncryptionTest(BaseSoledadTest): """ 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 83c3449e..869ecf9a 100644 --- a/common/src/leap/soledad/common/tests/test_sqlcipher_sync.py +++ b/common/src/leap/soledad/common/tests/test_sqlcipher_sync.py @@ -45,12 +45,12 @@ from leap.soledad.common.tests.util import ( ) -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_sync`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- def sync_via_synchronizer_and_soledad(test, db_source, db_target, - trace_hook=None, trace_hook_shallow=None): + trace_hook=None, trace_hook_shallow=None): if trace_hook: test.skipTest("full trace hook unsupported over http") path = test._http_at[db_target] @@ -82,8 +82,8 @@ class SQLCipherDatabaseSyncTests( scenarios = sync_scenarios - #def setUp(self): - # test_sync.DatabaseSyncTests.setUp(self) + # def setUp(self): + # test_sync.DatabaseSyncTests.setUp(self) def tearDown(self): test_sync.DatabaseSyncTests.tearDown(self) @@ -123,7 +123,7 @@ class SQLCipherDatabaseSyncTests( self.assertFalse(doc.has_conflicts) # if remote content is in conflicted state, then document revisions # will be different. - #self.assertEqual(doc.rev, self.db2.get_doc('doc').rev) + # self.assertEqual(doc.rev, self.db2.get_doc('doc').rev) v = vectorclock.VectorClockRev(doc.rev) self.assertTrue(v.is_newer(vectorclock.VectorClockRev(rev1))) self.assertTrue(v.is_newer(vectorclock.VectorClockRev(rev2))) @@ -245,7 +245,7 @@ class SQLCipherDatabaseSyncTests( # update on 1 doc1.set_json('{"a": 3}') self.db1.put_doc(doc1) - # conflicts + # conflicts self.sync(self.db2, self.db1) self.sync(db3, self.db1) self.assertTrue(self.db2.get_doc('the-doc').has_conflicts) @@ -307,7 +307,7 @@ def _make_local_db_and_token_http_target(test, path='test'): target_scenarios = [ ('leap', { 'create_db_and_target': _make_local_db_and_token_http_target, -# 'make_app_with_state': tests.test_remote_sync_target.make_http_app, + # 'make_app_with_state': tests.test_remote_sync_target.make_http_app, 'make_app_with_state': make_soledad_app, 'do_sync': sync_via_synchronizer_and_soledad}), ] diff --git a/common/src/leap/soledad/common/tests/test_sync.py b/common/src/leap/soledad/common/tests/test_sync.py index 92c601dc..9449f269 100644 --- a/common/src/leap/soledad/common/tests/test_sync.py +++ b/common/src/leap/soledad/common/tests/test_sync.py @@ -80,7 +80,7 @@ class InterruptableSyncTestCase( """ A thread meant to interrupt the sync process. """ - + def __init__(self, soledad, couchdb): self._soledad = soledad self._couchdb = couchdb @@ -88,7 +88,7 @@ class InterruptableSyncTestCase( def run(self): while db._get_generation() < 2: - #print "WAITING %d" % db._get_generation() + # print "WAITING %d" % db._get_generation() time.sleep(0.1) self._soledad.stop_sync() time.sleep(1) @@ -171,16 +171,18 @@ class TestSoledadDbSync( """ Need to explicitely invoke inicialization on all bases. """ - #tests.TestCaseWithServer.setUp(self) - #self.main_test_class = test_sync.TestDbSync + # tests.TestCaseWithServer.setUp(self) + # self.main_test_class = test_sync.TestDbSync SoledadWithCouchServerMixin.setUp(self) self.startServer() self.db = self.make_database_for_test(self, 'test1') self.db2 = couch.CouchDatabase.open_database( urljoin( - 'http://localhost:' + str(self.wrapper.port), 'test'), - create=True, - ensure_ddocs=True) + 'http://localhost:' + str(self.wrapper.port), + 'test' + ), + create=True, + ensure_ddocs=True) def tearDown(self): """ @@ -188,7 +190,7 @@ class TestSoledadDbSync( """ self.db2.delete_database() SoledadWithCouchServerMixin.tearDown(self) - #tests.TestCaseWithServer.tearDown(self) + # tests.TestCaseWithServer.tearDown(self) def do_sync(self, target_name): """ 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 010f5492..33c54641 100644 --- a/common/src/leap/soledad/common/tests/test_sync_deferred.py +++ b/common/src/leap/soledad/common/tests/test_sync_deferred.py @@ -85,9 +85,11 @@ class BaseSoledadDeferredEncTest(SoledadWithCouchServerMixin): self.db2 = couch.CouchDatabase.open_database( urljoin( - 'http://localhost:' + str(self.wrapper.port), 'test'), - create=True, - ensure_ddocs=True) + 'http://localhost:' + str(self.wrapper.port), + 'test' + ), + create=True, + ensure_ddocs=True) def tearDown(self): self.db1.close() @@ -154,7 +156,7 @@ class TestSoledadDbSyncDeferredEncDecr( and Token auth. """ if self.token: - creds={'token': { + creds = {'token': { 'uuid': 'user-uuid', 'token': 'auth-token', }} @@ -163,11 +165,17 @@ class TestSoledadDbSyncDeferredEncDecr( # get a u1db syncer crypto = self._soledad._crypto replica_uid = self.db1._replica_uid - dbsyncer = SQLCipherU1DBSync(self.opts, crypto, replica_uid, + dbsyncer = SQLCipherU1DBSync( + self.opts, + crypto, + replica_uid, defer_encryption=True) self.dbsyncer = dbsyncer - return dbsyncer.sync(target_url, creds=creds, - autocreate=True,defer_decryption=DEFER_DECRYPTION) + return dbsyncer.sync( + target_url, + creds=creds, + autocreate=True, + defer_decryption=DEFER_DECRYPTION) else: return test_sync.TestDbSync.do_sync(self, target_name) 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 941dc37c..65c7a2f2 100644 --- a/common/src/leap/soledad/common/tests/test_sync_target.py +++ b/common/src/leap/soledad/common/tests/test_sync_target.py @@ -51,9 +51,9 @@ from leap.soledad.common.tests.u1db_tests import test_remote_sync_target from leap.soledad.common.tests.u1db_tests import test_sync -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_remote_sync_target`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- class TestSoledadSyncTargetBasics( test_remote_sync_target.TestHTTPSyncTargetBasics): @@ -195,7 +195,7 @@ class TestSoledadSyncTarget( self.db2 = self.request_state._create_database('test2') def tearDown(self): - #db2, _ = self.request_state.ensure_database('test2') + # db2, _ = self.request_state.ensure_database('test2') self.db2.delete_database() self.db1.close() SoledadWithCouchServerMixin.tearDown(self) @@ -326,9 +326,9 @@ class TestSoledadSyncTarget( pass -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_sync`. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- target_scenarios = [ ('token_leap', {'create_db_and_target': @@ -468,7 +468,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) @@ -510,9 +509,11 @@ class TestSoledadDbSync( self.db2 = couch.CouchDatabase.open_database( urljoin( - 'http://localhost:' + str(self.wrapper.port), 'test'), - create=True, - ensure_ddocs=True) + 'http://localhost:' + str(self.wrapper.port), + 'test' + ), + create=True, + ensure_ddocs=True) def tearDown(self): """ @@ -535,7 +536,7 @@ class TestSoledadDbSync( and Token auth. """ if self.token: - creds={'token': { + creds = {'token': { 'uuid': 'user-uuid', 'token': 'auth-token', }} @@ -545,10 +546,12 @@ class TestSoledadDbSync( crypto = self._soledad._crypto replica_uid = self.db1._replica_uid dbsyncer = SQLCipherU1DBSync(self.opts, crypto, replica_uid, - defer_encryption=True) + defer_encryption=True) self.dbsyncer = dbsyncer - return dbsyncer.sync(target_url, creds=creds, - autocreate=True,defer_decryption=DEFER_DECRYPTION) + return dbsyncer.sync(target_url, + creds=creds, + autocreate=True, + defer_decryption=DEFER_DECRYPTION) else: return test_sync.TestDbSync.do_sync(self, target_name) diff --git a/common/src/leap/soledad/common/tests/u1db_tests/__init__.py b/common/src/leap/soledad/common/tests/u1db_tests/__init__.py index 6efeb87f..787494d3 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/__init__.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/__init__.py @@ -156,7 +156,7 @@ def copy_sqlite_partial_expanded_for_test(test, db): new_db = sqlite_backend.SQLitePartialExpandDatabase(':memory:') tmpfile = StringIO() for line in db._db_handle.iterdump(): - if not 'sqlite_sequence' in line: # work around bug in iterdump + if 'sqlite_sequence' not in line: # work around bug in iterdump tmpfile.write('%s\n' % line) tmpfile.seek(0) new_db._db_handle = dbapi2.connect(':memory:') @@ -185,8 +185,9 @@ LOCAL_DATABASES_SCENARIOS = [ class DatabaseBaseTests(TestCase): - accept_fixed_trans_id = False # set to True assertTransactionLog - # is happy with all trans ids = '' + # set to True assertTransactionLog + # is happy with all trans ids = '' + accept_fixed_trans_id = False scenarios = LOCAL_DATABASES_SCENARIOS diff --git a/common/src/leap/soledad/common/tests/u1db_tests/test_backends.py b/common/src/leap/soledad/common/tests/u1db_tests/test_backends.py index 27fc50dc..f26a4474 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/test_backends.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/test_backends.py @@ -28,9 +28,6 @@ from u1db import ( from leap.soledad.common.tests import u1db_tests as tests -simple_doc = tests.simple_doc -nested_doc = tests.nested_doc - from leap.soledad.common.tests.u1db_tests.test_remote_sync_target import ( make_http_app, make_oauth_http_app, @@ -42,6 +39,9 @@ from u1db.remote import ( from unittest import skip +simple_doc = tests.simple_doc +nested_doc = tests.nested_doc + def make_http_database_for_test(test, replica_uid, path='test', *args): test.startServer() diff --git a/common/src/leap/soledad/common/tests/u1db_tests/test_document.py b/common/src/leap/soledad/common/tests/u1db_tests/test_document.py index d8a27f51..23502b4b 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/test_document.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/test_document.py @@ -26,7 +26,7 @@ class TestDocument(tests.TestCase): scenarios = ([( 'py', {'make_document_for_test': tests.make_document_for_test})]) # + - #tests.C_DATABASE_SCENARIOS) + # tests.C_DATABASE_SCENARIOS) def test_create_doc(self): doc = self.make_document('doc-id', 'uid:1', tests.simple_doc) diff --git a/common/src/leap/soledad/common/tests/u1db_tests/test_http_app.py b/common/src/leap/soledad/common/tests/u1db_tests/test_http_app.py index 522eb476..c545aa55 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/test_http_app.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/test_http_app.py @@ -24,7 +24,7 @@ except ImportError: import json # noqa import StringIO -from unittest import skip +from unittest import skip from u1db import ( __version__ as _u1db_version, diff --git a/common/src/leap/soledad/common/tests/u1db_tests/test_sync.py b/common/src/leap/soledad/common/tests/u1db_tests/test_sync.py index bac1f177..a7b05c9a 100644 --- a/common/src/leap/soledad/common/tests/u1db_tests/test_sync.py +++ b/common/src/leap/soledad/common/tests/u1db_tests/test_sync.py @@ -82,7 +82,7 @@ class DatabaseSyncTargetTests(tests.DatabaseBaseTests, scenarios = (tests.multiply_scenarios(tests.DatabaseBaseTests.scenarios, target_scenarios)) - #+ c_db_scenarios) + # + c_db_scenarios) # whitebox true means self.db is the actual local db object # against which the sync is performed whitebox = True @@ -373,8 +373,7 @@ class DatabaseSyncTargetTests(tests.DatabaseBaseTests, called) def test__set_trace_hook_shallow(self): - if (self.st._set_trace_hook_shallow == self.st._set_trace_hook - or + if (self.st._set_trace_hook_shallow == self.st._set_trace_hook or self.st._set_trace_hook_shallow.im_func == SyncTarget._set_trace_hook_shallow.im_func): # shallow same as full @@ -493,8 +492,8 @@ class DatabaseSyncTests(tests.DatabaseBaseTests, # NINJA TO YOUR HOUSE. db_copy = super(DatabaseSyncTests, self).copy_database(db) name, orig_sync_role = self._use_tracking[db] - self._use_tracking[db_copy] = (name + '(copy)', sync_role - or orig_sync_role) + self._use_tracking[db_copy] = (name + '(copy)', sync_role or + orig_sync_role) return db_copy def sync(self, db_from, db_to, trace_hook=None, diff --git a/common/src/leap/soledad/common/tests/util.py b/common/src/leap/soledad/common/tests/util.py index 60bab81c..d8d86850 100644 --- a/common/src/leap/soledad/common/tests/util.py +++ b/common/src/leap/soledad/common/tests/util.py @@ -83,7 +83,7 @@ def copy_sqlcipher_database_for_test(test, db): new_db = make_sqlcipher_database_for_test(test, None) tmpfile = StringIO() for line in db._db_handle.iterdump(): - if not 'sqlite_sequence' in line: # work around bug in iterdump + if 'sqlite_sequence' not in line: # work around bug in iterdump tmpfile.write('%s\n' % line) tmpfile.seek(0) new_db._db_handle = dbapi2.connect(':memory:') @@ -117,7 +117,7 @@ def make_token_soledad_app(state): def make_soledad_document_for_test(test, doc_id, rev, content, - has_conflicts=False): + has_conflicts=False): return SoledadDocument( doc_id, rev, content, has_conflicts=has_conflicts) @@ -155,7 +155,7 @@ def copy_token_http_database_for_test(test, db): class MockedSharedDBTest(object): def get_default_shared_mock(self, put_doc_side_effect=None, - get_doc_return_value=None): + get_doc_return_value=None): """ Get a default class for mocking the shared DB """ @@ -235,7 +235,7 @@ class BaseSoledadTest(unittest.TestCase, MockedSharedDBTest): def _delete_temporary_dirs(): # XXX should not access "private" attrs for f in [self._soledad.local_db_path, - self._soledad.secrets.secrets_path]: + self._soledad.secrets.secrets_path]: if os.path.isfile(f): os.unlink(f) # The following snippet comes from BaseLeapTest.setUpClass, but we @@ -251,7 +251,6 @@ class BaseSoledadTest(unittest.TestCase, MockedSharedDBTest): reactor.addSystemEventTrigger( "after", "shutdown", _delete_temporary_dirs) - def _soledad_instance(self, user=ADDRESS, passphrase=u'123', prefix='', secrets_path='secrets.json', @@ -306,9 +305,9 @@ class BaseSoledadTest(unittest.TestCase, MockedSharedDBTest): self.assertEqual(exp_doc.content, doc.content) -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # A wrapper for running couchdb locally. -#----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # from: https://github.com/smcq/paisley/blob/master/paisley/test/util.py # TODO: include license of above project. @@ -427,7 +426,7 @@ class CouchDBTestCase(unittest.TestCase, MockedSharedDBTest): """ self.wrapper = CouchDBWrapper() self.wrapper.start() - #self.db = self.wrapper.db + # self.db = self.wrapper.db def tearDown(self): """ @@ -435,6 +434,7 @@ class CouchDBTestCase(unittest.TestCase, MockedSharedDBTest): """ self.wrapper.stop() + class CouchServerStateForTests(CouchServerState): """ This is a slightly modified CouchDB server state that allows for creating |