Skip to content

Commit

Permalink
test: add test for event emission exit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Oct 27, 2023
1 parent 4c77c54 commit e142f24
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions event_routing_backends/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
Test handlers for signals emitted by the analytics app
"""

from unittest.mock import Mock, patch
from unittest.mock import patch

from django.test import TestCase
from django.test.utils import override_settings
from eventtracking.django.django_tracker import DjangoTracker
from eventtracking.processors.exceptions import EventEmissionExit
from openedx_events.analytics.data import TrackingLogData

from event_routing_backends.handlers import send_tracking_log_to_backends
Expand Down Expand Up @@ -64,15 +63,28 @@ def test_send_tracking_log_to_backends(
True,
)

@override_settings(
EVENT_TRACKING_BACKENDS={
"event_bus": {
"ENGINE": "eventtracking.backends.event_bus.EventBusRoutingBackend",
"OPTIONS": {
"processors": [
{
"ENGINE": "eventtracking.processors.whitelist.NameWhitelistProcessor",
"OPTIONS": {
"whitelist": ["no_test_name"]
}
}
],
},
},
}
)
@patch("event_routing_backends.handlers.get_tracker")
@patch("event_routing_backends.handlers.isinstance")
@patch(
"event_routing_backends.handlers.send_event",
**{"return_value.raiseError.side_effect": EventEmissionExit()}
)
@patch("event_routing_backends.handlers.logger")
def test_send_tracking_log_to_backends_error(
self, mock_logger, mock_send_event, mock_is_instance, mock_get_tracker
self, mock_logger, mock_is_instance, mock_get_tracker
):
"""
Test for send_tracking_log_to_backends
Expand All @@ -95,6 +107,6 @@ def test_send_tracking_log_to_backends_error(

assert x is None

# mock_logger.info.assert_called_once_with(
# "[EventEmissionExit] skipping event {}".format("test_name")
# )
mock_logger.info.assert_called_once_with(
"[EventEmissionExit] skipping event {}".format("test_name")
)

0 comments on commit e142f24

Please sign in to comment.