summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Maia and Victor Shyba <pixelated-team+pmaia+vshyba@thoughtworks.com>2014-09-07 22:46:09 +0000
committerPatrick Maia <pmaia@thoughtworks.com>2014-09-07 22:46:09 +0000
commit733f2b7d6c76ac917720a4b4874c8165e8f34f5a (patch)
treef88f9fccd19c8aec3e14cb25a5f63fe13ad3b651
parent2b04f7a243b2c8c68f45dd60efdc5c38249ac220 (diff)
#51 - initializes index with all mail tags if it is empty
-rw-r--r--service/pixelated/adapter/pixelated_mailbox.py3
-rw-r--r--service/test/adapter/pixelated_mailbox_test.py9
-rw-r--r--service/test/adapter/test_helper.py4
3 files changed, 14 insertions, 2 deletions
diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py
index 61fd42dc..a5b07660 100644
--- a/service/pixelated/adapter/pixelated_mailbox.py
+++ b/service/pixelated/adapter/pixelated_mailbox.py
@@ -28,6 +28,9 @@ class PixelatedMailbox:
def __init__(self, leap_mailbox, index_file_path):
self.leap_mailbox = leap_mailbox
self.tag_index = TagIndex(index_file_path)
+ if self.tag_index.empty():
+ for mail in self.mails():
+ self.notify_tags_updated(mail.tags, [], mail.ident)
for tag in self.SPECIAL_TAGS:
self.tag_index.add(tag)
diff --git a/service/test/adapter/pixelated_mailbox_test.py b/service/test/adapter/pixelated_mailbox_test.py
index 2944275f..e763d8fe 100644
--- a/service/test/adapter/pixelated_mailbox_test.py
+++ b/service/test/adapter/pixelated_mailbox_test.py
@@ -53,3 +53,12 @@ class TestPixelatedMailbox(unittest.TestCase):
self.assertEquals(0, mailbox.tag_index.get('inbox').total)
mailbox.notify_tags_updated(set(['inbox']), set(['one_tag']), 12)
self.assertEquals(1, mailbox.tag_index.get('inbox').total)
+
+ def test_index_is_initialized_with_mail_tags_if_empty(self):
+ mail_one = test_helper.leap_mail(uid=0, extra_headers={'X-Tags': ['tag_1']})
+ mail_two = test_helper.leap_mail(uid=1, extra_headers={'X-Tags': ['tag_2']})
+
+ leap_mailbox = test_helper.leap_mailbox(messages=[mail_one, mail_two])
+
+ mailbox = PixelatedMailbox(leap_mailbox, self.db_file_path)
+ self.assertEquals(set([Tag('tag_1'), Tag('tag_2'), Tag('inbox'), Tag('sent'), Tag('drafts'), Tag('trash')]), mailbox.all_tags())
diff --git a/service/test/adapter/test_helper.py b/service/test/adapter/test_helper.py
index 70673481..7bf19a42 100644
--- a/service/test/adapter/test_helper.py
+++ b/service/test/adapter/test_helper.py
@@ -49,6 +49,6 @@ def leap_mail(uid=0, flags=LEAP_FLAGS, headers=DEFAULT_HEADERS, extra_headers={}
hdoc=Mock(content={'headers': headers}))
-def leap_mailbox():
+def leap_mailbox(messages=[leap_mail(uid=6)]):
return Mock(_get_mbox_doc=Mock(return_value=None),
- messages=[leap_mail(uid=6)])
+ messages=messages)