Beispiel #1
0
    def test_422_error_unprocessable_entity(self):
        messages = [
            PMMail(
                sender="*****@*****.**",
                to="*****@*****.**",
                subject="Subject",
                text_body="Body",
                api_key="test",
            ),
            PMMail(
                sender="*****@*****.**",
                to="*****@*****.**",
                subject="Subject",
                text_body="Body",
                api_key="test",
            ),
        ]

        json_payload = BytesIO()
        json_payload.write(b'{"Message": "", "ErrorCode": 422}')
        json_payload.seek(0)

        batch = PMBatchMail(messages=messages, api_key="test")

        with mock.patch("postmark.core.urlopen",
                        side_effect=HTTPError("", 422, "", {}, json_payload)):
            self.assertRaises(PMMailUnprocessableEntityException, batch.send)
Beispiel #2
0
    def test_500_error_server_error(self):
        messages = [
            PMMail(
                sender='*****@*****.**', to='*****@*****.**',
                subject='Subject', text_body='Body', api_key='test'
            ),
            PMMail(
                sender='*****@*****.**', to='*****@*****.**',
                subject='Subject', text_body='Body', api_key='test'
            ),
        ]

        batch = PMBatchMail(messages=messages, api_key='test')

        with mock.patch('postmark.core.urlopen', side_effect=HTTPError('',
            500, '', {}, None)):
            self.assertRaises(PMMailServerErrorException, batch.send)
Beispiel #3
0
    def test_422_error_unprocessable_entity(self):
        messages = [
            PMMail(
                sender='*****@*****.**', to='*****@*****.**',
                subject='Subject', text_body='Body', api_key='test'
            ),
            PMMail(
                sender='*****@*****.**', to='*****@*****.**',
                subject='Subject', text_body='Body', api_key='test'
            ),
        ]

        json_payload = BytesIO()
        json_payload.write(b'{"Message": "", "ErrorCode": 422}')
        json_payload.seek(0)

        batch = PMBatchMail(messages=messages, api_key='test')

        with mock.patch('postmark.core.urlopen', side_effect=HTTPError('',
            422, '', {}, json_payload)):
            self.assertRaises(PMMailUnprocessableEntityException, batch.send)
Beispiel #4
0
    def test_500_error_server_error(self):
        messages = [
            PMMail(
                sender="*****@*****.**",
                to="*****@*****.**",
                subject="Subject",
                text_body="Body",
                api_key="test",
            ),
            PMMail(
                sender="*****@*****.**",
                to="*****@*****.**",
                subject="Subject",
                text_body="Body",
                api_key="test",
            ),
        ]

        batch = PMBatchMail(messages=messages, api_key="test")

        with mock.patch("postmark.core.urlopen",
                        side_effect=HTTPError("", 500, "", {}, None)):
            self.assertRaises(PMMailServerErrorException, batch.send)