summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
authormfrankie <mfrankie@eumfranckie.local>2016-05-17 16:56:55 +0200
committermfrankie <mfrankie@eumfranckie.local>2016-05-19 13:30:18 +0200
commit3fd43a0a3f45bfbb0ab6bde36ba7b353dbf535ef (patch)
tree1b6bd18bcbde7a6bca00f362c0502f7ce2d901d0 /service/test
parent053d51e8c6484f95b43c7b45e5b42fcb3e89784c (diff)
remove duplicated mails, wip
Diffstat (limited to 'service/test')
-rw-r--r--service/test/support/test_helper.py14
-rw-r--r--service/test/unit/adapter/services/test_mail_sender.py26
2 files changed, 39 insertions, 1 deletions
diff --git a/service/test/support/test_helper.py b/service/test/support/test_helper.py
index ebe8a897..57f41a6e 100644
--- a/service/test/support/test_helper.py
+++ b/service/test/support/test_helper.py
@@ -45,6 +45,20 @@ def mail_dict():
}
+def duplicates_in_fields_mail_dict():
+ return {
+ 'header': {
+ 'to': ['to@pixelated.org', 'another@pixelated.org', 'third@pixelated.org'],
+ 'cc': ['cc@pixelated.org', 'another@pixelated.org', 'third@pixelated.org'],
+ 'bcc': ['bcc@pixelated.org', 'another@pixelated.org'],
+ 'subject': 'Subject'
+ },
+ 'body': 'Body',
+ 'ident': '',
+ 'tags': []
+ }
+
+
class TestDoc(object):
def __init__(self, content):
self.content = content
diff --git a/service/test/unit/adapter/services/test_mail_sender.py b/service/test/unit/adapter/services/test_mail_sender.py
index 9a7e8fea..77435b66 100644
--- a/service/test/unit/adapter/services/test_mail_sender.py
+++ b/service/test/unit/adapter/services/test_mail_sender.py
@@ -22,7 +22,7 @@ from pixelated.adapter.services.mail_sender import MailSender, MailSenderExcepti
from pixelated.adapter.model.mail import InputMail
from pixelated.bitmask_libraries.smtp import LeapSMTPConfig
from pixelated.support.functional import flatten
-from test.support.test_helper import mail_dict
+from test.support.test_helper import mail_dict, duplicates_in_fields_mail_dict
from twisted.internet import reactor, defer
from twisted.internet.defer import Deferred
from mockito.matchers import Matcher
@@ -101,6 +101,30 @@ class MailSenderTest(unittest.TestCase):
for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
verify(OutgoingMail).send_message(MailToSmtpFormatCapture(recipient, bccs), TwistedSmtpUserCapture(recipient))
+
+ @defer.inlineCallbacks
+ def test_if_recipent_doubled_in_fields_send_only_in_bcc(self):
+ input_mail = InputMail.from_dict(duplicates_in_fields_mail_dict(), from_address='pixelated@org')
+ when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))
+
+ yield self.sender.sendmail(input_mail)
+
+ self.assertIn('to@pixelated.org', input_mail.to)
+ self.assertNotIn('another@pixelated.org', input_mail.to)
+ #self.assertIn('another@pixelated.org', input_mail.bcc)
+
+ @defer.inlineCallbacks
+ def test_if_recipent_doubled_in_fields_send_only_in_to(self):
+ input_mail = InputMail.from_dict(duplicates_in_fields_mail_dict(), from_address='pixelated@org')
+ when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))
+
+ yield self.sender.sendmail(input_mail)
+
+ self.assertIn('third@pixelated.org', input_mail.to)
+ self.assertNotIn('third@pixelated.org', input_mail.cc)
+ self.assertIn('cc@pixelated.org', input_mail.cc)
+ self.assertNotIn(['third@pixelated.org', 'another@pixelated.org'], input_mail.cc)
+
def test_remove_canonical_recipient_when_it_is_not_canonical(self):
recipient = u'user@pixelated.org'