Skip to content

Commit

Permalink
add Grafana organisation-level test
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Aug 22, 2024
1 parent a398235 commit 79f269b
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion api/tests/unit/audit/test_unit_audit_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from audit.models import AuditLog
from audit.related_object_type import RelatedObjectType
from audit.signals import call_webhooks, send_audit_log_event_to_grafana
from integrations.grafana.models import GrafanaProjectConfiguration
from integrations.grafana.models import (
GrafanaOrganisationConfiguration,
GrafanaProjectConfiguration,
)
from organisations.models import Organisation, OrganisationWebhook
from projects.models import Project
from webhooks.webhooks import WebhookEventType
Expand Down Expand Up @@ -113,3 +116,36 @@ def test_send_audit_log_event_to_grafana__project_grafana_config__calls_expected
grafana_wrapper_instance_mock.track_event_async.assert_called_once_with(
event=grafana_wrapper_instance_mock.generate_event_data.return_value
)


def test_send_audit_log_event_to_grafana__organisation_grafana_config__calls_expected(
mocker: MockerFixture,
organisation: Organisation,
project: Project,
) -> None:
# Given
grafana_config = GrafanaOrganisationConfiguration(
base_url="test.com", api_key="test"
)
organisation.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
)

0 comments on commit 79f269b

Please sign in to comment.