summaryrefslogtreecommitdiff
path: root/service/test/adapter/mail_service_test.py
blob: 7b70ac9bd12becb7331238363b6f66e0d739a439 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import unittest

from app.adapter.mail_service import MailService
from mock import Mock, MagicMock, patch
import test_helper
from app.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"
        }

    def test_custom_tags_get_created_if_not_exists(self):
        MailService._open_leap_session = lambda self: None
        MailService.mailbox = Mock(messages=[test_helper.leap_mail(uid=6)])
        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

        self.assertIn(Tag('test'), mailservice.all_tags())