186 lines
5.6 KiB
Python
Executable File
186 lines
5.6 KiB
Python
Executable File
"""
|
|
Unit tests for data models
|
|
"""
|
|
import pytest
|
|
from drt.models.enums import Status, CheckType
|
|
from drt.models.table import TableInfo, ColumnInfo
|
|
from drt.models.results import CheckResult, ComparisonResult
|
|
|
|
|
|
class TestStatus:
|
|
"""Test Status enum"""
|
|
|
|
def test_status_values(self):
|
|
"""Test status enum values"""
|
|
assert Status.PASS.value == "PASS"
|
|
assert Status.FAIL.value == "FAIL"
|
|
assert Status.WARNING.value == "WARNING"
|
|
assert Status.ERROR.value == "ERROR"
|
|
assert Status.INFO.value == "INFO"
|
|
assert Status.SKIP.value == "SKIP"
|
|
|
|
def test_status_severity(self):
|
|
"""Test status severity comparison"""
|
|
assert Status.FAIL.severity > Status.WARNING.severity
|
|
assert Status.WARNING.severity > Status.PASS.severity
|
|
assert Status.ERROR.severity > Status.FAIL.severity
|
|
|
|
|
|
class TestCheckType:
|
|
"""Test CheckType enum"""
|
|
|
|
def test_check_type_values(self):
|
|
"""Test check type enum values"""
|
|
assert CheckType.TABLE_EXISTENCE.value == "TABLE_EXISTENCE"
|
|
assert CheckType.ROW_COUNT.value == "ROW_COUNT"
|
|
assert CheckType.SCHEMA.value == "SCHEMA"
|
|
assert CheckType.AGGREGATE.value == "AGGREGATE"
|
|
|
|
|
|
class TestTableInfo:
|
|
"""Test TableInfo model"""
|
|
|
|
def test_table_info_creation(self):
|
|
"""Test creating a TableInfo instance"""
|
|
table = TableInfo(
|
|
schema="dbo",
|
|
name="TestTable",
|
|
enabled=True,
|
|
expected_in_target=True
|
|
)
|
|
assert table.schema == "dbo"
|
|
assert table.name == "TestTable"
|
|
assert table.enabled is True
|
|
assert table.expected_in_target is True
|
|
assert table.aggregate_columns == []
|
|
|
|
def test_table_info_with_aggregates(self):
|
|
"""Test TableInfo with aggregate columns"""
|
|
table = TableInfo(
|
|
schema="dbo",
|
|
name="FactSales",
|
|
enabled=True,
|
|
expected_in_target=True,
|
|
aggregate_columns=["Amount", "Quantity"]
|
|
)
|
|
assert len(table.aggregate_columns) == 2
|
|
assert "Amount" in table.aggregate_columns
|
|
|
|
|
|
class TestColumnInfo:
|
|
"""Test ColumnInfo model"""
|
|
|
|
def test_column_info_creation(self):
|
|
"""Test creating a ColumnInfo instance"""
|
|
column = ColumnInfo(
|
|
name="CustomerID",
|
|
data_type="int",
|
|
is_nullable=False,
|
|
is_primary_key=True
|
|
)
|
|
assert column.name == "CustomerID"
|
|
assert column.data_type == "int"
|
|
assert column.is_nullable is False
|
|
assert column.is_primary_key is True
|
|
|
|
|
|
class TestCheckResult:
|
|
"""Test CheckResult model"""
|
|
|
|
def test_check_result_pass(self):
|
|
"""Test creating a passing check result"""
|
|
result = CheckResult(
|
|
check_type=CheckType.ROW_COUNT,
|
|
status=Status.PASS,
|
|
message="Row counts match",
|
|
baseline_value=1000,
|
|
target_value=1000
|
|
)
|
|
assert result.status == Status.PASS
|
|
assert result.baseline_value == 1000
|
|
assert result.target_value == 1000
|
|
|
|
def test_check_result_fail(self):
|
|
"""Test creating a failing check result"""
|
|
result = CheckResult(
|
|
check_type=CheckType.ROW_COUNT,
|
|
status=Status.FAIL,
|
|
message="Row count mismatch",
|
|
baseline_value=1000,
|
|
target_value=950
|
|
)
|
|
assert result.status == Status.FAIL
|
|
assert result.baseline_value != result.target_value
|
|
|
|
|
|
class TestComparisonResult:
|
|
"""Test ComparisonResult model"""
|
|
|
|
def test_comparison_result_creation(self):
|
|
"""Test creating a ComparisonResult instance"""
|
|
result = ComparisonResult(
|
|
schema="dbo",
|
|
table="TestTable"
|
|
)
|
|
assert result.schema == "dbo"
|
|
assert result.table == "TestTable"
|
|
assert len(result.checks) == 0
|
|
|
|
def test_add_check_result(self):
|
|
"""Test adding check results"""
|
|
comparison = ComparisonResult(
|
|
schema="dbo",
|
|
table="TestTable"
|
|
)
|
|
|
|
check = CheckResult(
|
|
check_type=CheckType.ROW_COUNT,
|
|
status=Status.PASS,
|
|
message="Row counts match"
|
|
)
|
|
|
|
comparison.checks.append(check)
|
|
assert len(comparison.checks) == 1
|
|
assert comparison.checks[0].status == Status.PASS
|
|
|
|
def test_overall_status_all_pass(self):
|
|
"""Test overall status when all checks pass"""
|
|
comparison = ComparisonResult(
|
|
schema="dbo",
|
|
table="TestTable"
|
|
)
|
|
|
|
comparison.checks.append(CheckResult(
|
|
check_type=CheckType.TABLE_EXISTENCE,
|
|
status=Status.PASS,
|
|
message="Table exists"
|
|
))
|
|
|
|
comparison.checks.append(CheckResult(
|
|
check_type=CheckType.ROW_COUNT,
|
|
status=Status.PASS,
|
|
message="Row counts match"
|
|
))
|
|
|
|
assert comparison.overall_status == Status.PASS
|
|
|
|
def test_overall_status_with_failure(self):
|
|
"""Test overall status when one check fails"""
|
|
comparison = ComparisonResult(
|
|
schema="dbo",
|
|
table="TestTable"
|
|
)
|
|
|
|
comparison.checks.append(CheckResult(
|
|
check_type=CheckType.TABLE_EXISTENCE,
|
|
status=Status.PASS,
|
|
message="Table exists"
|
|
))
|
|
|
|
comparison.checks.append(CheckResult(
|
|
check_type=CheckType.ROW_COUNT,
|
|
status=Status.FAIL,
|
|
message="Row count mismatch"
|
|
))
|
|
|
|
assert comparison.overall_status == Status.FAIL |