181 lines
5.6 KiB
Python
181 lines
5.6 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from api.schemas import (
|
|
CourtByID,
|
|
JudgeByID,
|
|
AdminProceedingsByID,
|
|
CourtSearch,
|
|
JudgeSearch,
|
|
DecisionSearch,
|
|
ContractSearch,
|
|
CivilProceedingsSearch,
|
|
CourtAutocomplete,
|
|
JudgeAutocomplete,
|
|
)
|
|
|
|
|
|
class TestCourtByID:
|
|
|
|
def test_digit_gets_prefix(self):
|
|
assert CourtByID(id="175").id == "sud_175"
|
|
|
|
def test_already_prefixed_unchanged(self):
|
|
assert CourtByID(id="sud_175").id == "sud_175"
|
|
|
|
def test_strips_whitespace(self):
|
|
assert CourtByID(id=" 42 ").id == "sud_42"
|
|
|
|
def test_single_digit(self):
|
|
assert CourtByID(id="1").id == "sud_1"
|
|
|
|
def test_large_number(self):
|
|
assert CourtByID(id="9999").id == "sud_9999"
|
|
|
|
def test_non_numeric_string_unchanged(self):
|
|
assert CourtByID(id="some_string").id == "some_string"
|
|
|
|
def test_whitespace_digit_combination(self):
|
|
assert CourtByID(id=" 7 ").id == "sud_7"
|
|
|
|
|
|
class TestJudgeByID:
|
|
|
|
def test_digit_gets_prefix(self):
|
|
assert JudgeByID(id="1").id == "sudca_1"
|
|
|
|
def test_already_prefixed_unchanged(self):
|
|
assert JudgeByID(id="sudca_99").id == "sudca_99"
|
|
|
|
def test_strips_whitespace(self):
|
|
assert JudgeByID(id=" 7 ").id == "sudca_7"
|
|
|
|
def test_large_number(self):
|
|
assert JudgeByID(id="12345").id == "sudca_12345"
|
|
|
|
def test_non_numeric_string_unchanged(self):
|
|
assert JudgeByID(id="sudca_abc").id == "sudca_abc"
|
|
|
|
|
|
class TestAdminProceedingsByID:
|
|
|
|
def test_digit_gets_prefix(self):
|
|
assert AdminProceedingsByID(id="103").id == "spravneKonanie_103"
|
|
|
|
def test_already_prefixed_unchanged(self):
|
|
assert AdminProceedingsByID(id="spravneKonanie_103").id == "spravneKonanie_103"
|
|
|
|
def test_strips_whitespace(self):
|
|
assert AdminProceedingsByID(id=" 55 ").id == "spravneKonanie_55"
|
|
|
|
def test_single_digit(self):
|
|
assert AdminProceedingsByID(id="5").id == "spravneKonanie_5"
|
|
|
|
def test_non_numeric_string_unchanged(self):
|
|
assert AdminProceedingsByID(id="custom_id").id == "custom_id"
|
|
|
|
|
|
class TestPaginationDefaults:
|
|
|
|
def test_court_search_defaults_are_none(self):
|
|
obj = CourtSearch()
|
|
assert obj.page is None
|
|
assert obj.size is None
|
|
|
|
def test_sort_direction_default_asc(self):
|
|
assert CourtSearch().sortDirection == "ASC"
|
|
|
|
def test_sort_direction_desc_accepted(self):
|
|
assert CourtSearch(sortDirection="DESC").sortDirection == "DESC"
|
|
|
|
def test_sort_direction_invalid_rejected(self):
|
|
with pytest.raises(ValidationError):
|
|
CourtSearch(sortDirection="INVALID")
|
|
|
|
def test_page_cannot_be_negative(self):
|
|
with pytest.raises(ValidationError):
|
|
CourtSearch(page=-1)
|
|
|
|
def test_size_cannot_be_zero(self):
|
|
with pytest.raises(ValidationError):
|
|
CourtSearch(size=0)
|
|
|
|
def test_size_one_accepted(self):
|
|
assert CourtSearch(size=1).size == 1
|
|
|
|
def test_page_zero_accepted(self):
|
|
assert CourtSearch(page=0).page == 0
|
|
|
|
|
|
class TestFacetFilters:
|
|
|
|
def test_court_search_facet_type_list(self):
|
|
obj = CourtSearch(typSuduFacetFilter=["Okresný súd", "Krajský súd"])
|
|
assert len(obj.typSuduFacetFilter) == 2
|
|
|
|
def test_judge_search_facet_kraj(self):
|
|
obj = JudgeSearch(krajFacetFilter=["Bratislavský kraj"])
|
|
assert obj.krajFacetFilter == ["Bratislavský kraj"]
|
|
|
|
def test_decision_search_forma_filter(self):
|
|
obj = DecisionSearch(formaRozhodnutiaFacetFilter=["Rozsudok"])
|
|
assert "Rozsudok" in obj.formaRozhodnutiaFacetFilter
|
|
|
|
def test_contract_search_typ_dokumentu(self):
|
|
obj = ContractSearch(typDokumentuFacetFilter=["ZMLUVA", "DODATOK"])
|
|
assert len(obj.typDokumentuFacetFilter) == 2
|
|
|
|
def test_civil_proceedings_usek_filter(self):
|
|
obj = CivilProceedingsSearch(usekFacetFilter=["C", "O"])
|
|
assert "C" in obj.usekFacetFilter
|
|
|
|
|
|
class TestAutocomplete:
|
|
|
|
def test_court_autocomplete_limit_min_one(self):
|
|
with pytest.raises(ValidationError):
|
|
CourtAutocomplete(limit=0)
|
|
|
|
def test_court_autocomplete_limit_valid(self):
|
|
assert CourtAutocomplete(limit=5).limit == 5
|
|
|
|
def test_judge_autocomplete_guid_sud(self):
|
|
obj = JudgeAutocomplete(guidSud="sud_100", limit=10)
|
|
assert obj.guidSud == "sud_100"
|
|
|
|
def test_autocomplete_empty_query_accepted(self):
|
|
assert CourtAutocomplete().query is None
|
|
|
|
def test_autocomplete_query_string(self):
|
|
assert JudgeAutocomplete(query="Novák").query == "Novák"
|
|
|
|
|
|
class TestModelDumpExcludeNone:
|
|
|
|
def test_excludes_none_fields(self):
|
|
dumped = CourtSearch(query="Bratislava").model_dump(exclude_none=True)
|
|
assert "query" in dumped
|
|
assert "page" not in dumped
|
|
assert "size" not in dumped
|
|
|
|
def test_full_params_included(self):
|
|
dumped = JudgeSearch(query="Novák", page=0, size=20).model_dump(exclude_none=True)
|
|
assert dumped["query"] == "Novák"
|
|
assert dumped["page"] == 0
|
|
assert dumped["size"] == 20
|
|
|
|
def test_empty_schema_dumps_empty_dict(self):
|
|
assert CourtSearch().model_dump(exclude_none=True) == {}
|
|
|
|
def test_empty_schema_excludes_none_fields_only(self):
|
|
dumped = CourtSearch().model_dump(exclude_none=True)
|
|
# sortDirection='ASC' is a real default, not None — correctly kept
|
|
assert dumped.get("sortDirection") == "ASC"
|
|
# None fields are excluded
|
|
assert "page" not in dumped
|
|
assert "size" not in dumped
|
|
assert "query" not in dumped
|
|
|
|
def test_empty_schema_exclude_defaults(self):
|
|
dumped = CourtSearch().model_dump(exclude_defaults=True)
|
|
assert dumped == {} |