summary refs log tree commit diff
path: root/tests/config/test_validators.py
diff options
context:
space:
mode:
authorDavid Robertson <davidr@element.io>2022-05-19 02:01:02 +0100
committerDavid Robertson <davidr@element.io>2022-05-19 10:29:27 +0100
commit9b9b51be6a77fc96c63dff6d0c20039a1c8b554a (patch)
treefa50d614a3c6e9b752204129195d6d7ed3c5b4dd /tests/config/test_validators.py
parentWIP trying out validators (diff)
downloadsynapse-9b9b51be6a77fc96c63dff6d0c20039a1c8b554a.tar.xz
It seems what I want is `constr`
but this interacts poorly with mypy :(
Diffstat (limited to '')
-rw-r--r--tests/config/test_validators.py52
1 files changed, 0 insertions, 52 deletions
diff --git a/tests/config/test_validators.py b/tests/config/test_validators.py
deleted file mode 100644

index 7b57a13d5e..0000000000 --- a/tests/config/test_validators.py +++ /dev/null
@@ -1,52 +0,0 @@ -from unittest import TestCase - -from pydantic import BaseModel, ValidationError, validator, StrictStr - -from synapse.config.validators import string_length_between, string_contains_characters - - -class TestValidators(TestCase): - def test_string_length_between(self) -> None: - class TestModel(BaseModel): - x: StrictStr - _x_length = validator("x")(string_length_between(5, 10)) - - with self.assertRaises(ValidationError): - TestModel(x="") - with self.assertRaises(ValidationError): - TestModel(x="a" * 4) - - # Should not raise: - TestModel(x="a" * 5) - TestModel(x="a" * 10) - - with self.assertRaises(ValidationError): - TestModel(x="a" * 11) - with self.assertRaises(ValidationError): - TestModel(x="a" * 1000) - - def test_string_contains_characters(self) -> None: - class TestModel(BaseModel): - x: StrictStr - _x_characters = validator("x")(string_contains_characters("A-Z0-9")) - - # Should not raise - TestModel(x="") - TestModel(x="A") - TestModel(x="B") - TestModel(x="Z") - TestModel(x="123456789") - - with self.assertRaises(ValidationError): - TestModel(x="---") - with self.assertRaises(ValidationError): - TestModel(x="$") - with self.assertRaises(ValidationError): - TestModel(x="A$") - with self.assertRaises(ValidationError): - TestModel(x="a") - with self.assertRaises(ValidationError): - TestModel(x="\u0000") - with self.assertRaises(ValidationError): - TestModel(x="☃") -