forked from tortoise/tortoise-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_char.py
More file actions
51 lines (42 loc) · 1.99 KB
/
test_char.py
File metadata and controls
51 lines (42 loc) · 1.99 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
from tests import testmodels
from tortoise import fields
from tortoise.contrib import test
from tortoise.exceptions import ConfigurationError, ValidationError
class TestCharFields(test.TestCase):
def test_max_length_missing(self):
with self.assertRaisesRegex(
TypeError, "missing 1 required positional argument: 'max_length'"
):
fields.CharField() # pylint: disable=E1120
def test_max_length_bad(self):
with self.assertRaisesRegex(ConfigurationError, "'max_length' must be >= 1"):
fields.CharField(max_length=0)
async def test_empty(self):
with self.assertRaises(ValidationError):
await testmodels.CharFields.create()
async def test_create(self):
obj0 = await testmodels.CharFields.create(char="moo")
obj = await testmodels.CharFields.get(id=obj0.id)
self.assertEqual(obj.char, "moo")
self.assertEqual(obj.char_null, None)
await obj.save()
obj2 = await testmodels.CharFields.get(id=obj.id)
self.assertEqual(obj, obj2)
async def test_update(self):
obj0 = await testmodels.CharFields.create(char="moo")
await testmodels.CharFields.filter(id=obj0.id).update(char="ba'a")
obj = await testmodels.CharFields.get(id=obj0.id)
self.assertEqual(obj.char, "ba'a")
self.assertEqual(obj.char_null, None)
async def test_cast(self):
obj0 = await testmodels.CharFields.create(char=33)
obj = await testmodels.CharFields.get(id=obj0.id)
self.assertEqual(obj.char, "33")
async def test_values(self):
obj0 = await testmodels.CharFields.create(char="moo")
values = await testmodels.CharFields.get(id=obj0.id).values("char")
self.assertEqual(values["char"], "moo")
async def test_values_list(self):
obj0 = await testmodels.CharFields.create(char="moo")
values = await testmodels.CharFields.get(id=obj0.id).values_list("char", flat=True)
self.assertEqual(values, "moo")