diff options
author | Jon Newson <jon_newson@ieee.org> | 2016-02-25 07:14:06 +1100 |
---|---|---|
committer | Jon Newson <jon_newson@ieee.org> | 2016-02-25 07:14:06 +1100 |
commit | c1f468abad6717fcabc2d812e34f4217215e70a8 (patch) | |
tree | 8ee1d7fe6463eaf5edad736d8d7b058a360b78f1 /service/test/unit | |
parent | 47df3a86d7cf412d766f8a1fdd1e9b9fe15bfb45 (diff) | |
parent | 6160633ab9a54238974af3cf498024ad98fc977e (diff) |
Merge commit '6160633ab9a54238974af3cf498024ad98fc977e'
* commit '6160633ab9a54238974af3cf498024ad98fc977e':
Fix repositore clone url
Returning 'not-sign' for no signature information
Only do initial sync on session creation
Improve stopwatch output
Improve error message if send mail fails
Diffstat (limited to 'service/test/unit')
-rw-r--r-- | service/test/unit/bitmask_libraries/test_session.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/service/test/unit/bitmask_libraries/test_session.py b/service/test/unit/bitmask_libraries/test_session.py index 22c2b3d9..a41cb805 100644 --- a/service/test/unit/bitmask_libraries/test_session.py +++ b/service/test/unit/bitmask_libraries/test_session.py @@ -16,7 +16,7 @@ from mock import patch from mock import MagicMock - +from twisted.internet import defer from pixelated.bitmask_libraries.session import LeapSession, SessionCache from test_abstract_leap import AbstractLeapTest from leap.common.events.catalog import KEYMANAGER_FINISHED_KEY_GENERATION @@ -28,14 +28,22 @@ class SessionTest(AbstractLeapTest): super(SessionTest, self).setUp() self.smtp_mock = MagicMock() - def test_background_jobs_are_started_during_initial_sync(self): + @patch('pixelated.bitmask_libraries.session.register') + @patch('pixelated.bitmask_libraries.session.IMAPAccount') + @defer.inlineCallbacks + def test_background_jobs_are_started_during_initial_sync(self, *unused): + mailFetcherMock = MagicMock() with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _: - with patch('pixelated.bitmask_libraries.session.LeapSession._create_incoming_mail_fetcher') as mail_fetcher_mock: + with patch.object(LeapSession, '_create_incoming_mail_fetcher', return_value=mailFetcherMock) as _: session = self._create_session() yield session.initial_sync() - mail_fetcher_mock.startService.assert_called_once() + mailFetcherMock.startService.assert_called_once() - def test_that_close_stops_background_jobs(self): + @patch('pixelated.bitmask_libraries.session.register') + @patch('pixelated.bitmask_libraries.session.unregister') + @patch('pixelated.bitmask_libraries.session.IMAPAccount') + @defer.inlineCallbacks + def test_that_close_stops_background_jobs(self, *unused): with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _: with patch('pixelated.bitmask_libraries.session.LeapSession._create_incoming_mail_fetcher') as mail_fetcher_mock: session = self._create_session() @@ -133,6 +141,19 @@ class SessionTest(AbstractLeapTest): self.assertFalse(session.fresh_account) + @patch('pixelated.bitmask_libraries.session.register') + @patch('pixelated.bitmask_libraries.session.unregister') + @patch('pixelated.bitmask_libraries.session.IMAPAccount') + @defer.inlineCallbacks + def test_session_initial_sync_only_triggered_once(self, *unused): + mailFetcherMock = MagicMock() + with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _: + with patch.object(LeapSession, '_create_incoming_mail_fetcher', return_value=mailFetcherMock) as _: + session = self._create_session() + session._has_been_synced = True + yield session.initial_sync() + self.assertFalse(mailFetcherMock.startService.called) + def _create_session(self): return LeapSession(self.provider, self.auth, self.mail_store, self.soledad_session, self.nicknym, self.smtp_mock) |