"""Test model validation.""" import pytest from sukimu import exceptions from auth.models import validators def test_enum_validator(): """Test the enum validator.""" values = (1, 2, 3) validate = validators.enum(*values) # Check the exception is thrown when a value is not part of the enum. with pytest.raises(exceptions.FieldException): validate(10) for value in values: assert validate(value) == value def test_only_contains(): """Test the contains validator.""" values = (1, 2, 3) validate = validators.only_contains(*values) with pytest.raises(exceptions.FieldException): validate([1, 2, 4]) for value in values: assert validate([value]) == [value]