Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
test: improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Feb 7, 2024
1 parent d9ec7a9 commit e752256
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion event_sink_clickhouse/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
11 changes: 4 additions & 7 deletions event_sink_clickhouse/sinks/base_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
45 changes: 44 additions & 1 deletion tests/test_base_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,47 @@ 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
# http://foo.openedx.org:8123/ . Note that we only support the ClickHouse HTTP interface
# 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,
},
Expand Down Expand Up @@ -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)

0 comments on commit e752256

Please sign in to comment.