This repository was archived by the owner on Oct 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
Expand file tree
/
Copy pathcomponents.py
More file actions
133 lines (96 loc) · 3.82 KB
/
Copy pathcomponents.py
File metadata and controls
133 lines (96 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
from vibora import Vibora, Response, Request
from vibora.tests import TestSuite
class ComponentsTestSuite(TestSuite):
def test_duplicated_component_expects_exception(self):
class Config:
def __init__(self):
self.name = b'test'
app = Vibora()
try:
app.components.add(Config(), Config())
self.fail('ComponentsEngine failed to validate duplicated components.')
except ValueError:
pass
async def test_single_component_in_route(self):
class Config:
def __init__(self):
self.name = b'test'
app = Vibora()
app.components.add(Config())
@app.route('/')
async def home(config: Config):
return Response(config.name)
async with app.test_client() as client:
response = await client.get('/')
self.assertEqual(response.content, app.components[Config].name)
async def test_multiple_components_in_route(self):
class TestComponent:
def __init__(self):
self.name = b'test'
class TestComponent2:
def __init__(self):
self.name = b'test'
app = Vibora()
app.components.add(TestComponent(), TestComponent2())
@app.route('/')
async def home(test: TestComponent, test2: TestComponent2):
return Response(test.name + test2.name)
async with app.test_client() as client:
response = await client.get('/')
self.assertEqual(response.content,
app.components[TestComponent].name +
app.components[TestComponent2].name)
async def test_multiple_components_with_parameters_in_route(self):
class TestComponent:
def __init__(self):
self.name = b'test'
class TestComponent2:
def __init__(self):
self.name = b'test'
app = Vibora()
app.components.add(TestComponent2(), TestComponent())
@app.route('/<name>')
async def home(test: TestComponent, test2: TestComponent2, name: str):
return Response(test.name + test2.name + name.encode())
async with app.test_client() as client:
response = await client.get('/test')
self.assertEqual(
response.content,
app.components[TestComponent].name + app.components[TestComponent2].name + b'test'
)
def test_loaded_component_class_instead_of_instance_expects_exception(self):
class TestComponent:
def __init__(self):
self.name = b'test'
app = Vibora()
try:
app.components.add(TestComponent)
self.fail('Loaded component must not accept class objects.')
except ValueError:
pass
async def test_override_request_expects_successful(self):
class Request2(Request):
@property
def test(self):
return 'test'
app = Vibora()
app.request_class = Request2
@app.route('/')
async def home(request: Request2):
return Response(request.test.encode())
async with app.test_client() as client:
response = await client.get('/')
self.assertEqual(response.content, b'test')
async def test_override_request_try_parent_one(self):
class Request2(Request):
@property
def test(self):
return 'test'
app = Vibora()
app.request_class = Request2
@app.route('/')
async def home(request: Request):
return Response(request.url)
async with app.test_client() as client:
response = await client.get('/')
self.assertEqual(response.content, b'/')