Skip to content

Commit

Permalink
test: add test for str datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Oct 30, 2023
1 parent 9cf7392 commit 28ec6c1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 2 additions & 4 deletions eventtracking/backends/event_bus.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion eventtracking/backends/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
5 changes: 4 additions & 1 deletion eventtracking/backends/tests/test_event_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"]),
)
Expand Down

0 comments on commit 28ec6c1

Please sign in to comment.