forked from tortoise/tortoise-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_validators.py
More file actions
54 lines (43 loc) · 2.12 KB
/
test_validators.py
File metadata and controls
54 lines (43 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from decimal import Decimal
from tests.testmodels import ValidatorModel
from tortoise.contrib import test
from tortoise.exceptions import ValidationError
class TestValues(test.TestCase):
async def test_validator_regex(self):
with self.assertRaises(ValidationError):
await ValidatorModel.create(regex="ccc")
await ValidatorModel.create(regex="abcd")
async def test_validator_max_length(self):
with self.assertRaises(ValidationError):
await ValidatorModel.create(max_length="aaaaaa")
await ValidatorModel.create(max_length="aaaaa")
async def test_validator_min_value(self):
# min value is 10
with self.assertRaises(ValidationError):
await ValidatorModel.create(min_value=9)
await ValidatorModel.create(min_value=10)
# min value is Decimal("1.0")
with self.assertRaises(ValidationError):
await ValidatorModel.create(min_value_decimal=Decimal("0.9"))
await ValidatorModel.create(min_value_decimal=Decimal("1.0"))
async def test_validator_max_value(self):
# max value is 20
with self.assertRaises(ValidationError):
await ValidatorModel.create(max_value=21)
await ValidatorModel.create(max_value=20)
# max value is Decimal("2.0")
with self.assertRaises(ValidationError):
await ValidatorModel.create(max_value_decimal=Decimal("3.0"))
await ValidatorModel.create(max_value_decimal=Decimal("2.0"))
async def test_validator_ipv4(self):
with self.assertRaises(ValidationError):
await ValidatorModel.create(ipv4="aaaaaa")
await ValidatorModel.create(ipv4="8.8.8.8")
async def test_validator_ipv6(self):
with self.assertRaises(ValidationError):
await ValidatorModel.create(ipv6="aaaaaa")
await ValidatorModel.create(ipv6="::")
async def test_validator_comma_separated_integer_list(self):
with self.assertRaises(ValidationError):
await ValidatorModel.create(comma_separated_integer_list="aaaaaa")
await ValidatorModel.create(comma_separated_integer_list="1,2,3")