def test_handle_bounce_event(self): """ Test handling a normal bounce request. """ req_mail_obj, req_bounce_obj, notification = get_mock_bounce() def _handler(sender, mail_obj, bounce_obj, raw_message, **kwargs): _handler.call_count += 1 self.assertEqual(req_mail_obj, mail_obj) self.assertEqual(req_bounce_obj, bounce_obj) self.assertEqual(raw_message, json.dumps(notification).encode()) _handler.call_count = 0 bounce_received.connect(_handler) # Mock the verification with mock.patch.object(ses_utils, "verify_event_message") as verify: verify.return_value = True response = self.client.post(reverse("event_webhook"), json.dumps(notification), content_type="application/json") self.assertEqual(response.status_code, 200) self.assertEqual(_handler.call_count, 1)
def test_handle_bounce(self): """ Test handling a normal bounce request. """ req_mail_obj = { "timestamp":"2012-05-25T14:59:38.623-07:00", "messageId":"000001378603177f-7a5433e7-8edb-42ae-af10-f0181f34d6ee-000000", "source":"*****@*****.**", "destination":[ "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" ] } req_bounce_obj = { 'bounceType': 'Permanent', 'bounceSubType': 'General', 'bouncedRecipients': [ { "status":"5.0.0", "action":"failed", "diagnosticCode":"smtp; 550 user unknown", "emailAddress":"*****@*****.**", }, { "status":"4.0.0", "action":"delayed", "emailAddress":"*****@*****.**", } ], "reportingMTA": "example.com", "timestamp":"2012-05-25T14:59:38.605-07:00", "feedbackId":"000001378603176d-5a4b5ad9-6f30-4198-a8c3-b1eb0c270a1d-000000", } message_obj = { 'notificationType': 'Bounce', 'mail': req_mail_obj, 'bounce': req_bounce_obj, } notification = { "Type" : "Notification", "MessageId" : "22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324", "TopicArn" : "arn:aws:sns:us-east-1:123456789012:MyTopic", "Subject" : "AWS Notification Message", "Message" : json.dumps(message_obj), "Timestamp" : "2012-05-02T00:54:06.655Z", "SignatureVersion" : "1", "Signature" : "", "SigningCertURL" : "", "UnsubscribeURL" : "" } def _handler(sender, mail_obj, bounce_obj, **kwargs): _handler.called = True self.assertEquals(req_mail_obj, mail_obj) self.assertEquals(req_bounce_obj, bounce_obj) _handler.called = False bounce_received.connect(_handler) # Mock the verification with mock.patch.object(ses_utils, 'verify_bounce_message') as verify: verify.return_value = True self.client.post(reverse('django_ses_bounce'), json.dumps(notification), content_type='application/json') self.assertTrue(_handler.called)
def test_handle_bounce(self): """ Test handling a normal bounce request. """ req_mail_obj = { "timestamp": "2012-05-25T14:59:38.623-07:00", "messageId": "000001378603177f-7a5433e7-8edb-42ae-af10-f0181f34d6ee-000000", "source": "*****@*****.**", "destination": [ "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**" ] } req_bounce_obj = { 'bounceType': 'Permanent', 'bounceSubType': 'General', 'bouncedRecipients': [{ "status": "5.0.0", "action": "failed", "diagnosticCode": "smtp; 550 user unknown", "emailAddress": "*****@*****.**", }, { "status": "4.0.0", "action": "delayed", "emailAddress": "*****@*****.**", }], "reportingMTA": "example.com", "timestamp": "2012-05-25T14:59:38.605-07:00", "feedbackId": "000001378603176d-5a4b5ad9-6f30-4198-a8c3-b1eb0c270a1d-000000", } message_obj = { 'notificationType': 'Bounce', 'mail': req_mail_obj, 'bounce': req_bounce_obj, } notification = { "Type": "Notification", "MessageId": "22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324", "TopicArn": "arn:aws:sns:us-east-1:123456789012:MyTopic", "Subject": "AWS Notification Message", "Message": json.dumps(message_obj), "Timestamp": "2012-05-02T00:54:06.655Z", "SignatureVersion": "1", "Signature": "", "SigningCertURL": "", "UnsubscribeURL": "" } def _handler(sender, mail_obj, bounce_obj, **kwargs): _handler.called = True self.assertEquals(req_mail_obj, mail_obj) self.assertEquals(req_bounce_obj, bounce_obj) _handler.called = False bounce_received.connect(_handler) # Mock the verification with mock.patch.object(ses_utils, 'verify_bounce_message') as verify: verify.return_value = True self.client.post(reverse('django_ses_bounce'), json.dumps(notification), content_type='application/json') self.assertTrue(_handler.called)