summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/mail_service.py8
-rw-r--r--service/pixelated/tags.py3
-rw-r--r--service/test/adapter/mail_service_test.py33
-rw-r--r--service/test/adapter/pixelated_mail_test.py18
-rw-r--r--service/test/adapter/test_helper.py4
5 files changed, 32 insertions, 34 deletions
diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py
index 6498a2e7..fc8002a1 100644
--- a/service/pixelated/adapter/mail_service.py
+++ b/service/pixelated/adapter/mail_service.py
@@ -30,7 +30,11 @@ class MailService:
self.provider = LeapProvider(self.server_name, self.leap_config)
self.leap_session = LeapSessionFactory(self.provider).create(LeapCredentials(self.username, self.password))
self.account = self.leap_session.account
- self.mailbox = self.account.getMailbox(self.mailbox_name)
+
+ @property
+ def mailbox(self):
+ return self.account.getMailbox(self.mailbox_name)
+
def mails(self, query):
mails = self.mailbox.messages or []
@@ -49,7 +53,7 @@ class MailService:
self.tags.add(tag)
def _update_flags(self, new_tags, mail_id):
- new_tags_flag_name = ['tag_' + tag.name for tag in new_tags]
+ new_tags_flag_name = ['tag_' + tag.name for tag in new_tags if tag.name not in Tags.SPECIAL_TAGS]
self.set_flags(mail_id, new_tags_flag_name)
def set_flags(self, mail_id, new_tags_flag_name):
diff --git a/service/pixelated/tags.py b/service/pixelated/tags.py
index 7452b7d6..cae5987e 100644
--- a/service/pixelated/tags.py
+++ b/service/pixelated/tags.py
@@ -27,6 +27,9 @@ class Tag:
}
}
+ def __repr__(self):
+ return self.name
+
class Tags:
diff --git a/service/test/adapter/mail_service_test.py b/service/test/adapter/mail_service_test.py
index 0c6538dc..1219307e 100644
--- a/service/test/adapter/mail_service_test.py
+++ b/service/test/adapter/mail_service_test.py
@@ -5,38 +5,19 @@ from mock import Mock, MagicMock, patch
import test_helper
from pixelated.tags import Tag
-
class TestMailService(unittest.TestCase):
- def _raw_mail(self):
- return {
- "header":
- {
- "to": ["p@k.s"],
- "from": "a@y.t",
- "subject": "Test",
- "date": "2007-09-28T06:11:03-03:00"
- },
- "ident": 6,
- "tags": ["instagramer"],
- "status": [],
- "security_casing": {},
- "draft_reply_for": [],
- "body": "teste"
- }
-
@patch.object(MailService, 'set_flags', return_value=None)
- def test_custom_tags_get_created_if_not_exists(self, setFlags):
+ def test_custom_tags_get_created_if_not_exists(self, mockSetFlags):
MailService._open_leap_session = lambda self: None
- MailService.mailbox = Mock(messages=[test_helper.leap_mail(uid=6)])
+ MailService.mailbox = Mock(messages=[test_helper.leap_mail(uid=6, leap_flags=['\\Recent'])])
MailService.account = Mock(return_value=MagicMock())
mailservice = MailService()
- new_tags = ['test']
- mails = mailservice.update_tags(6, new_tags)
-
- for tag in mailservice.all_tags():
- print tag.name
+ new_tags = ['test', 'inbox']
+ updated_tags = mailservice.update_tags(6, new_tags)
- self.assertIn(Tag('test'), mailservice.all_tags())
+ self.assertEquals(set([Tag('test'), Tag('inbox')]), set(updated_tags))
+ # make sure that special tags are skipped when setting leap flags (eg.: tag_inbox)
+ mockSetFlags.assert_called_with(6, ['tag_test'])
diff --git a/service/test/adapter/pixelated_mail_test.py b/service/test/adapter/pixelated_mail_test.py
index 923398ed..ae444098 100644
--- a/service/test/adapter/pixelated_mail_test.py
+++ b/service/test/adapter/pixelated_mail_test.py
@@ -8,15 +8,24 @@ import test_helper
class TestPixelatedMail(unittest.TestCase):
- def test_leap_flags_that_are_tags_are_handled(self):
- pixelated_mail = PixelatedMail(test_helper.leap_mail())
+ def test_leap_recent_flag_is_translated_to_inbox_tag(self):
+ pixelated_mail = PixelatedMail(test_helper.leap_mail(leap_flags=['\\Recent']))
self.assertIn(Tag('inbox'), pixelated_mail.tags)
+
+ def test_leap_deleted_flag_is_translated_to_trash_tag(self):
+ pixelated_mail = PixelatedMail(test_helper.leap_mail(leap_flags=['\\Deleted']))
self.assertIn(Tag('trash'), pixelated_mail.tags)
+
+ def test_leap_draft_flag_is_translated_to_draft_tag(self):
+ pixelated_mail = PixelatedMail(test_helper.leap_mail(leap_flags=['\\Draft']))
self.assertIn(Tag('drafts'), pixelated_mail.tags)
- def test_leap_flags_that_are_status_are_handled(self):
- pixelated_mail = PixelatedMail(test_helper.leap_mail())
+ def test_leap_seen_flag_is_translated_to_read_status(self):
+ pixelated_mail = PixelatedMail(test_helper.leap_mail(leap_flags=['\\Seen']))
self.assertIn('read', pixelated_mail.status)
+
+ def test_leap_answered_flag_is_translated_to_replied_status(self):
+ pixelated_mail = PixelatedMail(test_helper.leap_mail(leap_flags=['\\Answered']))
self.assertIn('replied', pixelated_mail.status)
def test_leap_flags_that_are_custom_tags_are_handled(self):
@@ -26,3 +35,4 @@ class TestPixelatedMail(unittest.TestCase):
def test_custom_tags_containing_our_prefix_are_handled(self):
pixelated_mail = PixelatedMail(test_helper.leap_mail(extra_flags=['tag_tag_work_tag_']))
self.assertIn(Tag('tag_work_tag_'), pixelated_mail.tags)
+
diff --git a/service/test/adapter/test_helper.py b/service/test/adapter/test_helper.py
index 3731dfe8..dd063bc4 100644
--- a/service/test/adapter/test_helper.py
+++ b/service/test/adapter/test_helper.py
@@ -10,8 +10,8 @@ LEAP_FLAGS = ['\\Seen',
'List']
-def leap_mail(uid=0, extra_flags=[], headers={'date': str(datetime.now())}):
- flags = LEAP_FLAGS + extra_flags
+def leap_mail(uid=0, leap_flags=LEAP_FLAGS, extra_flags=[], headers={'date': str(datetime.now())}):
+ flags = leap_flags + extra_flags
return Mock(getUID=Mock(return_value=uid),
getFlags=Mock(return_value=flags),
bdoc=Mock(content={'raw': 'test'}),