-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix-none-comparision
- Loading branch information
Showing
2 changed files
with
77 additions
and
2 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
45 changes: 45 additions & 0 deletions
45
posthog/temporal/data_imports/pipelines/sql_database/test/test_sql_database.py
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from posthog.temporal.data_imports.pipelines.sql_database import get_column_hints | ||
|
||
|
||
def _setup(return_value): | ||
mock_engine = MagicMock() | ||
mock_engine_enter = MagicMock() | ||
mock_connection = MagicMock() | ||
mock_result = MagicMock() | ||
|
||
mock_engine.configure_mock(**{"connect.return_value": mock_engine_enter}) | ||
mock_engine_enter.configure_mock(**{"__enter__.return_value": mock_connection}) | ||
mock_connection.configure_mock(**{"execute.return_value": mock_result}) | ||
mock_result.configure_mock(**{"fetchall.return_value": return_value}) | ||
|
||
return mock_engine | ||
|
||
|
||
def test_get_column_hints_numeric_no_results(): | ||
mock_engine = _setup([]) | ||
|
||
assert get_column_hints(mock_engine, "some_schema", "some_table") == {} | ||
|
||
|
||
def test_get_column_hints_numeric_with_scale_and_precision(): | ||
mock_engine = _setup([("column", "numeric", 10, 2)]) | ||
|
||
assert get_column_hints(mock_engine, "some_schema", "some_table") == { | ||
"column": {"data_type": "decimal", "precision": 10, "scale": 2} | ||
} | ||
|
||
|
||
def test_get_column_hints_numeric_with_missing_scale_and_precision(): | ||
mock_engine = _setup([("column", "numeric", None, None)]) | ||
|
||
assert get_column_hints(mock_engine, "some_schema", "some_table") == { | ||
"column": {"data_type": "decimal", "precision": 76, "scale": 16} | ||
} | ||
|
||
|
||
def test_get_column_hints_numeric_with_no_numeric(): | ||
mock_engine = _setup([("column", "bigint", None, None)]) | ||
|
||
assert get_column_hints(mock_engine, "some_schema", "some_table") == {} |