Files
gatehouse-api/tests/api/v1/test_superadmin_schemas.py
T

78 lines
2.6 KiB
Python

from gatehouse_app.api.v1.superadmin.organizations import (
ListOrganizationsSchema,
UpdateOrganizationSchema,
)
class TestListOrganizationsSchema:
def test_defaults_when_empty(self):
result = ListOrganizationsSchema.load({})
assert result["page"] == 1
assert result["per_page"] == 20
assert result["search"] is None
assert result["status"] is None
assert result["plan_slug"] is None
def test_normal_pagination(self):
result = ListOrganizationsSchema.load({"page": 3, "per_page": 10})
assert result["page"] == 3
assert result["per_page"] == 10
def test_page_zero_clamped_to_one(self):
result = ListOrganizationsSchema.load({"page": 0})
assert result["page"] == 1
def test_negative_per_page_clamped_to_one(self):
result = ListOrganizationsSchema.load({"per_page": -5})
assert result["per_page"] == 1
def test_per_page_exceeds_max_clamped_to_100(self):
result = ListOrganizationsSchema.load({"per_page": 200})
assert result["per_page"] == 100
def test_non_integer_values_fallback(self):
result = ListOrganizationsSchema.load({"page": "abc", "per_page": "xyz"})
assert result["page"] == 1
assert result["per_page"] == 20
def test_search_passthrough(self):
result = ListOrganizationsSchema.load({"search": "acme"})
assert result["search"] == "acme"
def test_status_passthrough(self):
result = ListOrganizationsSchema.load({"status": "active"})
assert result["status"] == "active"
def test_plan_slug_passthrough(self):
result = ListOrganizationsSchema.load({"plan_slug": "pro"})
assert result["plan_slug"] == "pro"
class TestUpdateOrganizationSchema:
def test_all_fields(self):
result = UpdateOrganizationSchema.load({
"name": "New Name",
"description": "New Description",
"is_active": True,
})
assert result == {
"name": "New Name",
"description": "New Description",
"is_active": True,
}
def test_empty_dict(self):
result = UpdateOrganizationSchema.load({})
assert result == {}
def test_partial_data(self):
result = UpdateOrganizationSchema.load({"name": "Renamed Only"})
assert result == {"name": "Renamed Only"}
def test_is_active_coerced_to_bool(self):
result = UpdateOrganizationSchema.load({"is_active": "truthy"})
assert result["is_active"] is True
result = UpdateOrganizationSchema.load({"is_active": ""})
assert result["is_active"] is False