forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_apps.py
More file actions
133 lines (108 loc) · 3.89 KB
/
test_apps.py
File metadata and controls
133 lines (108 loc) · 3.89 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from unittest import TestCase
from piccolo.apps.user.tables import BaseUser
from piccolo.conf.apps import AppRegistry, AppConfig, table_finder
from ..example_app.tables import Manager
class TestAppRegistry(TestCase):
def test_get_app_config(self):
app_registry = AppRegistry(apps=["piccolo.apps.user.piccolo_app"])
app_config = app_registry.get_app_config(app_name="user")
self.assertTrue(isinstance(app_config, AppConfig))
def test_get_table_classes(self):
app_registry = AppRegistry(apps=["piccolo.apps.user.piccolo_app"])
table_classes = app_registry.get_table_classes(app_name="user")
self.assertTrue(BaseUser in table_classes)
with self.assertRaises(ValueError):
app_registry.get_table_classes(app_name="Foo")
def test_duplicate_app_names(self):
"""
An exception should be if apps with duplicate names are registered.
"""
with self.assertRaises(ValueError):
AppRegistry(
apps=[
"piccolo.apps.user.piccolo_app",
"piccolo.apps.user.piccolo_app",
]
)
def test_get_table_with_name(self):
app_registry = AppRegistry(apps=["piccolo.apps.user.piccolo_app"])
table = app_registry.get_table_with_name(
app_name="user", table_class_name="BaseUser"
)
self.assertEqual(table, BaseUser)
class TestAppConfig(TestCase):
def test_get_table_with_name(self):
"""
Register a table, then test retrieving it.
"""
config = AppConfig(app_name="Music", migrations_folder_path="")
config.register_table(table_class=Manager)
self.assertEqual(config.get_table_with_name("Manager"), Manager)
with self.assertRaises(ValueError):
config.get_table_with_name("Foo")
class TestTableFinder(TestCase):
def test_table_finder(self):
"""
Should return all Table subclasses.
"""
tables = table_finder(modules=["tests.example_app.tables"])
table_class_names = [i.__name__ for i in tables]
table_class_names.sort()
self.assertEqual(
table_class_names,
[
"Band",
"Concert",
"Manager",
"Poster",
"Shirt",
"Ticket",
"Venue",
],
)
with self.assertRaises(ImportError):
table_finder(modules=["foo.bar.baz"])
def test_table_finder_coercion(self):
"""
Should convert a string argument to a list.
"""
tables = table_finder(modules="tests.example_app.tables")
table_class_names = [i.__name__ for i in tables]
table_class_names.sort()
self.assertEqual(
table_class_names,
[
"Band",
"Concert",
"Manager",
"Poster",
"Shirt",
"Ticket",
"Venue",
],
)
def test_include_tags(self):
"""
Should return all Table subclasses with a matching tag.
"""
tables = table_finder(
modules=["tests.example_app.tables"], include_tags=["special"]
)
table_class_names = [i.__name__ for i in tables]
table_class_names.sort()
self.assertEqual(
table_class_names, ["Poster"],
)
def test_exclude_tags(self):
"""
Should return all Table subclasses without the specified tags.
"""
tables = table_finder(
modules=["tests.example_app.tables"], exclude_tags=["special"]
)
table_class_names = [i.__name__ for i in tables]
table_class_names.sort()
self.assertEqual(
table_class_names,
["Band", "Concert", "Manager", "Shirt", "Ticket", "Venue"],
)