From 28ec6c111941a0e5afcc857927536aaf5408c98c Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Fri, 27 Oct 2023 13:26:35 -0500 Subject: [PATCH] test: add test for str datetime --- eventtracking/backends/event_bus.py | 6 ++---- eventtracking/backends/routing.py | 2 +- eventtracking/backends/tests/test_event_bus.py | 5 ++++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/eventtracking/backends/event_bus.py b/eventtracking/backends/event_bus.py index 8315f91..ca42988 100644 --- a/eventtracking/backends/event_bus.py +++ b/eventtracking/backends/event_bus.py @@ -1,11 +1,11 @@ """Event tracker backend that emits events to the event-bus.""" import json import logging +from datetime import datetime from openedx_events.analytics.data import TrackingLogData from openedx_events.analytics.signals import TRACKING_EVENT_EMITTED from openedx_events.event_bus import get_producer -from datetime import datetime from eventtracking.backends.routing import RoutingBackend from eventtracking.config import SEND_TRACKING_EVENT_EMITTED_SIGNAL @@ -43,9 +43,7 @@ def send(self, event): metadata = TRACKING_EVENT_EMITTED.generate_signal_metadata() - logger.info( - f"Sending tracking lof {tracking_log.name} to the event bus." - ) + logger.info(f"Sending tracking lof {tracking_log.name} to the event bus.") get_producer().send( signal=TRACKING_EVENT_EMITTED, topic="analytics", diff --git a/eventtracking/backends/routing.py b/eventtracking/backends/routing.py index 6942612..d59d941 100644 --- a/eventtracking/backends/routing.py +++ b/eventtracking/backends/routing.py @@ -142,7 +142,7 @@ def send_to_backends(self, event): LOG.info('[send_to_backends] Failed to send edx event "%s" to "%s" backend. "%s" backend has' ' not been enabled, [%s]', event["name"], name, name, repr(exc) ) - except Exception: # pylint: disable=broad-except + except Exception: LOG.exception( 'Unable to send edx event "%s" to backend: %s', event["name"], name ) diff --git a/eventtracking/backends/tests/test_event_bus.py b/eventtracking/backends/tests/test_event_bus.py index 83bb6f5..c16a7ab 100644 --- a/eventtracking/backends/tests/test_event_bus.py +++ b/eventtracking/backends/tests/test_event_bus.py @@ -2,6 +2,7 @@ Test the async routing backend. """ import json +from datetime import datetime from unittest import TestCase from unittest.mock import Mock, patch, sentinel @@ -51,7 +52,9 @@ def test_successful_send_event(self, mock_get_producer): "event_data": { "tracking_log": TrackingLogData( name=self.sample_event["name"], - timestamp=self.sample_event["timestamp"], + timestamp=datetime.strptime( + self.sample_event["timestamp"], "%Y-%m-%dT%H:%M:%S.%f%z" + ), data=json.dumps(self.sample_event["data"]), context=json.dumps(self.sample_event["context"]), )