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.
121 lines
3.5 KiB
Python
121 lines
3.5 KiB
Python
import pytest
|
|
from pydantic import ValidationError
|
|
from src.database.schema import CommonParams
|
|
|
|
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_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_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_query_str_max_length():
|
|
# Test query_str max length (100)
|
|
long_str = "a" * 101
|
|
with pytest.raises(ValidationError):
|
|
CommonParams(q=long_str)
|
|
|
|
def test_common_params_filter_spec_max_length():
|
|
# Test filter_spec max length (500)
|
|
long_filter = "a" * 501
|
|
with pytest.raises(ValidationError):
|
|
CommonParams(filter=long_filter)
|
|
|
|
from src.aeros_equipment.schema import EquipmentConfiguration, FlowrateUnit, UnitCode
|
|
|
|
def test_equipment_configuration_valid():
|
|
config = EquipmentConfiguration(
|
|
equipmentName="Pump A",
|
|
maxFlowrate=100.0,
|
|
designFlowrate=80.0,
|
|
flowrateUnit=FlowrateUnit.PER_HOUR,
|
|
relDisType="Weibull",
|
|
relDisP1=1.0,
|
|
relDisP2=2.0,
|
|
relDisP3=0.0,
|
|
relDisUnitCode=UnitCode.U_HOUR,
|
|
cmDisType="Normal",
|
|
cmDisP1=6.0,
|
|
cmDisP2=3.0,
|
|
cmDisP3=0.0,
|
|
cmDisUnitCode=UnitCode.U_HOUR,
|
|
ipDisType="Fixed",
|
|
ipDisP1=0.0,
|
|
ipDisP2=0.0,
|
|
ipDisP3=0.0,
|
|
ipDisUnitCode=UnitCode.U_HOUR,
|
|
pmDisType="Fixed",
|
|
pmDisP1=0.0,
|
|
pmDisP2=0.0,
|
|
pmDisP3=0.0,
|
|
pmDisUnitCode=UnitCode.U_HOUR,
|
|
ohDisType="Fixed",
|
|
ohDisP1=0.0,
|
|
ohDisP2=0.0,
|
|
ohDisP3=0.0,
|
|
ohDisUnitCode=UnitCode.U_HOUR
|
|
)
|
|
assert config.equipment_name == "Pump A"
|
|
assert config.max_flowrate == 100.0
|
|
|
|
def test_equipment_configuration_invalid_flowrate():
|
|
# maxFlowrate cannot be negative
|
|
with pytest.raises(ValidationError):
|
|
EquipmentConfiguration(
|
|
equipmentName="Pump A",
|
|
maxFlowrate=-1.0,
|
|
designFlowrate=80.0,
|
|
flowrateUnit=FlowrateUnit.PER_HOUR,
|
|
relDisType="Weibull",
|
|
relDisP1=1.0,
|
|
relDisP2=2.0,
|
|
relDisP3=0.0,
|
|
relDisUnitCode=UnitCode.U_HOUR,
|
|
cmDisType="Normal",
|
|
cmDisP1=6.0,
|
|
cmDisP2=3.0,
|
|
cmDisP3=0.0,
|
|
cmDisUnitCode=UnitCode.U_HOUR,
|
|
ipDisType="Fixed",
|
|
ipDisP1=0.0,
|
|
ipDisP2=0.0,
|
|
ipDisP3=0.0,
|
|
ipDisUnitCode=UnitCode.U_HOUR,
|
|
pmDisType="Fixed",
|
|
pmDisP1=0.0,
|
|
pmDisP2=0.0,
|
|
pmDisP3=0.0,
|
|
pmDisUnitCode=UnitCode.U_HOUR,
|
|
ohDisType="Fixed",
|
|
ohDisP1=0.0,
|
|
ohDisP2=0.0,
|
|
ohDisP3=0.0,
|
|
ohDisUnitCode=UnitCode.U_HOUR
|
|
)
|