Skip to content

Commit

Permalink
Merge pull request #537 from UW-GAC/bugfix/api-errors-in-audit
Browse files Browse the repository at this point in the history
Raise a CommandError instead of printing a message
  • Loading branch information
amstilp authored Nov 12, 2024
2 parents d3ebfe2 + d66e0bd commit 8c52fd2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

## Devel

* Bugfix: `run_anvil_audit` now raises a `CommandException` if an API call fails.

## 0.26.0 (2024-11-08)

* Move most account settings into the Account adapter
Expand Down
2 changes: 1 addition & 1 deletion anvil_consortium_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.26.0"
__version__ = "0.26.1.dev0"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."))
Expand Down
4 changes: 2 additions & 2 deletions anvil_consortium_manager/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c52fd2

Please sign in to comment.