Skip to content

Commit

Permalink
fix: assert for subset ignoring runtime generated only metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi committed Oct 26, 2023
1 parent eef9798 commit c980f89
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions eventtracking/backends/tests/test_event_bus.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
"""
Test the async routing backend.
"""
from django.test import override_settings
import json

from unittest import TestCase
from unittest.mock import sentinel, patch, Mock
from eventtracking.backends.event_bus import EventBusRoutingBackend
from openedx_events.analytics.data import TrackingLogData
from openedx_events.analytics.signals import TRACKING_EVENT_EMITTED

class TestAsyncRoutingBackend(TestCase):
"""
Expand All @@ -28,24 +30,32 @@ def test_successful_send(self, mocked_send_event):
backend.send(self.sample_event)
mocked_send_event.assert_called_once_with(self.sample_event)

@override_settings(SEND_TRACKING_EVENT_EMITTED_SIGNAL=True)
@patch('eventtracking.backends.event_bus.get_producer')
def test_successful_send_event(self, mock_get_producer):
backend = EventBusRoutingBackend()
backend.send(self.sample_event)
mock_send = Mock()

mock_get_producer.return_value = Mock(send=mock_send)

mock_get_producer.assert_called()
backend = EventBusRoutingBackend()
backend.send(self.sample_event)

mock_get_producer.assert_called()
mock_send.assert_called()
mock_send.assert_called_once_with(
tracking_log=TrackingLogData(
name=self.sample_event['name'],
timestamp=self.sample_event['timestamp'],
data=json.dumps(self.sample_event['data']),
context=json.dumps(self.sample_event['context']),
)
self.assertDictContainsSubset(
{
"signal": TRACKING_EVENT_EMITTED,
"topic": "analytics",
"event_key_field": "tracking_log.name",
"event_data": {
"tracking_log": TrackingLogData(
name=self.sample_event['name'],
timestamp=self.sample_event['timestamp'],
data=json.dumps(self.sample_event['data']),
context=json.dumps(self.sample_event['context']),
)
},
},
mock_send.call_args.kwargs
)

@patch('eventtracking.backends.event_bus.SEND_TRACKING_EVENT_EMITTED_SIGNAL.is_enabled')
Expand Down

0 comments on commit c980f89

Please sign in to comment.