forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_metaclass.py
More file actions
65 lines (47 loc) · 1.72 KB
/
test_metaclass.py
File metadata and controls
65 lines (47 loc) · 1.72 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
59
60
61
62
63
64
65
from piccolo.columns.column_types import ForeignKey
from unittest import TestCase
from piccolo.columns import Secret
from piccolo.table import Table
from ..example_app.tables import Band
class TestMetaClass(TestCase):
def test_tablename(self):
self.assertEqual(Band._meta.tablename, "band")
def test_protected_table_names(self):
"""
Some tablenames are forbidden because they're reserved words in the
database, and can potentially cause issues.
"""
with self.assertRaises(ValueError):
class User(Table):
pass
with self.assertRaises(ValueError):
class MyUser(Table, tablename="user"):
pass
def test_help_text(self):
"""
Make sure help_text can be set for the Table.
"""
help_text = "The manager of a band."
class Manager(Table, help_text=help_text):
pass
self.assertEqual(Manager._meta.help_text, help_text)
def test_foreign_key_columns(self):
"""
Make sure TableMeta.foreign_keys and TableMeta.foreign_key_references
are setup correctly.
"""
class TableA(Table):
pass
class TableB(Table):
table_a = ForeignKey(references=TableA)
self.assertEqual(TableB._meta.foreign_key_columns, [TableB.table_a])
self.assertEqual(TableA._meta.foreign_key_references, [TableB.table_a])
def test_secret_columns(self):
"""
Make sure TableMeta.secret_columns are setup correctly.
"""
class Classified(Table):
top_secret = Secret()
self.assertEqual(
Classified._meta.secret_columns, [Classified.top_secret]
)