From dc3a0f2aad08d201c717796b4f64b435d6b0bf87 Mon Sep 17 00:00:00 2001 From: Jillian Vogel Date: Thu, 20 Jun 2024 15:57:05 +0930 Subject: [PATCH] test: test the "append to events settings" functionality and fix coverage --- event_routing_backends/settings/common.py | 2 ++ event_routing_backends/tests/test_settings.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/event_routing_backends/settings/common.py b/event_routing_backends/settings/common.py index 24a5f83e..dbea6c90 100644 --- a/event_routing_backends/settings/common.py +++ b/event_routing_backends/settings/common.py @@ -205,6 +205,8 @@ def plugin_settings(settings): settings.EVENT_TRACKING_BACKENDS_ALLOWED_CALIPER_EVENTS ) + if not hasattr(settings, 'EVENT_TRACKING_BACKENDS') or not settings.EVENT_TRACKING_BACKENDS: + settings.EVENT_TRACKING_BACKENDS = {} settings.EVENT_TRACKING_BACKENDS.update(event_tracking_backends_config( settings, settings.EVENT_TRACKING_BACKENDS_ALLOWED_XAPI_EVENTS, diff --git a/event_routing_backends/tests/test_settings.py b/event_routing_backends/tests/test_settings.py index 3abe5357..f6957738 100644 --- a/event_routing_backends/tests/test_settings.py +++ b/event_routing_backends/tests/test_settings.py @@ -3,7 +3,7 @@ """ from django.conf import settings -from django.test import TestCase +from django.test import TestCase, override_settings from event_routing_backends.settings import common as common_settings from event_routing_backends.settings import devstack as devstack_settings @@ -82,3 +82,16 @@ def test_production_settings(self): self.assertTrue(settings.CALIPER_EVENT_LOGGING_ENABLED) self.assertFalse(settings.XAPI_EVENTS_ENABLED) self.assertTrue(settings.XAPI_EVENT_LOGGING_ENABLED) + + @override_settings( + EVENT_TRACKING_BACKENDS_ALLOWED_XAPI_EVENTS=["my.event.1"], + EVENT_TRACKING_BACKENDS_ALLOWED_CALIPER_EVENTS=["my.event.2"], + ) + def test_settings_append_events(self): + common_settings.plugin_settings(settings) + + self.assertGreater(len(settings.EVENT_TRACKING_BACKENDS_ALLOWED_XAPI_EVENTS), 1) + self.assertIn("my.event.1", settings.EVENT_TRACKING_BACKENDS_ALLOWED_XAPI_EVENTS) + + self.assertGreater(len(settings.EVENT_TRACKING_BACKENDS_ALLOWED_CALIPER_EVENTS), 1) + self.assertIn("my.event.2", settings.EVENT_TRACKING_BACKENDS_ALLOWED_CALIPER_EVENTS)