forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_boolean.py
More file actions
51 lines (39 loc) · 1.38 KB
/
test_boolean.py
File metadata and controls
51 lines (39 loc) · 1.38 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 unittest import TestCase
from piccolo.columns.column_types import Boolean
from piccolo.table import Table
class MyTable(Table):
boolean = Boolean(boolean=False, null=True)
class TestBoolean(TestCase):
def setUp(self):
MyTable.create_table().run_sync()
def tearDown(self):
MyTable.alter().drop_table().run_sync()
def test_return_type(self):
for value in (True, False, None, ...):
kwargs = {} if value is ... else {"boolean": value}
expected = MyTable.boolean.default if value is ... else value
row = MyTable(**kwargs)
row.save().run_sync()
self.assertEqual(row.boolean, expected)
self.assertEqual(
MyTable.select(MyTable.boolean)
.where(MyTable.id == row.id)
.first()
.run_sync()["boolean"],
expected,
)
def test_eq_and_ne(self):
"""
Make sure the `eq` and `ne` methods works correctly.
"""
MyTable.insert(
MyTable(boolean=True),
MyTable(boolean=False),
MyTable(boolean=True),
).run_sync()
self.assertEqual(
MyTable.count().where(MyTable.boolean.eq(True)).run_sync(), 2
)
self.assertEqual(
MyTable.count().where(MyTable.boolean.ne(True)).run_sync(), 1
)