summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/model/mail.py40
-rw-r--r--service/test/support/test_helper.py8
-rw-r--r--service/test/unit/adapter/test_mail.py4
-rw-r--r--service/test/unit/bitmask_libraries/test_nicknym.py2
-rw-r--r--service/test/unit/maintenance/test_commands.py3
-rw-r--r--service/test/unit/resources/test_keys_resources.py27
6 files changed, 57 insertions, 27 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index fd08af07..1cbb1ff8 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -33,6 +33,17 @@ from pixelated.support.functional import compact
logger = logging.getLogger(__name__)
+TYPE_KEY = 'type'
+CONTENT_HASH_KEY = 'chash'
+HEADERS_KEY = 'headers'
+DATE_KEY = 'date'
+SUBJECT_KEY = 'subject'
+PARTS_MAP_KEY = 'part_map'
+BODY_KEY = 'body'
+MSGID_KEY = 'msgid'
+MULTIPART_KEY = 'multi'
+SIZE_KEY = 'size'
+
class Mail(object):
@property
@@ -61,7 +72,8 @@ class Mail(object):
@property
def mailbox_name(self):
- return self.fdoc.content.get('mbox')
+ # FIXME mbox is no longer available, instead we now have mbox_uuid
+ return self.fdoc.content.get('mbox_uuid')
@property
def _mime_multipart(self):
@@ -131,16 +143,16 @@ class InputMail(Mail):
fd[fields.MBOX] = mailbox
fd[fields.MBOX_UUID] = next_uid
fd[fields.CONTENT_HASH] = self._get_chash()
- # fd[fields.SIZE_KEY] = len(self.raw)
- # fd[fields.MULTIPART_KEY] = True
+ fd[SIZE_KEY] = len(self.raw)
+ fd[MULTIPART_KEY] = True
fd[fields.RECENT] = True
- fd[fields.TYPE] = fields.TYPE_FLAGS_VAL
+ fd[fields.TYPE] = fields.FLAGS
fd[fields.FLAGS] = Status.to_flags(self._status)
self._fd = fd
return fd
def _get_body_phash(self):
- return walk.get_body_phash_multi(walk.get_payloads(self._mime_multipart))
+ return walk.get_body_phash(self._mime_multipart)
def _hdoc(self):
if self._hd:
@@ -151,15 +163,15 @@ class InputMail(Mail):
headers['From'] = InputMail.FROM_EMAIL_ADDRESS
hd = {}
- hd[fields.HEADERS_KEY] = headers
- hd[fields.DATE_KEY] = headers['Date']
- hd[fields.CONTENT_HASH_KEY] = self._get_chash()
- hd[fields.MSGID_KEY] = ''
- hd[fields.MULTIPART_KEY] = True
- hd[fields.SUBJECT_KEY] = headers.get('Subject')
- hd[fields.TYPE_KEY] = fields.TYPE_HEADERS_VAL
- hd[fields.BODY_KEY] = self._get_body_phash()
- hd[fields.PARTS_MAP_KEY] = \
+ hd[HEADERS_KEY] = headers
+ hd[DATE_KEY] = headers['Date']
+ hd[CONTENT_HASH_KEY] = self._get_chash()
+ hd[MSGID_KEY] = ''
+ hd[MULTIPART_KEY] = True
+ hd[SUBJECT_KEY] = headers.get('Subject')
+ hd[TYPE_KEY] = fields.HEADERS
+ hd[BODY_KEY] = self._get_body_phash()
+ hd[PARTS_MAP_KEY] = \
walk.walk_msg_tree(walk.get_parts(self._mime_multipart), body_phash=self._get_body_phash())['part_map']
self._hd = hd
diff --git a/service/test/support/test_helper.py b/service/test/support/test_helper.py
index c37c1408..8f2a5308 100644
--- a/service/test/support/test_helper.py
+++ b/service/test/support/test_helper.py
@@ -53,9 +53,9 @@ class TestDoc(object):
return self.content[key]
-def leap_mail(uid=0, flags=LEAP_FLAGS, headers=None, extra_headers={}, mbox='INBOX', body='body',
+def leap_mail(uid=0, flags=LEAP_FLAGS, headers=None, extra_headers={}, mbox_uuid='INBOX', body='body',
chash='chash'):
- fdoc = TestDoc({'flags': flags, 'mbox': mbox, 'type': 'flags', 'uid': uid, 'chash': chash})
+ fdoc = TestDoc({'flags': flags, 'mbox_uuid': mbox_uuid, 'type': 'flags', 'uid': uid, 'chash': chash})
if headers is None:
headers = {}
@@ -69,8 +69,8 @@ def leap_mail(uid=0, flags=LEAP_FLAGS, headers=None, extra_headers={}, mbox='INB
return (fdoc, hdoc, bdoc)
-def pixelated_mail(uid=0, flags=LEAP_FLAGS, headers=None, extra_headers={}, mbox='INBOX', body='body', chash='chash'):
- fdoc, hdoc, bdoc = leap_mail(uid, flags, headers, extra_headers, mbox, body, chash)
+def pixelated_mail(uid=0, flags=LEAP_FLAGS, headers=None, extra_headers={}, mbox_uuid='INBOX', body='body', chash='chash'):
+ fdoc, hdoc, bdoc = leap_mail(uid, flags, headers, extra_headers, mbox_uuid, body, chash)
return PixelatedMail.from_soledad(fdoc, hdoc, bdoc)
diff --git a/service/test/unit/adapter/test_mail.py b/service/test/unit/adapter/test_mail.py
index 92b1e905..f73ef333 100644
--- a/service/test/unit/adapter/test_mail.py
+++ b/service/test/unit/adapter/test_mail.py
@@ -17,7 +17,7 @@
import unittest
import pixelated.support.date
-from pixelated.adapter.model.mail import PixelatedMail, InputMail
+from pixelated.adapter.model.mail import PixelatedMail, InputMail, HEADERS_KEY
from mockito import mock, unstub, when
from test.support import test_helper
import dateutil.parser as dateparser
@@ -119,7 +119,7 @@ class TestPixelatedMail(unittest.TestCase):
input_mail = InputMail()
input_mail.headers = headers
- self.assertEqual('me@pixelated.org', input_mail.get_for_save(1, 'SENT')[1][fields.HEADERS_KEY]['From'])
+ self.assertEqual('me@pixelated.org', input_mail.get_for_save(1, 'SENT')[1][HEADERS_KEY]['From'])
def test_as_dict(self):
headers = {'Subject': 'The subject',
diff --git a/service/test/unit/bitmask_libraries/test_nicknym.py b/service/test/unit/bitmask_libraries/test_nicknym.py
index ca3b348d..85fd171d 100644
--- a/service/test/unit/bitmask_libraries/test_nicknym.py
+++ b/service/test/unit/bitmask_libraries/test_nicknym.py
@@ -61,5 +61,5 @@ class NickNymTest(AbstractLeapTest):
# when/then
nicknym.generate_openpgp_key()
- keyman.get_key.assert_called_with('test_user@some-server.test', openpgp.OpenPGPKey, fetch_remote=False, private=True)
+ keyman.get_key.assert_called_with('test_user@some-server.test', openpgp.OpenPGPKey)
keyman.gen_key.assert_called_with(openpgp.OpenPGPKey)
diff --git a/service/test/unit/maintenance/test_commands.py b/service/test/unit/maintenance/test_commands.py
index 7279f7a6..4eb2e990 100644
--- a/service/test/unit/maintenance/test_commands.py
+++ b/service/test/unit/maintenance/test_commands.py
@@ -19,6 +19,7 @@ import email
from pixelated.maintenance import delete_all_mails, load_mails
from pixelated.bitmask_libraries.session import LeapSession
from leap.mail.constants import MessageFlags
+from leap.mail.imap.account import IMAPAccount
from leap.soledad.client import Soledad
from leap.soledad.common.document import SoledadDocument
from mock import MagicMock
@@ -31,7 +32,9 @@ class TestCommands(unittest.TestCase):
def setUp(self):
self.leap_session = MagicMock(spec=LeapSession)
self.soledad = MagicMock(spec=Soledad)
+ self.account = MagicMock(spec=IMAPAccount)
self.mailbox = MagicMock()
+ self.leap_session.account = self.account
self.args = (self.leap_session, self.soledad)
diff --git a/service/test/unit/resources/test_keys_resources.py b/service/test/unit/resources/test_keys_resources.py
index be79424b..71a6415a 100644
--- a/service/test/unit/resources/test_keys_resources.py
+++ b/service/test/unit/resources/test_keys_resources.py
@@ -1,3 +1,5 @@
+import json
+import ast
from mockito import mock, when
from leap.keymanager import OpenPGPKey, KeyNotFound
from pixelated.resources.keys_resource import KeysResource
@@ -32,13 +34,26 @@ class TestKeysResource(unittest.TestCase):
d = self.web.get(request)
+ expected = {
+ "tags": ["keymanager-key"],
+ "fingerprint": '',
+ "private": False,
+ 'sign_used': False,
+ 'refreshed_at': 0,
+ "expiry_date": 0,
+ "address": 'some@key',
+ 'encr_used': False,
+ 'last_audited_at': 0,
+ 'key_data': '',
+ 'length': 0,
+ 'key_id': '',
+ 'validation': 'Weak_Chain',
+ 'type': 'OpenPGPKey',
+ }
+
def assert_response(_):
- self.assertEquals('"{\\"tags\\": [\\"keymanager-key\\"], \\"fingerprint\\": null, '
- '\\"private\\": null, \\"expiry_date\\": null, \\"address\\": '
- '\\"some@key\\", \\"last_audited_at\\": null, \\"key_data\\": null, '
- '\\"length\\": null, \\"key_id\\": null, \\"validation\\": null, '
- '\\"type\\": \\"<class \'leap.keymanager.openpgp.OpenPGPKey\'>\\", '
- '\\"first_seen_at\\": null}"', request.written[0])
+ actual = json.loads(ast.literal_eval(request.written[0]))
+ self.assertEquals(expected, actual)
d.addCallback(assert_response)
return d