summaryrefslogtreecommitdiff
path: root/service/test/support/integration
diff options
context:
space:
mode:
Diffstat (limited to 'service/test/support/integration')
-rw-r--r--service/test/support/integration/app_test_client.py58
-rw-r--r--service/test/support/integration/soledad_test_base.py60
2 files changed, 60 insertions, 58 deletions
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index 3ba6646e..baa95132 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -39,15 +39,19 @@ from pixelated.config import App
from pixelated.resources.root_resource import RootResource
from test.support.integration.model import MailBuilder
from test.support.test_helper import request_mock
+from test.support.integration.model import ResponseMail
-class AppTestClient:
+class AppTestClient(object):
INDEX_KEY = '\xde3?\x87\xff\xd9\xd3\x14\xf0\xa7>\x1f%C{\x16.\\\xae\x8c\x13\xa7\xfb\x04\xd4]+\x8d_\xed\xd1\x8d\x0bI' \
'\x8a\x0e\xa4tm\xab\xbf\xb4\xa5\x99\x00d\xd5w\x9f\x18\xbc\x1d\xd4_W\xd2\xb6\xe8H\x83\x1b\xd8\x9d\xad'
ACCOUNT = 'test'
MAIL_ADDRESS = 'test@pixelated.org'
def __init__(self):
+ self.start_client()
+
+ def start_client(self):
soledad_test_folder = self._generate_soledad_test_folder_name()
SearchEngine.DEFAULT_INDEX_HOME = soledad_test_folder
@@ -154,6 +158,58 @@ class AppTestClient:
def _generate_soledad_test_folder_name(self, soledad_test_folder='/tmp/soledad-test/test'):
return os.path.join(soledad_test_folder, str(uuid.uuid4()))
+ 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.get("/mails", {
+ 'q': [query],
+ 'w': [str(window)],
+ 'p': [str(page)]
+ })
+ return [ResponseMail(m) for m in res['mails']]
+
+ def get_attachment(self, ident, encoding):
+ res, req = self.get("/attachment/%s" % ident, {'encoding': [encoding]}, as_json=False)
+ return res
+
+ def put_mail(self, data):
+ res, req = self.put('/mails', data)
+ return res, req
+
+ def post_tags(self, mail_ident, tags_json):
+ res, req = self.post("/mail/%s/tags" % mail_ident, tags_json)
+ return res
+
+ def get_tags(self, **kwargs):
+ res, req = self.get('/tags', kwargs)
+ return res
+
+ def get_mail(self, mail_ident):
+ res, req = self.get('/mail/%s' % mail_ident)
+ return res
+
+ def delete_mail(self, mail_ident):
+ res, req = self.delete("/mail/%s" % mail_ident)
+ return req
+
+ def delete_mails(self, idents):
+ res, req = self.post("/mails/delete", json.dumps({'idents': idents}))
+ return req
+
+ def mark_many_as_unread(self, idents):
+ res, req = self.post('/mails/unread', json.dumps({'idents': idents}))
+ return req
+
+ def mark_many_as_read(self, idents):
+ res, req = self.post('/mails/read', json.dumps({'idents': idents}))
+ return req
+
+ def get_contacts(self, query):
+ res, req = self.get('/contacts', get_args={'q': query})
+ return res
+
def initialize_soledad(tempdir):
if os.path.isdir(tempdir):
diff --git a/service/test/support/integration/soledad_test_base.py b/service/test/support/integration/soledad_test_base.py
index 2c8bb023..c49de00a 100644
--- a/service/test/support/integration/soledad_test_base.py
+++ b/service/test/support/integration/soledad_test_base.py
@@ -14,70 +14,16 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
from twisted.trial import unittest
-from pixelated.resources import *
from test.support.integration.app_test_client import AppTestClient
-from test.support.integration.model import ResponseMail
-class SoledadTestBase(unittest.TestCase):
+class SoledadTestBase(unittest.TestCase, AppTestClient):
# these are so long because our CI is so slow at the moment.
DEFERRED_TIMEOUT = 120
DEFERRED_TIMEOUT_LONG = 300
def setUp(self):
- self.client = AppTestClient()
+ self.start_client()
def tearDown(self):
- self.client.cleanup()
-
- 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 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, req
-
- 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 get_mail(self, mail_ident):
- res, req = self.client.get('/mail/%s' % mail_ident)
- 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
+ self.cleanup()