diff options
author | Ivan Alejandro <ivanalejandro0@gmail.com> | 2015-05-06 17:42:26 -0300 |
---|---|---|
committer | Ivan Alejandro <ivanalejandro0@gmail.com> | 2015-05-27 12:02:39 -0300 |
commit | 7d4ab674a167d48686f61310ff4ff6a62a545e67 (patch) | |
tree | d8ed270d0a73c50eb65f392f231c5c3107473058 | |
parent | 91674a40edb19cd241c76b27ad998bb5df404570 (diff) |
[feat] adapt to new events api on common
- Related: #6359
-rw-r--r-- | client/changes/VERSION_COMPAT | 2 | ||||
-rw-r--r-- | client/changes/feature_adapt-to-new-events-on-common | 1 | ||||
-rw-r--r-- | client/src/leap/soledad/client/api.py | 2 | ||||
-rw-r--r-- | client/src/leap/soledad/client/events.py | 29 | ||||
-rw-r--r-- | client/src/leap/soledad/client/http_target.py | 6 | ||||
-rw-r--r-- | client/src/leap/soledad/client/secrets.py | 12 | ||||
-rw-r--r-- | common/changes/VERSION_COMPAT | 10 | ||||
-rw-r--r-- | common/changes/feature_adapt-to-new-events-on-common | 1 | ||||
-rw-r--r-- | common/src/leap/soledad/common/tests/test_soledad.py | 82 |
9 files changed, 79 insertions, 66 deletions
diff --git a/client/changes/VERSION_COMPAT b/client/changes/VERSION_COMPAT index 782844d7..c0747052 100644 --- a/client/changes/VERSION_COMPAT +++ b/client/changes/VERSION_COMPAT @@ -9,3 +9,5 @@ # BEGIN DEPENDENCY LIST ------------------------- # leap.foo.bar>=x.y.z pysqlcipher>2.6.3 +leap.common>=0.4 +leap.soledad.common>=0.6.5 diff --git a/client/changes/feature_adapt-to-new-events-on-common b/client/changes/feature_adapt-to-new-events-on-common new file mode 100644 index 00000000..cd55fa7d --- /dev/null +++ b/client/changes/feature_adapt-to-new-events-on-common @@ -0,0 +1 @@ +- Adapt soledad to the new events api on leap.common. Related to #6359. diff --git a/client/src/leap/soledad/client/api.py b/client/src/leap/soledad/client/api.py index 91e0a4a0..76d6acc3 100644 --- a/client/src/leap/soledad/client/api.py +++ b/client/src/leap/soledad/client/api.py @@ -656,7 +656,7 @@ class Soledad(object): defer_decryption=defer_decryption) def _sync_callback(local_gen): - soledad_events.signal( + soledad_events.emit( soledad_events.SOLEDAD_DONE_DATA_SYNC, self.uuid) return local_gen diff --git a/client/src/leap/soledad/client/events.py b/client/src/leap/soledad/client/events.py index 88e28674..b1379521 100644 --- a/client/src/leap/soledad/client/events.py +++ b/client/src/leap/soledad/client/events.py @@ -20,28 +20,27 @@ Signaling functions. """ +from leap.common.events import emit +from leap.common.events import catalog -from leap.common import events -from leap.common.events import signal - -SOLEDAD_CREATING_KEYS = events.proto.SOLEDAD_CREATING_KEYS -SOLEDAD_DONE_CREATING_KEYS = events.proto.SOLEDAD_DONE_CREATING_KEYS -SOLEDAD_DOWNLOADING_KEYS = events.proto.SOLEDAD_DOWNLOADING_KEYS +SOLEDAD_CREATING_KEYS = catalog.SOLEDAD_CREATING_KEYS +SOLEDAD_DONE_CREATING_KEYS = catalog.SOLEDAD_DONE_CREATING_KEYS +SOLEDAD_DOWNLOADING_KEYS = catalog.SOLEDAD_DOWNLOADING_KEYS SOLEDAD_DONE_DOWNLOADING_KEYS = \ - events.proto.SOLEDAD_DONE_DOWNLOADING_KEYS -SOLEDAD_UPLOADING_KEYS = events.proto.SOLEDAD_UPLOADING_KEYS + catalog.SOLEDAD_DONE_DOWNLOADING_KEYS +SOLEDAD_UPLOADING_KEYS = catalog.SOLEDAD_UPLOADING_KEYS SOLEDAD_DONE_UPLOADING_KEYS = \ - events.proto.SOLEDAD_DONE_UPLOADING_KEYS -SOLEDAD_NEW_DATA_TO_SYNC = events.proto.SOLEDAD_NEW_DATA_TO_SYNC -SOLEDAD_DONE_DATA_SYNC = events.proto.SOLEDAD_DONE_DATA_SYNC -SOLEDAD_SYNC_SEND_STATUS = events.proto.SOLEDAD_SYNC_SEND_STATUS -SOLEDAD_SYNC_RECEIVE_STATUS = events.proto.SOLEDAD_SYNC_RECEIVE_STATUS + catalog.SOLEDAD_DONE_UPLOADING_KEYS +SOLEDAD_NEW_DATA_TO_SYNC = catalog.SOLEDAD_NEW_DATA_TO_SYNC +SOLEDAD_DONE_DATA_SYNC = catalog.SOLEDAD_DONE_DATA_SYNC +SOLEDAD_SYNC_SEND_STATUS = catalog.SOLEDAD_SYNC_SEND_STATUS +SOLEDAD_SYNC_RECEIVE_STATUS = catalog.SOLEDAD_SYNC_RECEIVE_STATUS __all__ = [ - "events", - "signal", + "catalog", + "emit", "SOLEDAD_CREATING_KEYS", "SOLEDAD_DONE_CREATING_KEYS", "SOLEDAD_DOWNLOADING_KEYS", diff --git a/client/src/leap/soledad/client/http_target.py b/client/src/leap/soledad/client/http_target.py index 5eef2df3..30590ae1 100644 --- a/client/src/leap/soledad/client/http_target.py +++ b/client/src/leap/soledad/client/http_target.py @@ -47,7 +47,7 @@ from leap.soledad.client.crypto import encrypt_doc from leap.soledad.client.crypto import decrypt_doc from leap.soledad.client.events import SOLEDAD_SYNC_SEND_STATUS from leap.soledad.client.events import SOLEDAD_SYNC_RECEIVE_STATUS -from leap.soledad.client.events import signal +from leap.soledad.client.events import emit from leap.soledad.client.encdecpool import SyncDecrypterPool @@ -311,7 +311,7 @@ class SoledadHTTPSyncTarget(SyncTarget): if self._defer_encryption: self._sync_enc_pool.delete_encrypted_doc( doc.doc_id, doc.rev) - signal(SOLEDAD_SYNC_SEND_STATUS, + emit(SOLEDAD_SYNC_SEND_STATUS, "Soledad sync send status: %d/%d" % (idx, total)) response_dict = json.loads(result)[0] @@ -535,7 +535,7 @@ class SoledadHTTPSyncTarget(SyncTarget): # end of symmetric decryption # ------------------------------------------------------------- msg = "%d/%d" % (idx, total) - signal(SOLEDAD_SYNC_RECEIVE_STATUS, msg) + emit(SOLEDAD_SYNC_RECEIVE_STATUS, msg) logger.debug("Soledad sync receive status: %s" % msg) return number_of_changes, new_generation, new_transaction_id diff --git a/client/src/leap/soledad/client/secrets.py b/client/src/leap/soledad/client/secrets.py index 96f7e906..e89e21aa 100644 --- a/client/src/leap/soledad/client/secrets.py +++ b/client/src/leap/soledad/client/secrets.py @@ -480,13 +480,13 @@ class SoledadSecrets(object): :return: a document with encrypted key material in its contents :rtype: document.SoledadDocument """ - events.signal(events.SOLEDAD_DOWNLOADING_KEYS, self._uuid) + events.emit(events.SOLEDAD_DOWNLOADING_KEYS, self._uuid) db = self._shared_db if not db: logger.warning('No shared db found') return doc = db.get_doc(self._shared_db_doc_id()) - events.signal(events.SOLEDAD_DONE_DOWNLOADING_KEYS, self._uuid) + events.emit(events.SOLEDAD_DONE_DOWNLOADING_KEYS, self._uuid) return doc def _put_secrets_in_shared_db(self): @@ -509,13 +509,13 @@ class SoledadSecrets(object): # fill doc with encrypted secrets doc.content = self._export_recovery_document() # upload secrets to server - events.signal(events.SOLEDAD_UPLOADING_KEYS, self._uuid) + events.emit(events.SOLEDAD_UPLOADING_KEYS, self._uuid) db = self._shared_db if not db: logger.warning('No shared db found') return db.put_doc(doc) - events.signal(events.SOLEDAD_DONE_UPLOADING_KEYS, self._uuid) + events.emit(events.SOLEDAD_DONE_UPLOADING_KEYS, self._uuid) # # Management of secret for symmetric encryption. @@ -635,13 +635,13 @@ class SoledadSecrets(object): :return: The id of the generated secret. :rtype: str """ - events.signal(events.SOLEDAD_CREATING_KEYS, self._uuid) + events.emit(events.SOLEDAD_CREATING_KEYS, self._uuid) # generate random secret secret = os.urandom(self.GEN_SECRET_LENGTH) secret_id = sha256(secret).hexdigest() self._secrets[secret_id] = secret self._store_secrets() - events.signal(events.SOLEDAD_DONE_CREATING_KEYS, self._uuid) + events.emit(events.SOLEDAD_DONE_CREATING_KEYS, self._uuid) return secret_id def _store_secrets(self): diff --git a/common/changes/VERSION_COMPAT b/common/changes/VERSION_COMPAT index e69de29b..cc00ecf7 100644 --- a/common/changes/VERSION_COMPAT +++ b/common/changes/VERSION_COMPAT @@ -0,0 +1,10 @@ +################################################# +# This file keeps track of the recent changes +# introduced in internal leap dependencies. +# Add your changes here so we can properly update +# requirements.pip during the release process. +# (leave header when resetting) +################################################# +# +# BEGIN DEPENDENCY LIST ------------------------- +# leap.foo.bar>=x.y.z diff --git a/common/changes/feature_adapt-to-new-events-on-common b/common/changes/feature_adapt-to-new-events-on-common new file mode 100644 index 00000000..cd55fa7d --- /dev/null +++ b/common/changes/feature_adapt-to-new-events-on-common @@ -0,0 +1 @@ +- Adapt soledad to the new events api on leap.common. Related to #6359. diff --git a/common/src/leap/soledad/common/tests/test_soledad.py b/common/src/leap/soledad/common/tests/test_soledad.py index 0b49d9f5..1cd74dad 100644 --- a/common/src/leap/soledad/common/tests/test_soledad.py +++ b/common/src/leap/soledad/common/tests/test_soledad.py @@ -20,7 +20,7 @@ Tests for general Soledad functionality. import os from mock import Mock -from leap.common.events import events_pb2 as proto +from leap.common.events import catalog from leap.soledad.common.tests.util import ( BaseSoledadTest, ADDRESS, @@ -218,7 +218,7 @@ class SoledadSignalingTestCase(BaseSoledadTest): def setUp(self): # mock signaling soledad.client.signal = Mock() - soledad.client.secrets.events.signal = Mock() + soledad.client.secrets.events.emit = Mock() # run parent's setUp BaseSoledadTest.setUp(self) @@ -240,58 +240,58 @@ class SoledadSignalingTestCase(BaseSoledadTest): - downloading keys / done downloading keys. - uploading keys / done uploading keys. """ - soledad.client.secrets.events.signal.reset_mock() + soledad.client.secrets.events.emit.reset_mock() # get a fresh instance so it emits all bootstrap signals sol = self._soledad_instance( secrets_path='alternative_stage3.json', local_db_path='alternative_stage3.u1db') # reverse call order so we can verify in the order the signals were # expected - soledad.client.secrets.events.signal.mock_calls.reverse() - soledad.client.secrets.events.signal.call_args = \ - soledad.client.secrets.events.signal.call_args_list[0] - soledad.client.secrets.events.signal.call_args_list.reverse() + soledad.client.secrets.events.emit.mock_calls.reverse() + soledad.client.secrets.events.emit.call_args = \ + soledad.client.secrets.events.emit.call_args_list[0] + soledad.client.secrets.events.emit.call_args_list.reverse() # downloading keys signals - soledad.client.secrets.events.signal.assert_called_with( - proto.SOLEDAD_DOWNLOADING_KEYS, + soledad.client.secrets.events.emit.assert_called_with( + catalog.SOLEDAD_DOWNLOADING_KEYS, ADDRESS, ) - self._pop_mock_call(soledad.client.secrets.events.signal) - soledad.client.secrets.events.signal.assert_called_with( - proto.SOLEDAD_DONE_DOWNLOADING_KEYS, + self._pop_mock_call(soledad.client.secrets.events.emit) + soledad.client.secrets.events.emit.assert_called_with( + catalog.SOLEDAD_DONE_DOWNLOADING_KEYS, ADDRESS, ) # creating keys signals - self._pop_mock_call(soledad.client.secrets.events.signal) - soledad.client.secrets.events.signal.assert_called_with( - proto.SOLEDAD_CREATING_KEYS, + self._pop_mock_call(soledad.client.secrets.events.emit) + soledad.client.secrets.events.emit.assert_called_with( + catalog.SOLEDAD_CREATING_KEYS, ADDRESS, ) - self._pop_mock_call(soledad.client.secrets.events.signal) - soledad.client.secrets.events.signal.assert_called_with( - proto.SOLEDAD_DONE_CREATING_KEYS, + self._pop_mock_call(soledad.client.secrets.events.emit) + soledad.client.secrets.events.emit.assert_called_with( + catalog.SOLEDAD_DONE_CREATING_KEYS, ADDRESS, ) # downloading once more (inside _put_keys_in_shared_db) - self._pop_mock_call(soledad.client.secrets.events.signal) - soledad.client.secrets.events.signal.assert_called_with( - proto.SOLEDAD_DOWNLOADING_KEYS, + self._pop_mock_call(soledad.client.secrets.events.emit) + soledad.client.secrets.events.emit.assert_called_with( + catalog.SOLEDAD_DOWNLOADING_KEYS, ADDRESS, ) - self._pop_mock_call(soledad.client.secrets.events.signal) - soledad.client.secrets.events.signal.assert_called_with( - proto.SOLEDAD_DONE_DOWNLOADING_KEYS, + self._pop_mock_call(soledad.client.secrets.events.emit) + soledad.client.secrets.events.emit.assert_called_with( + catalog.SOLEDAD_DONE_DOWNLOADING_KEYS, ADDRESS, ) # uploading keys signals - self._pop_mock_call(soledad.client.secrets.events.signal) - soledad.client.secrets.events.signal.assert_called_with( - proto.SOLEDAD_UPLOADING_KEYS, + self._pop_mock_call(soledad.client.secrets.events.emit) + soledad.client.secrets.events.emit.assert_called_with( + catalog.SOLEDAD_UPLOADING_KEYS, ADDRESS, ) - self._pop_mock_call(soledad.client.secrets.events.signal) - soledad.client.secrets.events.signal.assert_called_with( - proto.SOLEDAD_DONE_UPLOADING_KEYS, + self._pop_mock_call(soledad.client.secrets.events.emit) + soledad.client.secrets.events.emit.assert_called_with( + catalog.SOLEDAD_DONE_UPLOADING_KEYS, ADDRESS, ) # assert db was locked and unlocked @@ -311,7 +311,7 @@ class SoledadSignalingTestCase(BaseSoledadTest): doc.content = sol.secrets._export_recovery_document() sol.close() # reset mock - soledad.client.secrets.events.signal.reset_mock() + soledad.client.secrets.events.emit.reset_mock() # get a fresh instance so it emits all bootstrap signals shared_db = self.get_default_shared_mock(get_doc_return_value=doc) sol = self._soledad_instance( @@ -320,18 +320,18 @@ class SoledadSignalingTestCase(BaseSoledadTest): shared_db_class=shared_db) # reverse call order so we can verify in the order the signals were # expected - soledad.client.secrets.events.signal.mock_calls.reverse() - soledad.client.secrets.events.signal.call_args = \ - soledad.client.secrets.events.signal.call_args_list[0] - soledad.client.secrets.events.signal.call_args_list.reverse() + soledad.client.secrets.events.emit.mock_calls.reverse() + soledad.client.secrets.events.emit.call_args = \ + soledad.client.secrets.events.emit.call_args_list[0] + soledad.client.secrets.events.emit.call_args_list.reverse() # assert download keys signals - soledad.client.secrets.events.signal.assert_called_with( - proto.SOLEDAD_DOWNLOADING_KEYS, + soledad.client.secrets.events.emit.assert_called_with( + catalog.SOLEDAD_DOWNLOADING_KEYS, ADDRESS, ) - self._pop_mock_call(soledad.client.secrets.events.signal) - soledad.client.secrets.events.signal.assert_called_with( - proto.SOLEDAD_DONE_DOWNLOADING_KEYS, + self._pop_mock_call(soledad.client.secrets.events.emit) + soledad.client.secrets.events.emit.assert_called_with( + catalog.SOLEDAD_DONE_DOWNLOADING_KEYS, ADDRESS, ) sol.close() @@ -360,7 +360,7 @@ class SoledadSignalingTestCase(BaseSoledadTest): def _assert_done_data_sync_signal_emitted(results): # assert the signal has been emitted soledad.client.signal.assert_called_with( - proto.SOLEDAD_DONE_DATA_SYNC, + catalog.SOLEDAD_DONE_DATA_SYNC, ADDRESS, ) sol.close() |