fix(dwh): validate adapter limits strictly
This commit is contained in:
@@ -11,6 +11,22 @@ from tht.db.sampling import distinct_values, is_text_type, sample_column, unique
|
||||
pytestmark = [pytest.mark.l0]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid_limit", [True, 1.5, 0, -1])
|
||||
def test_direct_sampling_rejects_non_positive_integer_limits(admin_engine, invalid_limit):
|
||||
with pytest.raises(ValueError, match="positive integer"):
|
||||
sample_column(
|
||||
admin_engine, "dw", "fct_ricoveri", "reparto", limit=invalid_limit
|
||||
)
|
||||
with pytest.raises(ValueError, match="positive integer"):
|
||||
distinct_values(
|
||||
admin_engine,
|
||||
"dw",
|
||||
"fct_ricoveri",
|
||||
"reparto",
|
||||
max_values=invalid_limit,
|
||||
)
|
||||
|
||||
|
||||
def test_is_text_type():
|
||||
assert is_text_type("text")
|
||||
assert is_text_type("varchar(100)")
|
||||
|
||||
@@ -2,6 +2,7 @@ import pytest
|
||||
from sqlalchemy.exc import OperationalError
|
||||
|
||||
from tht.config import DatabaseConfig, RestConfig
|
||||
from tht.db.sampling import distinct_values_rest, sample_column_rest
|
||||
from tht.execute import ExecutionError
|
||||
from tht.ports import DistinctValues, DwhAdapter
|
||||
from tht.rest.client import RestError
|
||||
@@ -45,12 +46,31 @@ def test_adapter_satisfies_dwh_protocol(factory):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("factory", [postgres_factory, rest_factory])
|
||||
def test_run_query_requires_explicit_positive_limit(factory):
|
||||
@pytest.mark.parametrize("invalid_limit", [True, 1.5, 0, -1])
|
||||
def test_run_query_rejects_non_positive_integer_limit(factory, invalid_limit):
|
||||
adapter = factory()
|
||||
with pytest.raises(ValueError, match="positive integer"):
|
||||
adapter.run_query("select 1", limit=invalid_limit)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("factory", [postgres_factory, rest_factory])
|
||||
def test_run_query_requires_explicit_limit(factory):
|
||||
with pytest.raises(TypeError):
|
||||
adapter.run_query("select 1")
|
||||
with pytest.raises(ValueError, match="positive"):
|
||||
adapter.run_query("select 1", limit=0)
|
||||
factory().run_query("select 1")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid_limit", [True, 1.5, 0, -1])
|
||||
def test_rest_sampling_rejects_non_positive_integer_limit(invalid_limit):
|
||||
class Client:
|
||||
def top_values(self, *args):
|
||||
raise AssertionError("transport must not be used")
|
||||
|
||||
with pytest.raises(ValueError, match="positive integer"):
|
||||
sample_column_rest(Client(), "dw", "sales", "region", limit=invalid_limit)
|
||||
with pytest.raises(ValueError, match="positive integer"):
|
||||
distinct_values_rest(
|
||||
Client(), "dw", "sales", "region", max_values=invalid_limit
|
||||
)
|
||||
|
||||
|
||||
def test_postgres_sampling_delegates_to_paired_sampling_functions(monkeypatch):
|
||||
@@ -101,8 +121,6 @@ def test_rest_sampling_delegates_and_translates_transport_errors(monkeypatch):
|
||||
|
||||
|
||||
def test_rest_distinct_values_reports_transport_truncation():
|
||||
from tht.db.sampling import distinct_values_rest
|
||||
|
||||
class Client:
|
||||
def top_values(self, schema, table, column, limit):
|
||||
assert (schema, table, column, limit) == ("dw", "sales", "region", 3)
|
||||
|
||||
Reference in New Issue
Block a user