forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_inheritance.py
More file actions
58 lines (42 loc) · 1.46 KB
/
test_inheritance.py
File metadata and controls
58 lines (42 loc) · 1.46 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
55
56
57
58
import datetime
from unittest import TestCase
from piccolo.columns import Varchar, Timestamp, Boolean
from piccolo.table import Table
class StartedOnMixin(Table):
"""
A mixin which inherits from Table.
"""
started_on = Timestamp()
class FavouriteMixin:
"""
A mixin which deliberately doesn't inherit from Table.
"""
favourite = Boolean()
class Manager(StartedOnMixin, FavouriteMixin, Table):
name = Varchar()
class TestInheritance(TestCase):
"""
Make sure columns can be inheritted from parent classes.
"""
def setUp(self):
Manager.create_table().run_sync()
def tearDown(self):
Manager.alter().drop_table().run_sync()
def test_inheritance(self):
"""
Test that a table created via inheritance works as expected.
"""
# Make sure both columns can be retrieved:
for column_name in ("started_on", "name", "favourite"):
Manager._meta.get_column_by_name(column_name)
# Test saving and retrieving data:
started_on = datetime.datetime(year=1989, month=12, day=1)
name = "Guido"
favourite = True
Manager(
name=name, started_on=started_on, favourite=favourite
).save().run_sync()
response = Manager.select().first().run_sync()
self.assertEqual(response["started_on"], started_on)
self.assertEqual(response["name"], name)
self.assertEqual(response["favourite"], favourite)