Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Jun 23, 2024
1 parent e5272ee commit 57a0169
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
34 changes: 33 additions & 1 deletion api/tests/unit/audit/test_unit_audit_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from pytest_mock import MockerFixture

from audit.models import AuditLog
from audit.signals import call_webhooks
from audit.related_object_type import RelatedObjectType
from audit.signals import call_webhooks, send_audit_log_event_to_grafana
from integrations.grafana.models import GrafanaConfiguration
from organisations.models import Organisation, OrganisationWebhook
from projects.models import Project
from webhooks.webhooks import WebhookEventType
Expand Down Expand Up @@ -81,3 +83,33 @@ def test_call_webhooks_creates_task_if_organisation_has_webhooks(
assert mock_call["args"][0] == organisation.id
assert mock_call["args"][1]["id"] == audit_log.id
assert mock_call["args"][2] == WebhookEventType.AUDIT_LOG_CREATED.name


def test_send_audit_log_event_to_grafana__project_grafana_config__calls_expected(
mocker: MockerFixture,
project: Project,
) -> None:
# Given
grafana_config = GrafanaConfiguration(base_url="test.com", api_key="test")
project.grafana_config = grafana_config
audit_log_record = AuditLog.objects.create(
project=project,
related_object_type=RelatedObjectType.FEATURE.name,
)
grafana_wrapper_mock = mocker.patch("audit.signals.GrafanaWrapper", autospec=True)
grafana_wrapper_instance_mock = grafana_wrapper_mock.return_value

# When
send_audit_log_event_to_grafana(AuditLog, audit_log_record)

# Then
grafana_wrapper_mock.assert_called_once_with(
base_url=grafana_config.base_url,
api_key=grafana_config.api_key,
)
grafana_wrapper_instance_mock.generate_event_data.assert_called_once_with(
audit_log_record
)
grafana_wrapper_instance_mock.track_event_async.assert_called_once_with(
event=grafana_wrapper_instance_mock.generate_event_data.return_value
)
12 changes: 0 additions & 12 deletions api/tests/unit/integrations/grafana/conftest.py

This file was deleted.

0 comments on commit 57a0169

Please sign in to comment.