forked from tortoise/tortoise-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bool.py
More file actions
35 lines (29 loc) · 1.42 KB
/
test_bool.py
File metadata and controls
35 lines (29 loc) · 1.42 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
from tests import testmodels
from tortoise.contrib import test
from tortoise.exceptions import IntegrityError
class TestBooleanFields(test.TestCase):
async def test_empty(self):
with self.assertRaises(IntegrityError):
await testmodels.BooleanFields.create()
async def test_create(self):
obj0 = await testmodels.BooleanFields.create(boolean=True)
obj = await testmodels.BooleanFields.get(id=obj0.id)
self.assertIs(obj.boolean, True)
self.assertIs(obj.boolean_null, None)
await obj.save()
obj2 = await testmodels.BooleanFields.get(id=obj.id)
self.assertEqual(obj, obj2)
async def test_update(self):
obj0 = await testmodels.BooleanFields.create(boolean=False)
await testmodels.BooleanFields.filter(id=obj0.id).update(boolean=False)
obj = await testmodels.BooleanFields.get(id=obj0.id)
self.assertIs(obj.boolean, False)
self.assertIs(obj.boolean_null, None)
async def test_values(self):
obj0 = await testmodels.BooleanFields.create(boolean=True)
values = await testmodels.BooleanFields.get(id=obj0.id).values("boolean")
self.assertIs(values["boolean"], True)
async def test_values_list(self):
obj0 = await testmodels.BooleanFields.create(boolean=True)
values = await testmodels.BooleanFields.get(id=obj0.id).values_list("boolean", flat=True)
self.assertIs(values, True)