This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(): | ||
""" | ||
|
@@ -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) | ||
|
@@ -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}, | ||
|
@@ -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", | ||
], | ||
), | ||
] | ||
|
||
|