import pytest from marshmallow.exceptions import ValidationError from atlas_um.api.v2 import schemas class TestPaginatedApiResponseSchema: def test_skip_none(self, faker): res = schemas.PaginatedApiResponseSchema().dump( { "count": faker.pyint(), "limit": faker.pyint(), "items": [], "previous": None, "next": None, } ) assert "previous" not in res assert "next" not in res previous = faker.url() next = faker.url() res = schemas.PaginatedApiResponseSchema().dump( { "count": faker.pyint(), "limit": faker.pyint(), "items": [], "previous": previous, "next": next, } ) assert res.get("previous") == previous assert res.get("next") == next class TestUserStatusParamsSchema: def test_blank_params(self): with pytest.raises(ValidationError) as e_info: schemas.UserStatusParamsSchema().load({}) assert e_info.value.messages == { "_schema": ["Either emails or IDs are required."] } def test_either_not_both_params(self, faker): with pytest.raises(ValidationError) as e_info: schemas.UserStatusParamsSchema().load( {"email": [faker.email()], "id": [faker.pystr()]} ) assert e_info.value.messages == { "_schema": ["Either emails or IDs are required, but not both."] } def test_success_email(self, faker): schemas.UserStatusParamsSchema().load({"email": [faker.email()]}) def test_success_id(self, faker): schemas.UserStatusParamsSchema().load({"id": [faker.pystr()]})