diff options
author | drebs <drebs@leap.se> | 2013-05-15 19:53:53 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2013-05-15 19:53:53 -0300 |
commit | 7e6f458af4c7b51f414d6303942fec10dd56d2d3 (patch) | |
tree | d29bbbbe4d65db25f69f71a550097b5037d938db | |
parent | a1df8fe814d9733cfc4aea635864fc9fe7383962 (diff) |
Fix pep8 style.
-rw-r--r-- | src/leap/soledad/__init__.py | 10 | ||||
-rw-r--r-- | src/leap/soledad/auth.py | 4 | ||||
-rw-r--r-- | src/leap/soledad/server.py | 1 | ||||
-rw-r--r-- | src/leap/soledad/tests/__init__.py | 10 | ||||
-rw-r--r-- | src/leap/soledad/tests/test_crypto.py | 4 | ||||
-rw-r--r-- | src/leap/soledad/tests/test_leap_backend.py | 59 | ||||
-rw-r--r-- | src/leap/soledad/tests/test_soledad.py | 3 | ||||
-rw-r--r-- | src/leap/soledad/tests/test_sqlcipher.py | 3 | ||||
-rw-r--r-- | src/leap/soledad/tests/u1db_tests/test_https.py | 3 |
9 files changed, 54 insertions, 43 deletions
diff --git a/src/leap/soledad/__init__.py b/src/leap/soledad/__init__.py index e3313ffe..7a3540bf 100644 --- a/src/leap/soledad/__init__.py +++ b/src/leap/soledad/__init__.py @@ -286,8 +286,8 @@ class Soledad(object): 'Found cryptographic secrets in shared recovery ' 'database.') self.import_recovery_document( - doc.content[self.SECRET_KEY], - passphrase=self._passphrase) + doc.content[self.SECRET_KEY], + passphrase=self._passphrase) else: # there are no secrets in server also, so generate a secret. logger.info( @@ -398,14 +398,14 @@ class Soledad(object): """ # does the file exist in disk? if not os.path.isfile(self._secrets_path): - raise IOError('File does not exist: %s' % self._secrets_path) + raise IOError('File does not exist: %s' % self._secrets_path) # read storage secrets from file content = None with open(self._secrets_path, 'r') as f: content = json.loads(f.read()) self._secrets = content[self.STORAGE_SECRETS_KEY] # choose first secret if no secret_id was given - if self._secret_id == None: + if self._secret_id is None: self._set_secret_id(self._secrets.items()[0][0]) # check secret is isncrypted if not self._crypto.is_encrypted_sym( @@ -429,7 +429,7 @@ class Soledad(object): return True except DecryptionFailed: logger.error('Could not decrypt storage secret.') - except IOError, e: + except IOError, e: logger.error('IOError: %s' % str(e)) return False diff --git a/src/leap/soledad/auth.py b/src/leap/soledad/auth.py index 1d8f1a42..562a8263 100644 --- a/src/leap/soledad/auth.py +++ b/src/leap/soledad/auth.py @@ -44,7 +44,6 @@ class TokenBasedAuth(object): """ self._creds = {'token': (uuid, token)} - def _sign_request(self, method, url_query, params): """ Return an authorization header to be included in the HTTP request, in @@ -67,4 +66,5 @@ class TokenBasedAuth(object): auth = '%s:%s' % (uuid, token) return [('Authorization', 'Token %s' % auth.encode('base64')[:-1])] else: - return HTTPClientBase._sign_request(self, method, url_query, params) + return HTTPClientBase._sign_request( + self, method, url_query, params) diff --git a/src/leap/soledad/server.py b/src/leap/soledad/server.py index e7b55a3e..7aa253a3 100644 --- a/src/leap/soledad/server.py +++ b/src/leap/soledad/server.py @@ -187,7 +187,6 @@ class SoledadAuthMiddleware(object): return not environ.get(self.PATH_INFO_KEY).startswith('/shared/') - #----------------------------------------------------------------------------- # Soledad WSGI application #----------------------------------------------------------------------------- diff --git a/src/leap/soledad/tests/__init__.py b/src/leap/soledad/tests/__init__.py index 6ddc9832..07038910 100644 --- a/src/leap/soledad/tests/__init__.py +++ b/src/leap/soledad/tests/__init__.py @@ -44,7 +44,8 @@ class BaseSoledadTest(BaseLeapTest): self._db2.close() self._soledad.close() - def _soledad_instance(self, user='leap@leap.se', passphrase='123', prefix='', + def _soledad_instance(self, user='leap@leap.se', passphrase='123', + prefix='', secrets_path=Soledad.STORAGE_SECRETS_FILE_NAME, local_db_path='/soledad.u1db', server_url='', cert_file=None): @@ -69,8 +70,11 @@ class BaseSoledadTest(BaseLeapTest): server_url=server_url, # Soledad will fail if not given an url. cert_file=cert_file) - def assertGetEncryptedDoc(self, db, doc_id, doc_rev, content, has_conflicts): - """Assert that the document in the database looks correct.""" + def assertGetEncryptedDoc( + self, db, doc_id, doc_rev, content, has_conflicts): + """ + Assert that the document in the database looks correct. + """ exp_doc = self.make_document(doc_id, doc_rev, content, has_conflicts=has_conflicts) doc = db.get_doc(doc_id) diff --git a/src/leap/soledad/tests/test_crypto.py b/src/leap/soledad/tests/test_crypto.py index 6804723a..9a219bd0 100644 --- a/src/leap/soledad/tests/test_crypto.py +++ b/src/leap/soledad/tests/test_crypto.py @@ -75,7 +75,8 @@ class EncryptedSyncTestCase(BaseSoledadTest): # encrypt doc doc1.set_json(encrypt_doc(self._soledad._crypto, doc1)) # assert content is different and includes keys - self.assertNotEqual(simpledoc, doc1.content, + self.assertNotEqual( + simpledoc, doc1.content, 'incorrect document encryption') self.assertTrue(ENC_JSON_KEY in doc1.content) self.assertTrue(ENC_SCHEME_KEY in doc1.content) @@ -84,7 +85,6 @@ class EncryptedSyncTestCase(BaseSoledadTest): self.assertEqual( simpledoc, doc1.content, 'incorrect document encryption') - def test_encrypt_sym(self): """ Test for successful symmetric encryption. diff --git a/src/leap/soledad/tests/test_leap_backend.py b/src/leap/soledad/tests/test_leap_backend.py index 9bd7b604..8afae6f6 100644 --- a/src/leap/soledad/tests/test_leap_backend.py +++ b/src/leap/soledad/tests/test_leap_backend.py @@ -106,7 +106,8 @@ def make_token_http_database_for_test(test, replica_uid): auth.TokenBasedAuth.set_token_credentials(self, uuid, token) def _sign_request(self, method, url_query, params): - return auth.TokenBasedAuth._sign_request(self, method, url_query, params) + return auth.TokenBasedAuth._sign_request( + self, method, url_query, params) http_db = _HTTPDatabaseWithToken(test.getURL('test')) http_db.set_token_credentials('user-uuid', 'auth-token') @@ -162,7 +163,8 @@ class TestLeapClientBase(test_http_client.TestHTTPClientBase): auth.TokenBasedAuth.set_token_credentials(self, uuid, token) def _sign_request(self, method, url_query, params): - return auth.TokenBasedAuth._sign_request(self, method, url_query, params) + return auth.TokenBasedAuth._sign_request( + self, method, url_query, params) return _HTTPClientWithToken(self.getURL('dbase'), **kwds) @@ -185,7 +187,8 @@ class TestLeapClientBase(test_http_client.TestHTTPClientBase): pass def app(self, environ, start_response): - res = test_http_client.TestHTTPClientBase.app(self, environ, start_response) + res = test_http_client.TestHTTPClientBase.app( + self, environ, start_response) if res is not None: return res # mime solead application here. @@ -195,13 +198,13 @@ class TestLeapClientBase(test_http_client.TestHTTPClientBase): start_response("401 Unauthorized", [('Content-Type', 'application/json')]) return [json.dumps({"error": "unauthorized", - "message": e.message})] + "message": e.message})] scheme, encoded = auth.split(None, 1) if scheme.lower() != 'token': start_response("401 Unauthorized", [('Content-Type', 'application/json')]) return [json.dumps({"error": "unauthorized", - "message": e.message})] + "message": e.message})] uuid, token = encoded.decode('base64').split(':', 1) if uuid != 'user-uuid' and token != 'auth-token': return unauth_err("Incorrect address or token.") @@ -228,7 +231,6 @@ class TestLeapClientBase(test_http_client.TestHTTPClientBase): ['/dbase/doc/token', 'user-uuid', 'auth-token'], json.loads(res)) - #----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_document`. #----------------------------------------------------------------------------- @@ -366,6 +368,7 @@ def oauth_leap_sync_target(test, path): tests.token1.key, tests.token1.secret) return st + def token_leap_sync_target(test, path): st = leap_sync_target(test, path) st.set_token_credentials('user-uuid', 'auth-token') @@ -373,7 +376,7 @@ def token_leap_sync_target(test, path): class TestLeapSyncTarget( - test_remote_sync_target.TestRemoteSyncTargets, BaseSoledadTest): + test_remote_sync_target.TestRemoteSyncTargets, BaseSoledadTest): scenarios = [ ('http', {'make_app_with_state': make_soledad_app, @@ -382,9 +385,10 @@ class TestLeapSyncTarget( ('oauth_http', {'make_app_with_state': make_oauth_http_app, 'make_document_for_test': make_leap_document_for_test, 'sync_target': oauth_leap_sync_target}), - ('token_soledad', {'make_app_with_state': make_token_soledad_app, - 'make_document_for_test': make_leap_document_for_test, - 'sync_target': token_leap_sync_target}), + ('token_soledad', + {'make_app_with_state': make_token_soledad_app, + 'make_document_for_test': make_leap_document_for_test, + 'sync_target': token_leap_sync_target}), ] def test_sync_exchange_send(self): @@ -522,10 +526,11 @@ class TestLeapSyncTargetHttpsSupport(test_https.TestHttpSyncTargetHttpsSupport, BaseSoledadTest): scenarios = [ - ('token_soledad_https', {'server_def': test_https.https_server_def, - 'make_app_with_state': make_token_soledad_app, - 'make_document_for_test': make_leap_document_for_test, - 'sync_target': token_leap_https_sync_target}), + ('token_soledad_https', + {'server_def': test_https.https_server_def, + 'make_app_with_state': make_token_soledad_app, + 'make_document_for_test': make_leap_document_for_test, + 'sync_target': token_leap_https_sync_target}), ] def setUp(self): @@ -567,6 +572,7 @@ class TestLeapSyncTargetHttpsSupport(test_https.TestHttpSyncTargetHttpsSupport, http_client.CertificateError, remote_target.record_sync_info, 'other-id', 2, 'T-id') + #----------------------------------------------------------------------------- # The following tests come from `u1db.tests.test_http_database`. #----------------------------------------------------------------------------- @@ -584,7 +590,8 @@ class _HTTPDatabase(http_database.HTTPDatabase, auth.TokenBasedAuth): self, method, url_query, params) -class TestHTTPDatabaseWithCreds(test_http_database.TestHTTPDatabaseCtrWithCreds): +class TestHTTPDatabaseWithCreds( + test_http_database.TestHTTPDatabaseCtrWithCreds): def test_get_sync_target_inherits_token_credentials(self): # this test was from TestDatabaseSimpleOperations but we put it here @@ -594,7 +601,6 @@ class TestHTTPDatabaseWithCreds(test_http_database.TestHTTPDatabaseCtrWithCreds) st = self.db.get_sync_target() self.assertEqual(self.db._creds, st._creds) - def test_ctr_with_creds(self): db1 = _HTTPDatabase('http://dbs/db', creds={'token': { 'uuid': 'user-uuid', @@ -657,7 +663,6 @@ class LeapDatabaseSyncTargetTests( (self.other_changes, new_gen, last_trans_id)) self.assertEqual(10, self.st.get_sync_info('replica')[3]) - def test_sync_exchange_push_many(self): """ Test sync exchange. @@ -665,9 +670,10 @@ class LeapDatabaseSyncTargetTests( This test was adapted to decrypt remote content before assert. """ docs_by_gen = [ - (self.make_document('doc-id', 'replica:1', tests.simple_doc), 10, 'T-1'), - (self.make_document('doc-id2', 'replica:1', tests.nested_doc), 11, - 'T-2')] + (self.make_document( + 'doc-id', 'replica:1', tests.simple_doc), 10, 'T-1'), + (self.make_document( + 'doc-id2', 'replica:1', tests.nested_doc), 11, 'T-2')] new_gen, trans_id = self.st.sync_exchange( docs_by_gen, 'replica', last_known_generation=0, last_known_trans_id=None, return_doc_cb=self.receive_doc) @@ -681,7 +687,6 @@ class LeapDatabaseSyncTargetTests( (self.other_changes, new_gen, trans_id)) self.assertEqual(11, self.st.get_sync_info('replica')[3]) - def test_sync_exchange_returns_many_new_docs(self): """ Test sync exchange. @@ -765,10 +770,10 @@ class TestLeapDbSync(test_sync.TestDbSync, BaseSoledadTest): self.assertEqual(1, len(changes)) self.assertEqual(doc2.doc_id, changes[0][0]) self.assertEqual(1, gen - local_gen_before_sync) - self.assertGetEncryptedDoc(self.db2, doc1.doc_id, doc1.rev, tests.simple_doc, - False) - self.assertGetEncryptedDoc(self.db, doc2.doc_id, doc2.rev, tests.nested_doc, - False) + self.assertGetEncryptedDoc( + self.db2, doc1.doc_id, doc1.rev, tests.simple_doc, False) + self.assertGetEncryptedDoc( + self.db, doc2.doc_id, doc2.rev, tests.nested_doc, False) def test_db_sync_autocreate(self): """ @@ -784,8 +789,8 @@ class TestLeapDbSync(test_sync.TestDbSync, BaseSoledadTest): gen, _, changes = db3.whats_changed() self.assertEqual(1, len(changes)) self.assertEqual(doc1.doc_id, changes[0][0]) - self.assertGetEncryptedDoc(db3, doc1.doc_id, doc1.rev, tests.simple_doc, - False) + self.assertGetEncryptedDoc( + db3, doc1.doc_id, doc1.rev, tests.simple_doc, False) t_gen, _ = self.db._get_replica_gen_and_trans_id('test3.db') s_gen, _ = db3._get_replica_gen_and_trans_id('test1') self.assertEqual(1, t_gen) diff --git a/src/leap/soledad/tests/test_soledad.py b/src/leap/soledad/tests/test_soledad.py index 49358ab6..6a4261c0 100644 --- a/src/leap/soledad/tests/test_soledad.py +++ b/src/leap/soledad/tests/test_soledad.py @@ -69,7 +69,8 @@ class AuxMethodsTestCase(BaseSoledadTest): secrets_path=None, local_db_path=None, server_url='', cert_file=None) # otherwise Soledad will fail. self.assertEquals( - os.path.join(sol.DEFAULT_PREFIX, Soledad.STORAGE_SECRETS_FILE_NAME), + os.path.join( + sol.DEFAULT_PREFIX, Soledad.STORAGE_SECRETS_FILE_NAME), sol.secrets_path) self.assertEquals( os.path.join(sol.DEFAULT_PREFIX, 'soledad.u1db'), diff --git a/src/leap/soledad/tests/test_sqlcipher.py b/src/leap/soledad/tests/test_sqlcipher.py index ea56edc9..60261111 100644 --- a/src/leap/soledad/tests/test_sqlcipher.py +++ b/src/leap/soledad/tests/test_sqlcipher.py @@ -712,7 +712,8 @@ class SQLCipherSyncTargetTests( sever-side. """ docs_by_gen = [ - (self.make_document('doc-id', 'replica:1', tests.simple_doc), 10, 'T-1'), + (self.make_document( + 'doc-id', 'replica:1', tests.simple_doc), 10, 'T-1'), (self.make_document('doc-id2', 'replica:1', tests.nested_doc), 11, 'T-2')] new_gen, trans_id = self.st.sync_exchange( diff --git a/src/leap/soledad/tests/u1db_tests/test_https.py b/src/leap/soledad/tests/u1db_tests/test_https.py index b4b14722..62180f8c 100644 --- a/src/leap/soledad/tests/u1db_tests/test_https.py +++ b/src/leap/soledad/tests/u1db_tests/test_https.py @@ -74,7 +74,8 @@ class TestHttpSyncTargetHttpsSupport(tests.TestCaseWithServer): # class with one that will do HTTPS independent of the platform. In # order to maintain the compatibility with u1db default tests, we undo # that replacement here. - http_client._VerifiedHTTPSConnection = soledad.old__VerifiedHTTPSConnection + http_client._VerifiedHTTPSConnection = \ + soledad.old__VerifiedHTTPSConnection super(TestHttpSyncTargetHttpsSupport, self).setUp() def getSyncTarget(self, host, path=None): |