-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_0010_component_registry.py
More file actions
150 lines (113 loc) · 3.82 KB
/
test_0010_component_registry.py
File metadata and controls
150 lines (113 loc) · 3.82 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
def test_component_registry():
from falk.component_registry import get_component_id, register_component
from falk.apps import get_default_app
def Component1(template_context):
pass
def Component2(template_context):
pass
def Component3(
template_context,
Component1=Component1,
Component2=Component2,
):
pass
mutable_app = get_default_app()
# the component registry should be empty at start
assert len(mutable_app["components"]) == 0
# component ids need to be unique but reproducible
get_component_id(
Component1,
mutable_app,
) == get_component_id(
Component1,
mutable_app,
)
get_component_id(
Component2,
mutable_app,
) == get_component_id(
Component2,
mutable_app,
)
get_component_id(
Component3,
mutable_app,
) == get_component_id(
Component3,
mutable_app,
)
component_id_1 = get_component_id(Component1, mutable_app)
component_id_2 = get_component_id(Component2, mutable_app)
component_id_3 = get_component_id(Component3, mutable_app)
assert len(set([component_id_1, component_id_2, component_id_3])) == 3
# components without dependencies
mutable_app["components"].clear()
register_component(Component1, mutable_app)
assert len(mutable_app["components"].keys()) == 2
assert Component1 in mutable_app["components"].values()
assert Component2 not in mutable_app["components"].values()
assert Component3 not in mutable_app["components"].values()
mutable_app["components"].clear()
register_component(Component2, mutable_app)
assert len(mutable_app["components"].keys()) == 2
assert Component1 not in mutable_app["components"].values()
assert Component2 in mutable_app["components"].values()
assert Component3 not in mutable_app["components"].values()
# components with dependencies
mutable_app["components"].clear()
register_component(Component3, mutable_app)
assert len(mutable_app["components"].keys()) == 6
assert Component1 in mutable_app["components"].values()
assert Component2 in mutable_app["components"].values()
assert Component3 in mutable_app["components"].values()
def test_component_id_collisions():
from falk.component_registry import get_component_id
from falk.apps import get_default_app
app = get_default_app()
def get_component_1():
def foo():
return ""
return foo
def get_component_2():
def foo():
return ""
return foo
component_1_id = get_component_id(get_component_1(), app)
component_2_id = get_component_id(get_component_2(), app)
assert component_1_id != component_2_id
def test_file_upload_handler_dependencies():
from falk.component_registry import (
get_file_upload_handler,
register_component,
get_component_id,
)
from falk.apps import get_default_app
mutable_app = get_default_app()
def handle_file_upload():
pass
def Component1(handle_file_upload=handle_file_upload):
pass
def Component2():
pass
register_component(
component=Component1,
mutable_app=mutable_app,
)
register_component(
component=Component2,
mutable_app=mutable_app,
)
assert get_file_upload_handler(
component_id=get_component_id(
component=Component1,
mutable_app=mutable_app,
),
mutable_app=mutable_app,
) is handle_file_upload
assert get_file_upload_handler(
component_id=get_component_id(
component=Component2,
mutable_app=mutable_app,
),
mutable_app=mutable_app,
) is mutable_app["settings"]["default_file_upload_handler"]