Skip to content

Commit

Permalink
test: add missing tests for new sync router
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Feb 2, 2024
1 parent 29e9ee3 commit f138ce5
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions event_routing_backends/backends/tests/test_events_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,27 @@ class TestSyncEventsRouter(TestEventsRouter): # pylint: disable=test-inherits-t
"""
Test the SyncEventsRouter
"""
@patch.dict('event_routing_backends.tasks.ROUTER_STRATEGY_MAPPING', {
'AUTH_HEADERS': MagicMock(side_effect=EventNotDispatched)
})
@patch('event_routing_backends.utils.http_client.requests.post')
def test_generic_exception_business_critical_event(self, mocked_post):
RouterConfigurationFactory.create(
backend_name=RouterConfiguration.XAPI_BACKEND,
enabled=True,
route_url='http://test3.com',
auth_scheme=RouterConfiguration.AUTH_BEARER,
auth_key='test_key',
configurations=ROUTER_CONFIG_FIXTURE[0]
)

router = SyncEventsRouter(processors=[], backend_name=RouterConfiguration.CALIPER_BACKEND)
event_data = self.transformed_event.copy()
business_critical_events = get_business_critical_events()
event_data['name'] = business_critical_events[0]

router.send(event_data)
mocked_post.assert_not_called()

@ddt.data(
(RouterConfiguration.AUTH_BASIC,
Expand Down Expand Up @@ -895,6 +916,8 @@ def test_successful_routing_of_event(

router = SyncEventsRouter(processors=[], backend_name=backend_name)

self.transformed_event["name"] = get_business_critical_events()[0]

with patch.dict('event_routing_backends.tasks.ROUTER_STRATEGY_MAPPING', MOCKED_MAP):
router.send(self.transformed_event)

Expand Down Expand Up @@ -1078,3 +1101,48 @@ def test_successful_routing_of_bulk_events(

# test mocked oauth client
mocked_oauth_client.assert_not_called()

@patch('event_routing_backends.utils.xapi_lrs_client.RemoteLRS')
@ddt.unpack
def test_failed_bulk_routing(self, mocked_remote_lrs):
mock_response = MagicMock()
mock_response.success = False
mock_response.data = "Fake response data"
mock_response.response.code = 500
mock_response.request.method = "POST"
mock_response.request.content = "Fake request content"

mocked_remote_lrs.return_value.save_statements.return_value = mock_response
RouterConfigurationFactory.create(
backend_name=RouterConfiguration.XAPI_BACKEND,
enabled=True,
route_url='http://test3.com',
configurations=ROUTER_CONFIG_FIXTURE[2]
)

router = SyncEventsRouter(processors=[], backend_name=RouterConfiguration.XAPI_BACKEND)
with self.assertRaises(EventNotDispatched):
router.bulk_send([self.transformed_event])

@patch('event_routing_backends.utils.xapi_lrs_client.RemoteLRS')
@ddt.unpack
def test_failed_routing(self, mocked_remote_lrs):
mock_response = MagicMock()
mock_response.success = False
mock_response.data = "Fake response data"
mock_response.response.code = 500
mock_response.request.method = "POST"
mock_response.request.content = "Fake request content"
mocked_remote_lrs.side_effect = EventNotDispatched

mocked_remote_lrs.return_value.save_statements.return_value = mock_response
RouterConfigurationFactory.create(
backend_name=RouterConfiguration.XAPI_BACKEND,
enabled=True,
route_url='http://test3.com',
configurations=ROUTER_CONFIG_FIXTURE[2]
)

router = SyncEventsRouter(processors=[], backend_name=RouterConfiguration.XAPI_BACKEND)
with self.assertRaises(EventNotDispatched):
router.send(self.transformed_event)

0 comments on commit f138ce5

Please sign in to comment.