From 2ecb96524c6b350c8f8287e8302d886c939d5fae Mon Sep 17 00:00:00 2001 From: Bruno Wagner Goncalves Date: Fri, 26 Sep 2014 14:45:30 -0300 Subject: All tests passing using soledad --- service/pixelated/adapter/pixelated_mail.py | 2 +- service/pixelated/adapter/pixelated_mailboxes.py | 2 +- service/test/adapter/pixelated_mail_test.py | 6 +++--- service/test/adapter/pixelated_mailboxes_test.py | 3 ++- service/test/adapter/test_helper.py | 24 ++++++++++-------------- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py index b603ba70..ee2666c3 100644 --- a/service/pixelated/adapter/pixelated_mail.py +++ b/service/pixelated/adapter/pixelated_mail.py @@ -184,7 +184,7 @@ class PixelatedMail: @property def tags(self): - _tags = self.hdoc.content.get('X-Tags', '[]') + _tags = self.hdoc.content['headers'].get('X-Tags', '[]') return set(_tags) if type(_tags) is list or type(_tags) is set else set(json.loads(_tags)) @property diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py index f3efe544..1f9662fb 100644 --- a/service/pixelated/adapter/pixelated_mailboxes.py +++ b/service/pixelated/adapter/pixelated_mailboxes.py @@ -46,7 +46,7 @@ class PixelatedMailBoxes(): return mails def add_draft(self, mail): - self.drafts().add(mail, use_smtp_format=True) + self.drafts().add(mail) return mail def update_draft(self, ident, new_version): diff --git a/service/test/adapter/pixelated_mail_test.py b/service/test/adapter/pixelated_mail_test.py index c8c23b8a..4e579cb7 100644 --- a/service/test/adapter/pixelated_mail_test.py +++ b/service/test/adapter/pixelated_mail_test.py @@ -73,12 +73,12 @@ class TestPixelatedMail(unittest.TestCase): def test_update_tags_notifies_tag_service(self): db_path = '/tmp/test_update_tags_notifies_tag_service' - tag_service = TagService(TagIndex(db_path)) + TagService.instance = TagService(TagIndex(db_path)) mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier) mail.update_tags({'new_tag'}) - self.assertIn(Tag('new_tag'), tag_service.all_tags()) + self.assertIn(Tag('new_tag'), mail.tag_service.all_tags()) os.remove(db_path + '.db') @@ -131,4 +131,4 @@ class InputMailTest(unittest.TestCase): smtp_format = InputMail.from_dict(self.mail_dict()).to_smtp_format() - self.assertRegexpMatches(smtp_format, "\nFrom: pixelated@org") \ No newline at end of file + self.assertRegexpMatches(smtp_format, "\nFrom: pixelated@org") diff --git a/service/test/adapter/pixelated_mailboxes_test.py b/service/test/adapter/pixelated_mailboxes_test.py index e8f76e0f..b13c7c33 100644 --- a/service/test/adapter/pixelated_mailboxes_test.py +++ b/service/test/adapter/pixelated_mailboxes_test.py @@ -23,6 +23,7 @@ global querier pixelated.adapter.soledad_querier.get_soledad_querier_instance = lambda x, y: querier from pixelated.adapter.pixelated_mail import PixelatedMail +from pixelated.adapter.pixelated_mail import InputMail from pixelated.adapter.pixelated_mailbox import PixelatedMailbox from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes @@ -50,7 +51,7 @@ class PixelatedMailboxesTest(unittest.TestCase): self.assertEqual("mail", mails[0]) def test_add_draft(self): - mail = PixelatedMail() + mail = InputMail() when(self.drafts_mailbox).add(mail).thenReturn(1) self.mailboxes.add_draft(mail) diff --git a/service/test/adapter/test_helper.py b/service/test/adapter/test_helper.py index c8593fc1..86552008 100644 --- a/service/test/adapter/test_helper.py +++ b/service/test/adapter/test_helper.py @@ -27,7 +27,6 @@ LEAP_FLAGS = ['\\Seen', DEFAULT_HEADERS = {'date': str(datetime.now())} - def mail_dict(): return { 'header': { @@ -41,30 +40,27 @@ def mail_dict(): 'tags': [] } +class TestDoc: + def __init__(self, content): + self.content = content -def doc(content): - class TestDoc: - def __init__(self, content): - self.content = content - - return TestDoc(content) - - -def leap_mail(uid=0, flags=LEAP_FLAGS, headers=DEFAULT_HEADERS, extra_headers={}, mbox='INBOX', body='body', +def leap_mail(uid=0, flags=LEAP_FLAGS, headers=None, extra_headers={}, mbox='INBOX', body='body', chash='chash'): - fdoc = doc({'flags': flags, 'mbox': mbox, 'type': 'flags', 'uid': uid, 'chash': chash}) + fdoc = TestDoc({'flags': flags, 'mbox': mbox, 'type': 'flags', 'uid': uid, 'chash': chash}) + if headers is None: headers = {} + if not (headers.get('received') or headers.get('date')): headers.update(DEFAULT_HEADERS) headers['headers'] = extra_headers - hdoc = doc(headers) + hdoc = TestDoc(headers) - bdoc = doc({'raw': body, 'type': 'cnt'}) + bdoc = TestDoc({'raw': body, 'type': 'cnt'}) return (fdoc, hdoc, bdoc) def input_mail(): mail = InputMail() - mail.fdoc = doc({}) + mail.fdoc = TestDoc({}) mail._chash = "123" mail.as_dict = lambda: None return mail -- cgit v1.2.3