Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
fix(audit): incorrect audit report redirect params (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarosevcik committed Feb 26, 2021
1 parent 0f71065 commit 1d1444c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ jobs:
steps:
- uses: actions/checkout@v2

- run: apk add --no-cache tar

- name: Cache
uses: actions/cache@v2
with:
Expand All @@ -87,7 +85,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- run: apk add --no-cache tar
- run: apk add --no-cache cargo tar

- name: Cache
uses: actions/cache@v2
Expand Down Expand Up @@ -129,7 +127,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- run: apk add --no-cache tar
- run: apk add --no-cache cargo tar

- name: Cache
uses: actions/cache@v2
Expand Down
15 changes: 12 additions & 3 deletions test/auditing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from slacker import Error as SlackError

import zoo.auditing.runner as uut
from zoo import auditing
from zoo.auditing.models import Issue

pytestmark = pytest.mark.django_db
Expand Down Expand Up @@ -62,12 +63,13 @@ def test_save_check_result__found_new_issue(is_found, status, repository, freeze
),
)
def test_save_check_result__existing_issue(
is_found, old_status, new_status, issue_factory, freezer
is_found, old_status, new_status, issue_factory, service_factory, freezer
):
issue = issue_factory(
status=old_status, last_check=arrow.utcnow().shift(years=-1).datetime
)
repository = issue.repository
service = service_factory(repository=repository)

uut.save_check_result(repository, issue.kind_key, is_found)

Expand Down Expand Up @@ -110,9 +112,11 @@ def test_save_check_result__details_of_new_issue(
),
)
def test_save_check_result__details_of_existing_issue(
is_found, old_details, details, expected_details, issue_factory
is_found, old_details, details, expected_details, issue_factory, service_factory
):
issue = issue_factory(details=old_details)
service = service_factory(repository=issue.repository)

uut.save_check_result(issue.repository, issue.kind_key, is_found, details)

new_issue = Issue.objects.get()
Expand Down Expand Up @@ -178,10 +182,11 @@ def test_check_repository__failing_check(repository, fake_path, mocker):
)


def test_run_checks_and_save_results(repository, fake_path, mocker):
def test_run_checks_and_save_results(repository, fake_path, mocker, service_factory):
checks = [check_passing, check_found, check_unknown]

uut.run_checks_and_save_results(checks, repository, fake_path)
service = service_factory(repository=repository)

assert Issue.objects.count() == 2

Expand Down Expand Up @@ -251,13 +256,17 @@ def test_notify_status_change(mocker, issue_factory, service_factory):
issue = issue_factory(repository=service.repository)
log = mocker.patch("zoo.auditing.runner.log", mocker.Mock())
slack = mocker.patch("zoo.auditing.runner.slack", mocker.Mock())
m_reverse = mocker.patch("zoo.auditing.runner.reverse", mocker.Mock())

uut.notify_status_change(issue)
slack.chat.post_message.assert_called_once()
channel, text = slack.chat.post_message.call_args[0]
assert channel == service.slack_channel
assert issue.kind.title in text
assert issue.repository.name in text
m_reverse.assert_called_once_with(
"audit_report", args=("services", service.owner_slug, service.name_slug)
)

# Unhappy path
slack.chat.post_message.side_effect = SlackError("channel_not_found")
Expand Down
4 changes: 3 additions & 1 deletion zoo/auditing/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from slacker import Error as SlackError
from slacker import Slacker

from ..services.models import Service
from .check_discovery import CHECKS
from .models import Issue

Expand Down Expand Up @@ -79,9 +80,10 @@ def update_issue(issue: Issue, is_found, details=None):
def notify_status_change(issue: Issue):
if Issue.Status(issue.status) in [Issue.Status.NEW, Issue.Status.REOPENED]:
site = Site.objects.get_current()
service = Service.objects.get(repository=issue.repository)
audit_url = reverse(
"audit_report",
args=("services", issue.repository.owner, issue.repository.name),
args=("services", service.owner_slug, service.name_slug),
)
text = "{status} issue {issue} on <{repo.url}|{repo.name}>.".format(
status=issue.status.title(),
Expand Down

0 comments on commit 1d1444c

Please sign in to comment.