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

Commit

Permalink
chore: quality fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Feb 12, 2024
1 parent 01aae49 commit b2d450d
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions tests/commands/test_dump_data_to_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@

from collections import namedtuple
from datetime import datetime
from unittest.mock import Mock

import django.core.management.base
import pytest
from django.core.management import call_command
from django_mock_queries.query import MockModel, MockSet

from event_sink_clickhouse.sinks.base_sink import ModelBaseSink

CommandOptions = namedtuple(
"TestCommandOptions", ["options", "expected_num_submitted", "expected_logs"]
)

from django_mock_queries.query import MockSet, MockModel




def dummy_model_factory():
"""
Expand Down Expand Up @@ -81,11 +77,11 @@ class DummySink(ModelBaseSink):

def get_queryset(self, start_pk=None):
qs = MockSet(
MockModel(mock_name='john', email='[email protected]', pk=1),
MockModel(mock_name='jeff', email='[email protected]', pk=2),
MockModel(mock_name='bill', email='[email protected]', pk=3),
MockModel(mock_name='joe', email='[email protected]', pk=4),
MockModel(mock_name='jim', email='[email protected]', pk=5),
MockModel(mock_name="john", email="[email protected]", pk=1),
MockModel(mock_name="jeff", email="[email protected]", pk=2),
MockModel(mock_name="bill", email="[email protected]", pk=3),
MockModel(mock_name="joe", email="[email protected]", pk=4),
MockModel(mock_name="jim", email="[email protected]", pk=5),
)
if start_pk:
qs = qs.filter(pk__gt=start_pk)
Expand All @@ -109,7 +105,9 @@ def dump_command_basic_options():
CommandOptions(
options={"object": "dummy", "batch_size": 1, "sleep_time": 0},
expected_num_submitted=5,
expected_logs=["Dumped 5 objects to ClickHouse",],
expected_logs=[
"Dumped 5 objects to ClickHouse",
],
),
CommandOptions(
options={"object": "dummy", "limit": 1, "batch_size": 1, "sleep_time": 0},
Expand All @@ -119,17 +117,35 @@ def dump_command_basic_options():
CommandOptions(
options={"object": "dummy", "batch_size": 2, "sleep_time": 0},
expected_num_submitted=2,
expected_logs=["Now dumping 2 Dummy to ClickHouse",],
expected_logs=[
"Now dumping 2 Dummy to ClickHouse",
],
),
CommandOptions(
options={"object": "dummy", "batch_size": 1, "sleep_time": 0, "ids": ["1", "2", "3"]},
options={
"object": "dummy",
"batch_size": 1,
"sleep_time": 0,
"ids": ["1", "2", "3"],
},
expected_num_submitted=3,
expected_logs=["Now dumping 1 Dummy to ClickHouse", "Dumped 3 objects to ClickHouse"],
expected_logs=[
"Now dumping 1 Dummy to ClickHouse",
"Dumped 3 objects to ClickHouse",
],
),
CommandOptions(
options={"object": "dummy", "batch_size": 1, "sleep_time": 0, "start_pk": 1},
options={
"object": "dummy",
"batch_size": 1,
"sleep_time": 0,
"start_pk": 1,
},
expected_num_submitted=4,
expected_logs=["Now dumping 1 Dummy to ClickHouse", "Dumped 4 objects to ClickHouse"],
expected_logs=[
"Now dumping 1 Dummy to ClickHouse",
"Dumped 4 objects to ClickHouse",
],
),
]

Expand Down

0 comments on commit b2d450d

Please sign in to comment.