diff --git a/event_sink_clickhouse/settings/common.py b/event_sink_clickhouse/settings/common.py index 73dae80..2ff6818 100644 --- a/event_sink_clickhouse/settings/common.py +++ b/event_sink_clickhouse/settings/common.py @@ -13,7 +13,7 @@ def plugin_settings(settings): # to avoid pulling in more dependencies to the platform than necessary. "url": "http://clickhouse:8123", "username": "ch_cms", - "password": "TYreGozgtDG3vkoWPUHVVM6q", + "password": "password", "database": "event_sink", "timeout_secs": 5, } diff --git a/event_sink_clickhouse/sinks/base_sink.py b/event_sink_clickhouse/sinks/base_sink.py index 94cf717..b66ad0c 100644 --- a/event_sink_clickhouse/sinks/base_sink.py +++ b/event_sink_clickhouse/sinks/base_sink.py @@ -288,13 +288,10 @@ def fetch_target_items(self, start_pk=None, ids=None, skip_ids=None, force_dump= skip_ids = ( [str(item_id) for item_id in skip_ids] if skip_ids else [] ) - if batch_size: - paginator = Paginator(item_keys, batch_size) - for i in range(1, paginator.num_pages): - page = paginator.page(i) - yield from self.iter_target_items(page.object_list, skip_ids, force_dump) - else: - yield from self.iter_target_items(item_keys, skip_ids, force_dump) + paginator = Paginator(item_keys, batch_size) + for i in range(1, paginator.num_pages): + page = paginator.page(i) + yield from self.iter_target_items(page.object_list, skip_ids, force_dump) def iter_target_items(self, item_keys, skip_ids, force_dump): """ diff --git a/tests/test_base_sink.py b/tests/test_base_sink.py index a215225..9c39158 100644 --- a/tests/test_base_sink.py +++ b/tests/test_base_sink.py @@ -25,6 +25,39 @@ class ChildSink(ModelBaseSink): # pylint: disable=abstract-method serializer_class = Mock() +@override_settings( + EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG={ + "url": "http://clickhouse:8123", + "username": "ch_cms", + "password": "password", + "database": "event_sink", + "timeout_secs": 5, + }, + EVENT_SINK_CLICKHOUSE_MODEL_CONFIG={}, +) +class TestBaseSink(TestCase): + """ + Tests for the BaseSink. + """ + + def test_connection_overrides(self): + """ + Test that connection_overrides() returns the correct data. + """ + child_sink = ChildSink(connection_overrides={ + "url": "http://dummy:8123", + "username": "dummy_username", + "password": "dummy_password", + "database": "dummy_database", + "timeout_secs": 0, + }, log=logging.getLogger()) + + self.assertEqual(child_sink.ch_url, "http://dummy:8123") + self.assertEqual(child_sink.ch_auth, ("dummy_username", "dummy_password")) + self.assertEqual(child_sink.ch_database, "dummy_database") + self.assertEqual(child_sink.ch_timeout_secs, 0) + + @override_settings( EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG={ # URL to a running ClickHouse server's HTTP interface. ex: https://foo.openedx.org:8443/ or @@ -32,7 +65,7 @@ class ChildSink(ModelBaseSink): # pylint: disable=abstract-method # to avoid pulling in more dependencies to the platform than necessary. "url": "http://clickhouse:8123", "username": "ch_cms", - "password": "TYreGozgtDG3vkoWPUHVVM6q", + "password": "password", "database": "event_sink", "timeout_secs": 5, }, @@ -243,3 +276,13 @@ def test_is_enabled(self): Test that is_enable() returns the correct data. """ self.assertEqual(self.child_sink.is_enabled(), True) + + def test_get_sink_by_model_name(self): + """ + Test that get_sink_by_model_name() returns the correct data. + """ + no_sink = ModelBaseSink.get_sink_by_model_name("non_existent_model") + child_sink = ModelBaseSink.get_sink_by_model_name("child_model") + + self.assertIsNone(no_sink) + self.assertEqual(child_sink, ChildSink)