From c58640d43814931203aa07f60bc538d41b26fa26 Mon Sep 17 00:00:00 2001 From: Mike Edmunds Date: Thu, 9 Mar 2023 09:56:42 -0800 Subject: [PATCH] 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.) --- tests/test_mandrill_integration.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_mandrill_integration.py b/tests/test_mandrill_integration.py index df78ea2..5dac6c4 100644 --- a/tests/test_mandrill_integration.py +++ b/tests/test_mandrill_integration.py @@ -171,10 +171,9 @@ class MandrillBackendIntegrationTests(AnymailTestMixin, SimpleTestCase): @override_settings(MANDRILL_API_KEY="Hey, that's not an API key!") def test_invalid_api_key(self): - # Example of trying to send with an invalid MANDRILL_API_KEY - with self.assertRaises(AnymailAPIError) as cm: + # Example of trying to send with an invalid MANDRILL_API_KEY. + # 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() - 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))