summaryrefslogtreecommitdiff
path: root/service/test/support/integration/soledad_test_base.py
blob: 6368d3e8037e9be128996ffbe97d9cd08f44a2e8 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#
# Copyright (c) 2014 ThoughtWorks, Inc.
#
# Pixelated is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pixelated is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import unittest

from pixelated.controllers import *
from test.support.integration.app_test_client import AppTestClient
from test.support.integration.model import ResponseMail


class SoledadTestBase(unittest.TestCase):
    # these are so long because our CI is so slow at the moment.
    DEFERRED_TIMEOUT = 120
    DEFERRED_TIMEOUT_LONG = 300

    @classmethod
    def setUpClass(cls):
        from nose.twistedtools import threaded_reactor

        threaded_reactor()

    def setUp(self):
        self.client = AppTestClient()

    def get_mails_by_tag(self, tag, page=1, window=100):
        tags = 'tag:%s' % tag
        return self.search(tags, page, window)

    def search(self, query, page=1, window=100):
        res, req = self.client.get("/mails", {
            'q': [query],
            'w': [str(window)],
            'p': [str(page)]
        })
        return [ResponseMail(m) for m in res['mails']]

    def post_mail(self, data):
        res, req = self.client.post('/mails', data)
        return ResponseMail(res)

    def get_attachment(self, ident, encoding):
        res, req = self.client.get("/attachment/%s" % ident, {'encoding': [encoding]}, as_json=False)
        return res

    def put_mail(self, data):
        res, req = self.client.put('/mails', data)
        return res['ident']

    def post_tags(self, mail_ident, tags_json):
        res, req = self.client.post("/mail/%s/tags" % mail_ident, tags_json)
        return res

    def get_tags(self, **kwargs):
        res, req = self.client.get('/tags', kwargs)
        return res

    def delete_mail(self, mail_ident):
        res, req = self.client.delete("/mail/%s" % mail_ident)
        return req

    def delete_mails(self, idents):
        res, req = self.client.post("/mails/delete", json.dumps({'idents': idents}))
        return req

    def mark_many_as_unread(self, idents):
        res, req = self.client.post('/mails/unread', json.dumps({'idents': idents}))
        return req

    def mark_many_as_read(self, idents):
        res, req = self.client.post('/mails/read', json.dumps({'idents': idents}))
        return req

    def get_contacts(self, query):
        res, req = self.client.get('/contacts', get_args={'q': query})
        return res