Пример #1
0
 def set_mock_failure(self, status_code=400, raw=b'{"errors":[{"message":"test error"}]}', encoding='utf-8'):
     # Need to build a real(-ish) requests.Response for SparkPostAPIException
     response = requests.Response()
     response.status_code = status_code
     response.encoding = encoding
     response.raw = six.BytesIO(raw)
     response.url = "/mock/send"
     self.mock_send.side_effect = SparkPostAPIException(response)
Пример #2
0
def test_template_stored_invalid():
    mock_resp = mock.Mock()
    mock_resp.status_code = 422
    mock_resp.json = lambda: {
        'errors': [{
            "message": "Subresource not found",
            "description": "template 'invalid_stored_template' does not exist",
            "code": "1603"
        }]
    }

    with mock.patch.object(Transmissions, 'send') as mock_send:
        mock_send.side_effect = SparkPostAPIException(mock_resp)

        with pytest.raises(InvalidStoredTemplate):
            email = EmailMessage(subject='test subject',
                                 from_email="*****@*****.**",
                                 to=['*****@*****.**'])
            email.sparkpost = {'template_name': 'invalid_stored_template'}
            email.send()