Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Aug 22, 2024
1 parent 19b55c0 commit 2f4749d
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion api/tests/unit/audit/test_unit_audit_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

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 audit.signals import (
call_webhooks,
send_audit_log_event_to_dynatrace,
send_audit_log_event_to_grafana,
)
from environments.models import Environment
from integrations.dynatrace.models import DynatraceConfiguration
from integrations.grafana.models import (
GrafanaOrganisationConfiguration,
GrafanaProjectConfiguration,
Expand Down Expand Up @@ -149,3 +155,38 @@ def test_send_audit_log_event_to_grafana__organisation_grafana_config__calls_exp
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_dynatrace__environment_dynatrace_config__calls_expected(
mocker: MockerFixture,
environment: Environment,
) -> None:
# Given
dynatrace_config = DynatraceConfiguration.objects.create(
base_url="http://test.com", api_key="api_123", environment=environment
)
environment.refresh_from_db()
audit_log_record = AuditLog.objects.create(
environment=environment,
related_object_type=RelatedObjectType.FEATURE.name,
)
dynatrace_wrapper_mock = mocker.patch(
"audit.signals.DynatraceWrapper", autospec=True
)
dynatrace_wrapper_instance_mock = dynatrace_wrapper_mock.return_value

# When
send_audit_log_event_to_dynatrace(AuditLog, audit_log_record)

# Then
dynatrace_wrapper_mock.assert_called_once_with(
base_url=dynatrace_config.base_url,
api_key=dynatrace_config.api_key,
entity_selector=dynatrace_config.entity_selector,
)
dynatrace_wrapper_instance_mock.generate_event_data.assert_called_once_with(
audit_log_record
)
dynatrace_wrapper_instance_mock.track_event_async.assert_called_once_with(
event=dynatrace_wrapper_instance_mock.generate_event_data.return_value
)

0 comments on commit 2f4749d

Please sign in to comment.