Skip to content

Commit

Permalink
chore: quality fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Oct 30, 2023
1 parent eb53c0d commit 29e8faa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
11 changes: 6 additions & 5 deletions event_routing_backends/backends/async_events_router.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""
Generic async router to send events to hosts via celery.
"""
from event_routing_backends.tasks import dispatch_bulk_events, dispatch_event, dispatch_event_persistent
from event_routing_backends.backends.events_router import EventsRouter
from event_routing_backends.tasks import dispatch_bulk_events, dispatch_event, dispatch_event_persistent


class AsyncEventsRouter(EventsRouter):
"""
Router to send events to hosts via celery using requests library.
"""

def dispatch_event(self, event_name, event, router_type, host_configurations):
def dispatch_event(self, event_name, updated_event, router_type, host_configurations):
"""
Dispatch the event to the configured router.
Expand All @@ -19,7 +20,7 @@ def dispatch_event(self, event_name, event, router_type, host_configurations):
router_type (str): type of the router
host_configurations (dict): host configurations dict
"""
dispatch_event.delay(event_name, event, router_type, host_configurations)
dispatch_event.delay(event_name, updated_event, router_type, host_configurations)

def dispatch_bulk_events(self, events, router_type, host_configurations):
"""
Expand All @@ -32,7 +33,7 @@ def dispatch_bulk_events(self, events, router_type, host_configurations):
"""
dispatch_bulk_events.delay(events, router_type, host_configurations)

def dispatch_event_persistent(self, event_name, event, router_type, host_configurations):
def dispatch_event_persistent(self, event_name, updated_event, router_type, host_configurations):
"""
Dispatch the event to the configured router providing persistent storage.
Expand All @@ -42,4 +43,4 @@ def dispatch_event_persistent(self, event_name, event, router_type, host_configu
router_type (str): type of the router
host_configurations (dict): host configurations dict
"""
dispatch_event_persistent.delay(event_name, event, router_type, host_configurations)
dispatch_event_persistent.delay(event_name, updated_event, router_type, host_configurations)
3 changes: 0 additions & 3 deletions event_routing_backends/backends/events_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ def send(self, event):

for events_for_route in event_routes.values():
for event_name, updated_event, host, is_business_critical in events_for_route:
from event_routing_backends.backends.sync_events_router import SyncEventsRouter
#if event_name == 'edx.course.enrollment.activated' and self.__class__ == SyncEventsRouter:
# raise ValueError(f"event_name {event_name}, host {host}, is_business_critical {is_business_critical}")
if is_business_critical:
self.dispatch_event_persistent(
event_name,
Expand Down
11 changes: 6 additions & 5 deletions event_routing_backends/backends/sync_events_router.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""
Generic router to send events to hosts.
"""
from event_routing_backends.tasks import send_event, bulk_send_events
from event_routing_backends.backends.events_router import EventsRouter
from event_routing_backends.tasks import bulk_send_events, send_event


class SyncEventsRouter(EventsRouter):
"""
Router to send events to hosts via celery using requests library.
"""

def dispatch_event(self, event_name, event, router_type, host_configurations):
def dispatch_event(self, event_name, updated_event, router_type, host_configurations):
"""
Dispatch the event to the configured router.
Expand All @@ -19,7 +20,7 @@ def dispatch_event(self, event_name, event, router_type, host_configurations):
router_type (str): type of the router
host_configurations (dict): host configurations dict
"""
send_event(None, event_name, event, router_type, host_configurations)
send_event(None, event_name, updated_event, router_type, host_configurations)

def dispatch_bulk_events(self, events, router_type, host_configurations):
"""
Expand All @@ -32,7 +33,7 @@ def dispatch_bulk_events(self, events, router_type, host_configurations):
"""
bulk_send_events(None, events, router_type, host_configurations)

def dispatch_event_persistent(self, event_name, event, router_type, host_configurations):
def dispatch_event_persistent(self, event_name, updated_event, router_type, host_configurations):
"""
Dispatch the event to the configured router providing persistent storage.
Expand All @@ -42,4 +43,4 @@ def dispatch_event_persistent(self, event_name, event, router_type, host_configu
router_type (str): type of the router
host_configurations (dict): host configurations dict
"""
self.dispatch_event(event_name, event, router_type, host_configurations)
self.dispatch_event(event_name, updated_event, router_type, host_configurations)

Check warning on line 46 in event_routing_backends/backends/sync_events_router.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/backends/sync_events_router.py#L46

Added line #L46 was not covered by tests
9 changes: 3 additions & 6 deletions event_routing_backends/backends/tests/test_events_router.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Test the EventsRouter
"""
from unittest.mock import MagicMock, call, patch, sentinel, Mock
from unittest.mock import MagicMock, call, patch, sentinel

import ddt
from django.conf import settings
Expand Down Expand Up @@ -214,7 +214,6 @@ def test_with_no_available_hosts(self, mocked_logger, mocked_post):
mocked_logger.info.mock_calls
)


def test_with_non_dict_event(self):
RouterConfigurationFactory.create(
backend_name=RouterConfiguration.XAPI_BACKEND,
Expand All @@ -227,7 +226,6 @@ def test_with_non_dict_event(self):
with self.assertRaises(ValueError):
router.send(transformed_event)


def test_unsuccessful_routing_of_event(self):
host_configurations = {
'url': 'http://test3.com',
Expand Down Expand Up @@ -260,9 +258,8 @@ def test_duplicate_xapi_event_id(self, mocked_logger):
)



@ddt.ddt
class TestAsyncEventsRouter(TestEventsRouter):
class TestAsyncEventsRouter(TestEventsRouter): # pylint: disable=test-inherits-tests
"""
Test the AsyncEventsRouter
"""
Expand Down Expand Up @@ -803,7 +800,7 @@ def test_successful_routing_of_bulk_events(


@ddt.ddt
class TestSyncEventsRouter(TestEventsRouter):
class TestSyncEventsRouter(TestEventsRouter): # pylint: disable=test-inherits-tests
"""
Test the SyncEventsRouter
"""
Expand Down
12 changes: 3 additions & 9 deletions event_routing_backends/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Test handlers for signals emitted by the analytics app
"""

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

from django.test import TestCase
from django.test.utils import override_settings
Expand All @@ -26,22 +26,15 @@ class TestHandlers(TestCase):
}
)
@patch("event_routing_backends.handlers.get_tracker")
@patch("event_routing_backends.handlers.isinstance")
def test_send_tracking_log_to_backends(
self, mock_isinstance, mock_get_tracker
self, mock_get_tracker
):
"""
Test for send_tracking_log_to_backends
"""
tracker = DjangoTracker()
mock_get_tracker.return_value = tracker

mock_backend = Mock()

tracker.backends["event_bus"].send_to_backends = mock_backend

# mock_isinstance.return_value = True

tracker.backends["event_bus"].send_to_backends = mock_backend

send_tracking_log_to_backends(
Expand All @@ -63,6 +56,7 @@ def test_send_tracking_log_to_backends(
"context": {},
}
)

@override_settings(
EVENT_TRACKING_BACKENDS={
"event_bus": {
Expand Down

0 comments on commit 29e8faa

Please sign in to comment.