-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_controller.py
More file actions
103 lines (83 loc) · 2.63 KB
/
Copy pathtest_controller.py
File metadata and controls
103 lines (83 loc) · 2.63 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
import pytest
from ellar.common import Controller, ControllerBase, UseGuards, Version, set_metadata
from ellar.common.constants import CONTROLLER_METADATA, GUARDS_KEY, VERSIONING_KEY
from ellar.common.exceptions import ImproperConfiguration
from ellar.reflect import reflect
@set_metadata("OtherAttributes", "Something")
@Controller(
prefix="/decorator",
name="test",
)
@Version("v1")
@UseGuards()
class ControllerDecorationTest:
pass
@Controller
class ControllerDefaultTest:
pass
@Controller
@set_metadata("OtherAttributes", "Something")
class ControllerWithSetMetadata:
pass
@Controller
@set_metadata("OtherAttributes", "Something")
class ControllerWithSetMetadataAndControllerBase(ControllerBase):
pass
def test_controller_decoration_default():
assert (
reflect.get_metadata(CONTROLLER_METADATA.NAME, ControllerDefaultTest)
== "defaulttest"
)
assert reflect.get_metadata(GUARDS_KEY, ControllerDefaultTest) is None
assert reflect.get_metadata(VERSIONING_KEY, ControllerDefaultTest) is None
assert (
reflect.get_metadata(CONTROLLER_METADATA.PATH, ControllerDefaultTest)
== "/defaulttest"
)
assert (
reflect.get_metadata(
CONTROLLER_METADATA.INCLUDE_IN_SCHEMA, ControllerDefaultTest
)
is True
)
def test_controller_decoration_test():
assert (
reflect.get_metadata(CONTROLLER_METADATA.NAME, ControllerDecorationTest)
== "test"
)
assert reflect.get_metadata(GUARDS_KEY, ControllerDecorationTest) == []
assert reflect.get_metadata(VERSIONING_KEY, ControllerDecorationTest) == {
"v1",
}
assert (
reflect.get_metadata(CONTROLLER_METADATA.PATH, ControllerDecorationTest)
== "/decorator"
)
assert (
reflect.get_metadata(
CONTROLLER_METADATA.INCLUDE_IN_SCHEMA, ControllerDecorationTest
)
is True
)
assert (
reflect.get_metadata("OtherAttributes", ControllerDecorationTest) == "Something"
)
def test_controller_set_metadata_decorator_works():
assert (
reflect.get_metadata("OtherAttributes", ControllerWithSetMetadata)
== "Something"
)
assert (
reflect.get_metadata(
"OtherAttributes", ControllerWithSetMetadataAndControllerBase
)
== "Something"
)
def test_controller_decorator_fails_as_a_function_decorator():
def controller_function():
pass # pragma: no cover
with pytest.raises(
ImproperConfiguration,
match=f"Controller is a class decorator - {controller_function}",
):
Controller("/some-prefix")(controller_function)