You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
from src.database.schema import CommonParams
|
|
from src.overhaul.schema import OverhaulCriticalParts
|
|
|
|
def test_common_params_valid():
|
|
params = CommonParams(
|
|
page=1,
|
|
itemsPerPage=10,
|
|
q="search test",
|
|
all=1
|
|
)
|
|
assert params.page == 1
|
|
assert params.items_per_page == 10
|
|
assert params.query_str == "search test"
|
|
assert params.is_all is True
|
|
|
|
def test_common_params_page_constraints():
|
|
# Test page must be > 0
|
|
with pytest.raises(ValidationError):
|
|
CommonParams(page=0)
|
|
|
|
with pytest.raises(ValidationError):
|
|
CommonParams(page=-1)
|
|
|
|
def test_common_params_items_per_page_constraints():
|
|
# Test items_per_page must be multiple of 5
|
|
with pytest.raises(ValidationError):
|
|
CommonParams(itemsPerPage=7)
|
|
|
|
# Test items_per_page maximum
|
|
with pytest.raises(ValidationError):
|
|
CommonParams(itemsPerPage=55)
|
|
|
|
# Valid multiples of 5
|
|
assert CommonParams(itemsPerPage=50).items_per_page == 50
|
|
assert CommonParams(itemsPerPage=5).items_per_page == 5
|
|
|
|
def test_overhaul_critical_parts_valid():
|
|
parts = OverhaulCriticalParts(criticalParts=["Part A", "Part B"])
|
|
assert parts.criticalParts == ["Part A", "Part B"]
|
|
|
|
def test_overhaul_critical_parts_invalid():
|
|
# criticalParts is required and must be a list
|
|
with pytest.raises(ValidationError):
|
|
OverhaulCriticalParts()
|
|
|
|
with pytest.raises(ValidationError):
|
|
OverhaulCriticalParts(criticalParts="Not a list")
|