コード例 #1
0
ファイル: test_views.py プロジェクト: tricoder42/django-ses
    def test_handle_complaint(self):
        """
        Test handling a normal complaint request.
        """
        req_mail_obj = {
            "timestamp":"2012-05-25T14:59:38.623-07:00",
            "messageId":"000001378603177f-7a5433e7-8edb-42ae-af10-f0181f34d6ee-000000",
            "source":"*****@*****.**",
            "destination": [
                "*****@*****.**",
                "*****@*****.**",
                "*****@*****.**",
                "*****@*****.**",
            ]
        }
        req_complaint_obj = {
            "userAgent":"Comcast Feedback Loop (V0.01)",
            "complainedRecipients": [
                {
                    "emailAddress":"*****@*****.**",
                }
            ],
            "complaintFeedbackType":"abuse",
            "arrivalDate":"2009-12-03T04:24:21.000-05:00",
            "timestamp":"2012-05-25T14:59:38.623-07:00",
            "feedbackId":"000001378603177f-18c07c78-fa81-4a58-9dd1-fedc3cb8f49a-000000",
        }

        message_obj = {
            'notificationType': 'Complaint',
            'mail': req_mail_obj,
            'complaint': req_complaint_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, complaint_obj, **kwargs):
            _handler.called = True
            self.assertEquals(req_mail_obj, mail_obj)
            self.assertEquals(req_complaint_obj, complaint_obj)
        _handler.called = False
        complaint_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)
コード例 #2
0
ファイル: views.py プロジェクト: piyushmaurya23/test1
    def test_handle_complaint(self):
        """
        Test handling a normal complaint request.
        """
        req_mail_obj = {
            "timestamp":
            "2012-05-25T14:59:38.623-07:00",
            "messageId":
            "000001378603177f-7a5433e7-8edb-42ae-af10-f0181f34d6ee-000000",
            "source":
            "*****@*****.**",
            "destination": [
                "*****@*****.**",
                "*****@*****.**",
                "*****@*****.**",
                "*****@*****.**",
            ]
        }
        req_complaint_obj = {
            "userAgent":
            "Comcast Feedback Loop (V0.01)",
            "complainedRecipients": [{
                "emailAddress": "*****@*****.**",
            }],
            "complaintFeedbackType":
            "abuse",
            "arrivalDate":
            "2009-12-03T04:24:21.000-05:00",
            "timestamp":
            "2012-05-25T14:59:38.623-07:00",
            "feedbackId":
            "000001378603177f-18c07c78-fa81-4a58-9dd1-fedc3cb8f49a-000000",
        }

        message_obj = {
            'notificationType': 'Complaint',
            'mail': req_mail_obj,
            'complaint': req_complaint_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, complaint_obj, **kwargs):
            _handler.called = True
            self.assertEquals(req_mail_obj, mail_obj)
            self.assertEquals(req_complaint_obj, complaint_obj)

        _handler.called = False
        complaint_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)