diff --git a/api/tests/unit/audit/test_unit_audit_signals.py b/api/tests/unit/audit/test_unit_audit_signals.py index 3fd924141635..6265276f2ff0 100644 --- a/api/tests/unit/audit/test_unit_audit_signals.py +++ b/api/tests/unit/audit/test_unit_audit_signals.py @@ -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 @@ -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 + ) diff --git a/api/tests/unit/integrations/grafana/conftest.py b/api/tests/unit/integrations/grafana/conftest.py deleted file mode 100644 index a4186d3e8d19..000000000000 --- a/api/tests/unit/integrations/grafana/conftest.py +++ /dev/null @@ -1,12 +0,0 @@ -import pytest - -from integrations.grafana.models import GrafanaConfiguration - - -@pytest.fixture() -def deleted_grafana_configuration(project): - configuration = GrafanaConfiguration.objects.create( - project=project, base_url="http://localhost:3001", api_key="some-key" - ) - configuration.delete() - return configuration