Make registering of events for fresh accounts a bit more robust by replacing the...
authorOla Bini <ola@olabini.se>
Fri, 20 Jan 2017 19:25:54 +0000 (17:25 -0200)
committerTulio Casagrande <tuliocasagrande@gmail.com>
Sat, 21 Jan 2017 14:08:49 +0000 (12:08 -0200)
service/pixelated/config/sessions.py
service/test/unit/config/test_sessions.py

index 2bad3e3..b4d69d2 100644 (file)
@@ -154,7 +154,7 @@ class LeapSession(object):
         self.account = None
         self._has_been_initially_synced = False
         self._is_closed = False
-        register(events.KEYMANAGER_FINISHED_KEY_GENERATION, self._set_fresh_account, uid=self.account_email())
+        register(events.KEYMANAGER_FINISHED_KEY_GENERATION, self._set_fresh_account, uid=self.account_email(), replace=True)
 
     @defer.inlineCallbacks
     def first_required_sync(self):
index e2254ea..06bffc9 100644 (file)
@@ -74,13 +74,12 @@ class SessionTest(AbstractLeapTest):
         yield session.sync()
         self.soledad_session.sync.assert_called_once()
 
-    def test_session_registers_to_generated_keys(self):
+    @patch('pixelated.config.sessions.register')
+    def test_session_registers_to_generated_keys(self, register_mock):
         email = 'someone@somedomain.tld'
         self.provider.address_for.return_value = email
-        with patch('pixelated.config.sessions.register') as register_mock:
-            session = self._create_session()
-
-            register_mock.assert_called_once_with(KEYMANAGER_FINISHED_KEY_GENERATION, session._set_fresh_account, uid=email)
+        session = self._create_session()
+        register_mock.assert_called_once_with(KEYMANAGER_FINISHED_KEY_GENERATION, session._set_fresh_account, uid=email, replace=True)
 
     @patch('pixelated.config.sessions.register')
     def test_close_unregisters_from_generate_keys_events(self, _):