summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-03-22 00:54:02 -0300
committerVictor Shyba <victor.shyba@gmail.com>2015-03-22 01:00:12 -0300
commit37781b4dccadb2e10589d814cd748ee6d83de9ab (patch)
treee11bdf164d2e355f87736402048b9dd8b982f157
parentabd30a888978da49ffe01025be9918854bc36c7c (diff)
extracts get_lastuid and adds tests for create_mail uid consistency.
-- Issue #334
-rw-r--r--service/pixelated/adapter/soledad/soledad_facade_mixin.py3
-rw-r--r--service/pixelated/adapter/soledad/soledad_writer_mixin.py8
-rw-r--r--service/test/unit/adapter/test_soledad_querier.py25
3 files changed, 32 insertions, 4 deletions
diff --git a/service/pixelated/adapter/soledad/soledad_facade_mixin.py b/service/pixelated/adapter/soledad/soledad_facade_mixin.py
index 2dad78b8..280fc81e 100644
--- a/service/pixelated/adapter/soledad/soledad_facade_mixin.py
+++ b/service/pixelated/adapter/soledad/soledad_facade_mixin.py
@@ -59,5 +59,8 @@ class SoledadDbFacadeMixin(object):
def get_mbox(self, mbox):
return self.soledad.get_from_index('by-type-and-mbox', 'mbox', mbox) if mbox else []
+ def get_lastuid(self, mbox_doc):
+ return mbox_doc.content['lastuid']
+
def get_search_index_masterkey(self):
return self.soledad.get_from_index('by-type', 'index_key')
diff --git a/service/pixelated/adapter/soledad/soledad_writer_mixin.py b/service/pixelated/adapter/soledad/soledad_writer_mixin.py
index c95c7b57..9c5eb47a 100644
--- a/service/pixelated/adapter/soledad/soledad_writer_mixin.py
+++ b/service/pixelated/adapter/soledad/soledad_writer_mixin.py
@@ -31,13 +31,13 @@ class SoledadWriterMixin(SoledadDbFacadeMixin, object):
self.put_doc(mail.fdoc)
def create_mail(self, mail, mailbox_name):
- mbox = self.get_mbox(mailbox_name)[0]
- uid = mbox.content['lastuid'] + 1
+ mbox_doc = self.get_mbox(mailbox_name)[0]
+ uid = self.get_lastuid(mbox_doc)
[self.create_doc(doc) for doc in mail.get_for_save(next_uid=uid, mailbox=mailbox_name)]
- mbox.content['lastuid'] = uid
- self.put_doc(mbox)
+ mbox_doc.content['lastuid'] = uid + 1
+ self.put_doc(mbox_doc)
return self.mail(mail.ident)
diff --git a/service/test/unit/adapter/test_soledad_querier.py b/service/test/unit/adapter/test_soledad_querier.py
index e977b5dc..e5ea457d 100644
--- a/service/test/unit/adapter/test_soledad_querier.py
+++ b/service/test/unit/adapter/test_soledad_querier.py
@@ -123,3 +123,28 @@ class SoledadQuerierTest(unittest.TestCase):
call_with_bad_parameters(querier.get_recent_by_mbox)
call_with_bad_parameters(querier.idents_by_mailbox)
call_with_bad_parameters(querier.get_mbox)
+
+ def test_get_lastuid(self):
+ soledad = mock()
+ mbox = mock()
+ mbox.content = {'lastuid': 0}
+ when(soledad).get_from_index('by-type-and-mbox', 'mbox', 'INBOX').thenReturn([mbox])
+ querier = SoledadQuerier(soledad)
+
+ self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 0)
+ mbox.content = {'lastuid': 1}
+ self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 1)
+
+ def test_create_mail_increments_uid(self):
+ soledad = mock()
+ mbox = mock()
+ mail = mock()
+ when(mail).get_for_save(next_uid=any(), mailbox='INBOX').thenReturn([])
+ mbox.content = {'lastuid': 0}
+ when(soledad).get_from_index('by-type-and-mbox', 'mbox', 'INBOX').thenReturn([mbox])
+ querier = SoledadQuerier(soledad)
+ when(querier).mail(any()).thenReturn([])
+
+ self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 0)
+ querier.create_mail(mail, 'INBOX')
+ self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 1)