summaryrefslogtreecommitdiff
path: root/service/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'service/test/unit')
-rw-r--r--service/test/unit/adapter/mailstore/test_leap_mail.py102
-rw-r--r--service/test/unit/adapter/services/test_mail_sender.py6
-rw-r--r--service/test/unit/adapter/test_draft_service.py2
-rw-r--r--service/test/unit/adapter/test_mail.py16
-rw-r--r--service/test/unit/adapter/test_mail_service.py8
-rw-r--r--service/test/unit/support/test_replier.py42
6 files changed, 57 insertions, 119 deletions
diff --git a/service/test/unit/adapter/mailstore/test_leap_mail.py b/service/test/unit/adapter/mailstore/test_leap_mail.py
index 91e960e1..cd8852ad 100644
--- a/service/test/unit/adapter/mailstore/test_leap_mail.py
+++ b/service/test/unit/adapter/mailstore/test_leap_mail.py
@@ -68,11 +68,6 @@ class TestLeapMail(TestCase):
'imprints': [{'state': 'no_signature_information'}],
'locks': []
},
- 'replying': {'all': {'cc-field': [],
- 'to-field': ['receiver@example.test',
- 'test@example.test',
- 'receiver2@other.test']},
- 'single': 'test@example.test'},
'attachments': []
}
@@ -105,103 +100,6 @@ class TestLeapMail(TestCase):
self.assertEqual([expected_address], mail.as_dict()['header']['cc'])
self.assertEqual(expected_subject, mail.as_dict()['header']['subject'])
- def test_as_dict_replying_with_special_chars(self):
- expected_address = u'"\xc4lbert \xdcbr\xf6" <\xe4\xfc\xf6@example.mail>'
- mail = LeapMail('', 'INBOX',
- {'From': '=?iso-8859-1?q?=22=C4lbert_=DCbr=F6=22_=3C=E4=FC=F6=40example=2Email=3E?=',
- 'To': '=?iso-8859-1?q?=22=C4lbert_=DCbr=F6=22_=3C=E4=FC=F6=40example=2Email=3E?=',
- 'Cc': '=?iso-8859-1?q?=22=C4lbert_=DCbr=F6=22_=3C=E4=FC=F6=40example=2Email=3E?=',
- 'Subject': '=?iso-8859-1?q?H=E4ll=F6_W=F6rld?='})
- self.assertEqual([expected_address], mail.as_dict()['replying']['all']['to-field'])
- self.assertEqual([expected_address], mail.as_dict()['replying']['all']['cc-field'])
- self.assertEqual(expected_address, mail.as_dict()['replying']['single'])
-
- def test_reply_all_result_does_not_contain_own_address_in_to_with_spaces(self):
- my_address = 'myaddress@example.test'
-
- with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address):
- mail = LeapMail('', 'INBOX',
- {'From': 'test@example.test',
- 'To': 'receiver@example.test, %s ' % my_address})
- expected_recipients = ['receiver@example.test', 'test@example.test']
- actual_recipients = mail.as_dict()['replying']['all']['to-field']
- expected_recipients.sort()
- actual_recipients.sort()
-
- self.assertEqual(expected_recipients, actual_recipients)
-
- def test_reply_all_result_does_not_contain_own_address_in_to_with_name(self):
- my_address = 'myaddress@example.test'
-
- with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address):
- mail = LeapMail('', 'INBOX',
- {'From': 'test@example.test',
- 'To': 'receiver@example.test, Folker Bernitt <%s>' % my_address})
-
- expected_recipients = ['receiver@example.test', 'test@example.test']
- actual_recipients = mail.as_dict()['replying']['all']['to-field']
- expected_recipients.sort()
- actual_recipients.sort()
-
- self.assertEqual(expected_recipients, actual_recipients)
-
- # TODO: fix this test
- def test_reply_all_does_not_contain_own_address_in_to_field_with_different_encodings(self):
- my_address = 'myaddress@example.test'
-
- with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address):
- mail = LeapMail('', 'INBOX',
- {'From': 'test@example.test',
- 'To': 'receiver@example.test, =?iso-8859-1?q?=C4lbert_=3Cmyaddress=40example=2Etest=3E?='})
-
- expected_recipients = [u'receiver@example.test', u'test@example.test']
- actual_recipients = mail.as_dict()['replying']['all']['to-field']
- expected_recipients.sort()
- actual_recipients.sort()
-
- self.assertEqual(expected_recipients, actual_recipients)
-
- def test_reply_all_result_does_not_contain_own_address_in_cc(self):
- my_address = 'myaddress@example.test'
-
- with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address):
- mail = LeapMail('', 'INBOX',
- {'From': 'test@example.test',
- 'To': 'receiver@example.test',
- 'Cc': my_address})
-
- self.assertEqual([my_address], mail.as_dict()['replying']['all']['cc-field'])
-
- def test_reply_all_result_does_not_contain_own_address_if_sender(self):
- my_address = 'myaddress@example.test'
-
- with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address):
- mail = LeapMail('', 'INBOX',
- {'From': 'myaddress@example.test',
- 'To': 'receiver@example.test'})
-
- self.assertEqual(['receiver@example.test'], mail.as_dict()['replying']['all']['to-field'])
-
- def test_reply_all_result_does_contain_own_address_if_only_recipient(self):
- my_address = 'myaddress@example.test'
-
- with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address):
- mail = LeapMail('', 'INBOX',
- {'From': 'myaddress@example.test',
- 'To': 'myaddress@example.test'})
-
- self.assertEqual(['myaddress@example.test'], mail.as_dict()['replying']['all']['to-field'])
-
- def test_reply_result_swaps_sender_and_recipient_if_i_am_the_sender(self):
- my_address = 'myaddress@example.test'
-
- with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address):
- mail = LeapMail('', 'INBOX',
- {'From': 'myaddress@example.test',
- 'To': 'recipient@example.test'})
-
- self.assertEqual('myaddress@example.test', mail.as_dict()['replying']['single'])
-
def test_as_dict_with_mixed_encodings(self):
subject = 'Another test with =?iso-8859-1?B?3G1s5Px0?= =?iso-8859-1?Q?s?='
mail = LeapMail('', 'INBOX',
diff --git a/service/test/unit/adapter/services/test_mail_sender.py b/service/test/unit/adapter/services/test_mail_sender.py
index cd4a84c3..9a7e8fea 100644
--- a/service/test/unit/adapter/services/test_mail_sender.py
+++ b/service/test/unit/adapter/services/test_mail_sender.py
@@ -67,7 +67,7 @@ class MailSenderTest(unittest.TestCase):
@defer.inlineCallbacks
def test_iterates_over_recipients(self):
- input_mail = InputMail.from_dict(mail_dict())
+ input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org')
when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))
@@ -78,7 +78,7 @@ class MailSenderTest(unittest.TestCase):
@defer.inlineCallbacks
def test_problem_with_email_raises_exception(self):
- input_mail = InputMail.from_dict(mail_dict())
+ input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org')
when(OutgoingMail).send_message(any(), any()).thenReturn(defer.fail(Exception('pretend something went wrong')))
@@ -91,7 +91,7 @@ class MailSenderTest(unittest.TestCase):
@defer.inlineCallbacks
def test_iterates_over_recipients_and_send_whitout_bcc_field(self):
- input_mail = InputMail.from_dict(mail_dict())
+ input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org')
bccs = input_mail.bcc
when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))
diff --git a/service/test/unit/adapter/test_draft_service.py b/service/test/unit/adapter/test_draft_service.py
index bf5e18c5..c2516013 100644
--- a/service/test/unit/adapter/test_draft_service.py
+++ b/service/test/unit/adapter/test_draft_service.py
@@ -22,7 +22,7 @@ class DraftServiceTest(unittest.TestCase):
verify(self.mail_store).add_mail('DRAFTS', mail.raw)
def test_update_draft(self):
- mail = InputMail.from_dict(test_helper.mail_dict())
+ mail = InputMail.from_dict(test_helper.mail_dict(), from_address='pixelated@org')
when(self.mail_store).delete_mail(mail.ident).thenReturn(defer.succeed(True))
when(self.mail_store).add_mail('DRAFTS', mail.raw).thenReturn(defer.succeed(LeapMail('id', 'DRAFTS')))
diff --git a/service/test/unit/adapter/test_mail.py b/service/test/unit/adapter/test_mail.py
index 6e4943fa..d66eddd9 100644
--- a/service/test/unit/adapter/test_mail.py
+++ b/service/test/unit/adapter/test_mail.py
@@ -81,7 +81,7 @@ class InputMailTest(unittest.TestCase):
mail_dict['header']['cc'] = ''
mail_dict['header']['subject'] = ''
- mime_multipart = InputMail.from_dict(mail_dict).to_mime_multipart()
+ mime_multipart = InputMail.from_dict(mail_dict, from_address='pixelated@org').to_mime_multipart()
self.assertNotRegexpMatches(mime_multipart.as_string(), "\nTo: \n")
self.assertNotRegexpMatches(mime_multipart.as_string(), "\nBcc: \n")
@@ -99,14 +99,14 @@ class InputMailTest(unittest.TestCase):
}
}
- result = InputMail.from_dict(mail_single_recipient).raw
+ result = InputMail.from_dict(mail_single_recipient, from_address='pixelated@org').raw
self.assertRegexpMatches(result, 'To: to@pixelated.org')
def test_to_mime_multipart(self):
pixelated.support.date.mail_date_now = lambda: 'date now'
- mime_multipart = InputMail.from_dict(simple_mail_dict()).to_mime_multipart()
+ mime_multipart = InputMail.from_dict(simple_mail_dict(), from_address='pixelated@org').to_mime_multipart()
self.assertRegexpMatches(mime_multipart.as_string(), "\nTo: to@pixelated.org, anotherto@pixelated.org\n")
self.assertRegexpMatches(mime_multipart.as_string(), "\nCc: cc@pixelated.org, anothercc@pixelated.org\n")
@@ -120,20 +120,18 @@ class InputMailTest(unittest.TestCase):
mail_dict['header']['to'] = u'"Älbert Übrö \xF0\x9F\x92\xA9" <äüö@example.mail>'
pixelated.support.date.mail_date_now = lambda: 'date now'
- mime_multipart = InputMail.from_dict(mail_dict).to_mime_multipart()
+ mime_multipart = InputMail.from_dict(mail_dict, from_address='pixelated@org').to_mime_multipart()
expected_part_of_encoded_to = 'Iiwgw4QsIGwsIGIsIGUsIHIsIHQsICAsIMOcLCBiLCByLCDDtiwgICwgw7As'
self.assertRegexpMatches(mime_multipart.as_string(), expected_part_of_encoded_to)
def test_smtp_format(self):
- InputMail.FROM_EMAIL_ADDRESS = 'pixelated@org'
-
- smtp_format = InputMail.from_dict(simple_mail_dict()).to_smtp_format()
+ smtp_format = InputMail.from_dict(simple_mail_dict(), from_address='pixelated@org').to_smtp_format()
self.assertRegexpMatches(smtp_format, "\nFrom: pixelated@org")
def test_to_mime_multipart_handles_alternative_bodies(self):
- mime_multipart = InputMail.from_dict(multipart_mail_dict()).to_mime_multipart()
+ mime_multipart = InputMail.from_dict(multipart_mail_dict(), from_address='pixelated@org').to_mime_multipart()
part_one = 'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\nHello world!'
part_two = 'Content-Type: text/html; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\n<p>Hello html world!</p>'
@@ -142,7 +140,7 @@ class InputMailTest(unittest.TestCase):
self.assertRegexpMatches(mime_multipart.as_string(), part_two)
def test_raw_with_attachment_data(self):
- input_mail = InputMail.from_dict(with_attachment_mail_dict())
+ input_mail = InputMail.from_dict(with_attachment_mail_dict(), from_address='pixelated@org')
attachment = MIMENonMultipart('text', 'plain', Content_Disposition='attachment; filename=ayoyo.txt')
attachment.set_payload('Hello World')
diff --git a/service/test/unit/adapter/test_mail_service.py b/service/test/unit/adapter/test_mail_service.py
index 27c80fde..a8b6d597 100644
--- a/service/test/unit/adapter/test_mail_service.py
+++ b/service/test/unit/adapter/test_mail_service.py
@@ -45,7 +45,7 @@ class TestMailService(unittest.TestCase):
def test_send_mail(self):
input_mail = InputMail()
- when(InputMail).from_dict(ANY()).thenReturn(input_mail)
+ when(InputMail).from_dict(ANY(), ANY()).thenReturn(input_mail)
when(self.mail_sender).sendmail(ANY()).thenReturn(defer.Deferred())
sent_deferred = self.mail_service.send_mail(mail_dict())
@@ -60,7 +60,7 @@ class TestMailService(unittest.TestCase):
def test_send_mail_removes_draft(self):
mail = LeapMail('id', 'INBOX')
when(mail).raw = 'raw mail'
- when(InputMail).from_dict(ANY()).thenReturn(mail)
+ when(InputMail).from_dict(ANY(), ANY()).thenReturn(mail)
when(self.mail_store).delete_mail('12').thenReturn(defer.succeed(None))
when(self.mail_store).add_mail('SENT', ANY()).thenReturn(mail)
@@ -77,7 +77,7 @@ class TestMailService(unittest.TestCase):
def test_send_mail_marks_as_read(self):
mail = InputMail()
when(mail).raw = 'raw mail'
- when(InputMail).from_dict(ANY()).thenReturn(mail)
+ when(InputMail).from_dict(ANY(), ANY()).thenReturn(mail)
when(self.mail_store).delete_mail('12').thenReturn(defer.succeed(None))
when(self.mail_sender).sendmail(mail).thenReturn(defer.succeed(None))
@@ -93,7 +93,7 @@ class TestMailService(unittest.TestCase):
@defer.inlineCallbacks
def test_send_mail_does_not_delete_draft_on_error(self):
input_mail = InputMail()
- when(InputMail).from_dict(ANY()).thenReturn(input_mail)
+ when(InputMail).from_dict(ANY(), ANY()).thenReturn(input_mail)
deferred_failure = defer.fail(Exception("Assume sending mail failed"))
when(self.mail_sender).sendmail(ANY()).thenReturn(deferred_failure)
diff --git a/service/test/unit/support/test_replier.py b/service/test/unit/support/test_replier.py
new file mode 100644
index 00000000..5e1c234a
--- /dev/null
+++ b/service/test/unit/support/test_replier.py
@@ -0,0 +1,42 @@
+import unittest
+from pixelated.support import replier
+
+
+class TestReplier(unittest.TestCase):
+ def test_reply_all_dont_exclude_own_address_if_only_recipient(self):
+ current_user = sender = 'me@pixelated.org'
+ to = [sender]
+ cc = []
+
+ reply_dict = replier.generate_recipients(sender, to, cc, current_user)
+ expected = {'single': sender, 'all': {'to-field': [current_user], 'cc-field': []}}
+ self.assertEquals(expected, reply_dict)
+
+ def test_reply_all_does_not_contain_own_address_in_to(self):
+ current_user = 'me@pixelated.org'
+ sender = 'sender@pixelated.org'
+ to = ['test@pixelated.org', current_user]
+ cc = []
+
+ reply_dict = replier.generate_recipients(sender, to, cc, current_user)
+ expected = {'single': sender, 'all': {'to-field': ['test@pixelated.org', sender], 'cc-field': []}}
+ self.assertEquals(expected, reply_dict)
+
+ def test_reply_all_does_not_contain_own_address_in_cc(self):
+ current_user = 'me@pixelated.org'
+ sender = 'sender@pixelated.org'
+ to = ['test@pixelated.org']
+ cc = ['test2@pixelated.org', current_user]
+
+ reply_dict = replier.generate_recipients(sender, to, cc, current_user)
+ expected = {'single': sender, 'all': {'to-field': ['test@pixelated.org', sender], 'cc-field': ['test2@pixelated.org']}}
+ self.assertEquals(expected, reply_dict)
+
+ def test_reply_single_swaps_current_user_and_recipient_if_a_am_the_sender(self):
+ current_user = sender = 'me@pixelated.org'
+ to = ['test@pixelated.org']
+ cc = []
+
+ reply_dict = replier.generate_recipients(sender, to, cc, current_user)
+ expected = {'single': 'test@pixelated.org', 'all': {'to-field': ['test@pixelated.org'], 'cc-field': []}}
+ self.assertEquals(expected, reply_dict)