Mandrill: update integration test

Mandrill bad API key can respond either 401 or 500,
so don't bother checking exact status code. 
(Just make sure it results in a useful error.)
This commit is contained in:
Mike Edmunds
2023-03-09 09:56:42 -08:00
committed by GitHub
parent ea446a94d3
commit c58640d438

View File

@@ -171,10 +171,9 @@ class MandrillBackendIntegrationTests(AnymailTestMixin, SimpleTestCase):
@override_settings(MANDRILL_API_KEY="Hey, that's not an API key!") @override_settings(MANDRILL_API_KEY="Hey, that's not an API key!")
def test_invalid_api_key(self): def test_invalid_api_key(self):
# Example of trying to send with an invalid MANDRILL_API_KEY # Example of trying to send with an invalid MANDRILL_API_KEY.
with self.assertRaises(AnymailAPIError) as cm: # Mandrill responds either 401 or 500 status for this case (it varies),
# but always seems to include the message "Invalid API key".
# Either response should result in an AnymailAPIError.
with self.assertRaisesMessage(AnymailAPIError, "Invalid API key"):
self.message.send() self.message.send()
err = cm.exception
self.assertEqual(err.status_code, 500)
# Make sure the exception message includes Mandrill's response:
self.assertIn("Invalid API key", str(err))