diff --git a/anvil_consortium_manager/management/commands/run_anvil_audit.py b/anvil_consortium_manager/management/commands/run_anvil_audit.py index 261d0e11..1832abaf 100644 --- a/anvil_consortium_manager/management/commands/run_anvil_audit.py +++ b/anvil_consortium_manager/management/commands/run_anvil_audit.py @@ -3,7 +3,7 @@ import django_tables2 as tables from django.contrib.sites.models import Site from django.core.mail import send_mail -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandError from django.template.loader import render_to_string from ...anvil_api import AnVILAPIError @@ -58,7 +58,7 @@ def _run_audit(self, audit_results, **options): # Assume the method is called anvil_audit. audit_results.run_audit() except AnVILAPIError: - self.stdout.write(self.style.ERROR("API error.")) + raise CommandError("API error.") else: if not audit_results.ok(): self.stdout.write(self.style.ERROR("problems found.")) diff --git a/anvil_consortium_manager/tests/test_commands.py b/anvil_consortium_manager/tests/test_commands.py index e1fc11b0..8ce9a3ca 100644 --- a/anvil_consortium_manager/tests/test_commands.py +++ b/anvil_consortium_manager/tests/test_commands.py @@ -254,8 +254,8 @@ def test_command_run_audit_api_error(self): api_url = self.get_api_url_billing_project(billing_project.name) self.anvil_response_mock.add(responses.GET, api_url, status=500, json={"message": "error"}) out = StringIO() - call_command("run_anvil_audit", "--no-color", models=["BillingProject"], stdout=out) - self.assertIn("BillingProjectAudit... API error.", out.getvalue()) + with self.assertRaises(CommandError): + call_command("run_anvil_audit", "--no-color", models=["BillingProject"], stdout=out) # This test is complicated so skipping for now. # When trying to change the settings, the test attempts to repopulate the