summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-10-23 12:08:02 +0200
committerDuda Dornelles <ddornell@thoughtworks.com>2014-10-23 12:08:31 +0200
commit5c56864305db45f33ac1b1bda0552a7e59ff3bf2 (patch)
tree25f362fc63a67dab2a4d5b72c2729b5252f1c470 /service
parentc2bc082b710297dc9b66d8895e9b756a24b87c6a (diff)
Improving test on soldeda_querier all_mails to make it more robust and
deleting marking recent flags for all mailboxes
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/soledad_querier.py17
-rw-r--r--service/test/integration/soledad_querier_test.py21
2 files changed, 28 insertions, 10 deletions
diff --git a/service/pixelated/adapter/soledad_querier.py b/service/pixelated/adapter/soledad_querier.py
index 9187e50b..9b7c0290 100644
--- a/service/pixelated/adapter/soledad_querier.py
+++ b/service/pixelated/adapter/soledad_querier.py
@@ -25,14 +25,14 @@ class SoledadQuerier:
[self.soledad.delete_doc(doc) for doc in docs]
def _remove_dup_inboxes(self, mailbox_name):
- mailboxes = [d for d in self.soledad.get_from_index('by-type', 'mbox') if d.content['mbox'] == mailbox_name]
+ mailboxes = self.soledad.get_from_index('by-type-and-mbox', 'mbox', mailbox_name)
if len(mailboxes) == 0:
return
mailboxes_to_remove = sorted(mailboxes, key=lambda x: x.content['created'])[1:len(mailboxes)]
self._remove_many(mailboxes_to_remove)
def _remove_dup_recent(self, mailbox_name):
- rct = [d for d in self.soledad.get_from_index('by-type', 'rct') if d.content['mbox'] == mailbox_name]
+ rct = self.soledad.get_from_index('by-type-and-mbox', 'rct', mailbox_name)
if len(rct) == 0:
return
rct_to_remove = sorted(rct, key=lambda x: len(x.content['rct']), reverse=True)[1:len(rct)]
@@ -45,7 +45,10 @@ class SoledadQuerier:
def mark_all_as_not_recent(self):
for mailbox in ['INBOX', 'DRAFTS', 'SENT', 'TRASH']:
- rct = self.soledad.get_from_index('by-type-and-mbox', 'rct', mailbox)[0]
+ rct = self.soledad.get_from_index('by-type-and-mbox', 'rct', mailbox)
+ if len(rct) == 0:
+ return
+ rct = rct[0]
rct.content['rct'] = []
self.soledad.put_doc(rct)
@@ -71,7 +74,13 @@ class SoledadQuerier:
fdocs_hdocs.append((fdoc, hdoc[0]))
fdocs_hdocs_bodyphash = [(f[0], f[1], f[1].content.get('body')) for f in fdocs_hdocs]
- fdocs_hdocs_bdocs = [(f[0], f[1], self.soledad.get_from_index('by-type-and-payloadhash', 'cnt', f[2])[0]) for f in fdocs_hdocs_bodyphash]
+ fdocs_hdocs_bdocs = []
+ for fdoc, hdoc, body_phash in fdocs_hdocs_bodyphash:
+ bdoc = self.soledad.get_from_index('by-type-and-payloadhash', 'cnt', body_phash)
+ if len(bdoc) == 0:
+ continue
+ fdocs_hdocs_bdocs.append((fdoc, hdoc, bdoc[0]))
+
return [PixelatedMail.from_soledad(*raw_mail, soledad_querier=self) for raw_mail in fdocs_hdocs_bdocs]
def save_mail(self, mail):
diff --git a/service/test/integration/soledad_querier_test.py b/service/test/integration/soledad_querier_test.py
index a6d0319f..f6e9f26f 100644
--- a/service/test/integration/soledad_querier_test.py
+++ b/service/test/integration/soledad_querier_test.py
@@ -57,12 +57,21 @@ class SoledadQuerierTest(unittest.TestCase, SoledadTestBase, WithMsgFields):
self.assertEqual(3, inboxes[0].content['lastuid'])
def test_all_mails_skips_incomplete_mails(self):
- self.add_multiple_to_mailbox(1, 'INBOX')
- self.add_multiple_to_mailbox(1, 'SENT')
-
# creating incomplete mail, we will only save the fdoc
- fdoc, hdoc, bdoc = MailBuilder().build_input_mail().get_for_save(2, 'INBOX')
-
+ fdoc, hdoc, bdoc = MailBuilder().build_input_mail().get_for_save(1, 'INBOX')
self.soledad.create_doc(fdoc)
+
+ mails = self.soledad_querier.all_mails()
+ self.assertEqual(0, len(mails)) # mail is incomplete since it only has fdoc
+
+ # adding the hdoc still doesn't complete the mail
+ self.soledad.create_doc(hdoc)
+
+ mails = self.soledad_querier.all_mails()
+ self.assertEqual(0, len(mails))
+
+ # now the mail is complete
+ self.soledad.put_doc(bdoc)
+
mails = self.soledad_querier.all_mails()
- self.assertEqual(2, len(mails)) # mail is incomplete since it only has fdoc \ No newline at end of file
+ self.assertEqual(1, len(mails))