summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorBruno Wagner <bwagner@riseup.net>2015-09-16 15:59:13 -0300
committerBruno Wagner <bwagner@riseup.net>2015-09-16 16:04:58 -0300
commit3f150ba7c119ad6f7a52d05915966ac1f78a6f0b (patch)
treea0faa23fe355fac2bb7e793ab60a71fc91a78f2a /service
parentab4387345975cde8681c6af4ee92a10dc7e3be8e (diff)
Fixed duplicate document error on reruns #458
Setting up the incoming mail fetcher checked for an INBOX before the first sync, that created an INBOX on every new machine and when you removed the leap folder. We moved that right after the initial sync, along the generation of the OpenPGP keys and adapted the tests
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/bitmask_libraries/session.py37
-rw-r--r--service/test/unit/bitmask_libraries/test_session.py36
2 files changed, 28 insertions, 45 deletions
diff --git a/service/pixelated/bitmask_libraries/session.py b/service/pixelated/bitmask_libraries/session.py
index 2098c9ce..ca3c80ff 100644
--- a/service/pixelated/bitmask_libraries/session.py
+++ b/service/pixelated/bitmask_libraries/session.py
@@ -55,7 +55,7 @@ class LeapSession(object):
- ``incoming_mail_fetcher`` Background job for fetching incoming mails from LEAP server (LeapIncomingMail)
"""
- def __init__(self, provider, user_auth, mail_store, soledad_session, nicknym, soledad_account, incoming_mail_fetcher, smtp):
+ def __init__(self, provider, user_auth, mail_store, soledad_session, nicknym, soledad_account, smtp):
self.smtp = smtp
self.config = provider.config
self.provider = provider
@@ -64,27 +64,35 @@ class LeapSession(object):
self.soledad_session = soledad_session
self.nicknym = nicknym
self.account = soledad_account
- self.incoming_mail_fetcher = incoming_mail_fetcher
@defer.inlineCallbacks
def initial_sync(self):
yield self.sync()
+ yield self.after_first_sync()
+
+ def after_first_sync(self):
yield self.nicknym.generate_openpgp_key()
- yield self.start_background_jobs()
- defer.returnValue(self)
+ self.incoming_mail_fetcher = yield self._create_incoming_mail_fetcher(
+ self.nicknym,
+ self.soledad_session,
+ self.account,
+ self.account_email())
+ reactor.callFromThread(self.incoming_mail_fetcher.startService)
def account_email(self):
name = self.user_auth.username
return self.provider.address_for(name)
def close(self):
- self.stop_background_jobs()
+ self.stop_background_jobs
@defer.inlineCallbacks
- def start_background_jobs(self):
- self.incoming_mail_fetcher = yield self.incoming_mail_fetcher
-
- reactor.callFromThread(self.incoming_mail_fetcher.startService)
+ def _create_incoming_mail_fetcher(self, nicknym, soledad_session, account, user_mail):
+ inbox = yield account.callWhenReady(lambda _: account.getMailbox('INBOX'))
+ defer.returnValue(IncomingMail(nicknym.keymanager,
+ soledad_session.soledad,
+ inbox.collection,
+ user_mail))
def stop_background_jobs(self):
reactor.callFromThread(self.incoming_mail_fetcher.stopService)
@@ -124,11 +132,10 @@ class LeapSessionFactory(object):
nicknym = self._create_nicknym(account_email, auth.token, auth.uuid, soledad)
account = self._create_account(account_email, soledad)
- deferred_incoming_mail_fetcher = self._create_incoming_mail_fetcher(nicknym, soledad, account, account_email)
smtp = LeapSmtp(self._provider, auth, nicknym.keymanager)
- return LeapSession(self._provider, auth, mail_store, soledad, nicknym, account, deferred_incoming_mail_fetcher, smtp)
+ return LeapSession(self._provider, auth, mail_store, soledad, nicknym, account, smtp)
def _lookup_session(self, key):
global SESSIONS
@@ -161,11 +168,3 @@ class LeapSessionFactory(object):
return account
# memstore = MemoryStore(permanent_store=SoledadStore(soledad_session.soledad))
# return SoledadBackedAccount(uuid, soledad_session.soledad, memstore)
-
- @defer.inlineCallbacks
- def _create_incoming_mail_fetcher(self, nicknym, soledad_session, account, user_mail):
- inbox = yield account.callWhenReady(lambda _: account.getMailbox('INBOX'))
- defer.returnValue(IncomingMail(nicknym.keymanager,
- soledad_session.soledad,
- inbox.collection,
- user_mail))
diff --git a/service/test/unit/bitmask_libraries/test_session.py b/service/test/unit/bitmask_libraries/test_session.py
index ad2b10d0..e4dddf68 100644
--- a/service/test/unit/bitmask_libraries/test_session.py
+++ b/service/test/unit/bitmask_libraries/test_session.py
@@ -25,37 +25,22 @@ class SessionTest(AbstractLeapTest):
def setUp(self):
super(SessionTest, self).setUp()
- self.mail_fetcher_mock = MagicMock()
self.smtp_mock = MagicMock()
- def tearDown(self):
- self.mail_fetcher_mock = MagicMock()
-
- @defer.inlineCallbacks
def test_background_jobs_are_started_during_initial_sync(self):
- self.config.start_background_jobs = True
-
with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _:
- session = self._create_session()
- yield session.initial_sync()
-
- self.mail_fetcher_mock.startService.assert_called_once_with()
-
- def test_background_jobs_are_not_started(self):
- self.config.start_background_jobs = False
-
- with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _:
- self._create_session()
-
- self.assertFalse(self.mail_fetcher_mock.start_loop.called)
+ with patch('pixelated.bitmask_libraries.session.LeapSession._create_incoming_mail_fetcher') as mail_fetcher_mock:
+ session = self._create_session()
+ yield session.initial_sync()
+ mail_fetcher_mock.startService.assert_called_once_with()
def test_that_close_stops_background_jobs(self):
with patch('pixelated.bitmask_libraries.session.reactor.callFromThread', new=_execute_func) as _:
- session = self._create_session()
-
- session.close()
-
- self.mail_fetcher_mock.stopService.assert_called_once_with()
+ with patch('pixelated.bitmask_libraries.session.LeapSession._create_incoming_mail_fetcher') as mail_fetcher_mock:
+ session = self._create_session()
+ yield session.initial_sync()
+ session.close()
+ mail_fetcher_mock.stopService.assert_called_once_with()
def test_that_sync_deferes_to_soledad(self):
session = self._create_session()
@@ -65,8 +50,7 @@ class SessionTest(AbstractLeapTest):
self.soledad_session.sync.assert_called_once_with()
def _create_session(self):
- return LeapSession(self.provider, self.auth, self.mail_store, self.soledad_session, self.nicknym, self.soledad_account,
- self.mail_fetcher_mock, self.smtp_mock)
+ return LeapSession(self.provider, self.auth, self.mail_store, self.soledad_session, self.nicknym, self.soledad_account, self.smtp_mock)
def _execute_func(func):