-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_thermal_characteristics.py
220 lines (172 loc) · 10.5 KB
/
test_thermal_characteristics.py
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import pytest
from httpx import AsyncClient
from main import app
@pytest.mark.asyncio(scope='session')
async def test_thermal_characteristics_heating_types_before_rows_average_metric():
# Create a object containing the options the route expects.
options_object = [{"filter": "heating_type", "rows": "before", "metric": "average"}]
# Get the values from the options object.
filter = options_object[0]["filter"]
rows = options_object[0]["rows"]
metric = options_object[0]["metric"]
async with AsyncClient(app=app, base_url="http://localhost") as client:
response = await client.post("/api/Thermal_characteristics", json=options_object)
# Check if the response is 200. Indicating the request was successful.
assert response.status_code == 200
json = response.json()
# Check if the key exists in the json object. If it does not the response is malformed.
key = f'{filter}:{rows}'
assert key in json
expected_mean_values = [15765.225677120825, 22203.95709521921, 6290.303308937876, 15612.598575890848]
# Loop over each array in the json object under the 'metric' key checking if each value matches the
# respective 'correct' value the route should have returned.
for i in range(len(json[key][metric])):
assert abs(json[key][metric][i][1] - expected_mean_values[i]) < 0.1
@pytest.mark.asyncio(scope='session')
async def test_thermal_characteristics_heating_types_before_rows_sum_metric():
# Create a object containing the options the route expects.
options_object = [{"filter": "heating_type", "rows": "before", "metric": "sum"}]
# Get the values from the options object.
filter = options_object[0]["filter"]
rows = options_object[0]["rows"]
metric = options_object[0]["metric"]
async with AsyncClient(app=app, base_url="http://localhost") as client:
response = await client.post("/api/Thermal_characteristics", json=options_object)
# Check if the response is 200. Indicating the request was successful.
assert response.status_code == 200
json = response.json()
# Check if the key exists in the json object. If it does not the response is malformed.
key = f'{filter}:{rows}'
assert key in json
expected_sum_values = [6552248504.570894, 3076469275.3280973, 2255620992.642106, 1939599958.878648]
# Loop over each array in the json object under the 'metric' key checking if each value matches the
# respective 'correct' value the route should have returned.
for i in range(len(json[key][metric])):
assert abs(json[key][metric][i][1] - expected_sum_values[i]) < 0.1
@pytest.mark.asyncio(scope='session')
async def test_thermal_characteristics_heating_types_after_rows_average_metric():
# Create a object containing the options the route expects.
options_object = [{"filter": "heating_type", "rows": "after", "metric": "average"}]
# Get the values from the options object.
filter = options_object[0]["filter"]
rows = options_object[0]["rows"]
metric = options_object[0]["metric"]
async with AsyncClient(app=app, base_url="http://localhost") as client:
response = await client.post("/api/Thermal_characteristics", json=options_object)
# Check if the response is 200. Indicating the request was successful.
assert response.status_code == 200
json = response.json()
# Check if the key exists in the json object. If it does not the response is malformed.
key = f'{filter}:{rows}'
assert key in json
expected_sum_values = [10527.696184971752, 13960.90677065643, 3527.8255074619874, 9667.736665062077]
# Loop over each array in the json object under the 'metric' key checking if each value matches the
# respective 'correct' value the route should have returned.
for i in range(len(json[key][metric])):
assert abs(json[key][metric][i][1] - expected_sum_values[i]) < 0.1
@pytest.mark.asyncio(scope='session')
async def test_thermal_characteristics_heating_types_after_rows_sum_metric():
# Create a object containing the options the route expects.
options_object = [{"filter": "heating_type", "rows": "after", "metric": "sum"}]
# Get the values from the options object.
filter = options_object[0]["filter"]
rows = options_object[0]["rows"]
metric = options_object[0]["metric"]
async with AsyncClient(app=app, base_url="http://localhost") as client:
response = await client.post("/api/Thermal_characteristics", json=options_object)
# Check if the response is 200. Indicating the request was successful.
assert response.status_code == 200
json = response.json()
# Check if the key exists in the json object. If it does not the response is malformed.
key = f'{filter}:{rows}'
assert key in json
expected_sum_values = [4375457922.22085, 1934353437.6083016, 1265032365.2442715, 1201051929.1106572]
# Loop over each array in the json object under the 'metric' key checking if each value matches the
# respective 'correct' value the route should have returned.
for i in range(len(json[key][metric])):
assert abs(json[key][metric][i][1] - expected_sum_values[i]) < 0.1
@pytest.mark.asyncio(scope='session')
async def test_thermal_characteristics_dwelling_types_before_rows_average_metric():
# Create a object containing the options the route expects.
options_object = [{"filter": "dwelling_type", "rows": "before", "metric": "average"}]
# Get the values from the options object.
filter = options_object[0]["filter"]
rows = options_object[0]["rows"]
metric = options_object[0]["metric"]
async with AsyncClient(app=app, base_url="http://localhost") as client:
response = await client.post("/api/Thermal_characteristics", json=options_object)
# Check if the response is 200. Indicating the request was successful.
assert response.status_code == 200
json = response.json()
# Check if the key exists in the json object. If it does not the response is malformed.
key = f'{filter}:{rows}'
assert key in json
expected_mean_values = [20662.334566326088, 7360.218202025956, 13433.8746398528, 11310.990174552595]
# Loop over each array in the json object under the 'metric' key checking if each value matches the
# respective 'correct' value the route should have returned.
for i in range(len(json[key][metric])):
assert abs(json[key][metric][i][1] - expected_mean_values[i]) < 0.1
@pytest.mark.asyncio(scope='session')
async def test_thermal_characteristics_dwelling_types_before_rows_sum_metric():
# Create a object containing the options the route expects.
options_object = [{"filter": "dwelling_type", "rows": "before", "metric": "sum"}]
# Get the values from the options object.
filter = options_object[0]["filter"]
rows = options_object[0]["rows"]
metric = options_object[0]["metric"]
async with AsyncClient(app=app, base_url="http://localhost") as client:
response = await client.post("/api/Thermal_characteristics", json=options_object)
# Check if the response is 200. Indicating the request was successful.
assert response.status_code == 200
json = response.json()
# Check if the key exists in the json object. If it does not the response is malformed.
key = f'{filter}:{rows}'
assert key in json
expected_sum_values = [5393551178.851798, 1762477850.6571355, 3794397892.026423, 2873511809.8843884]
# Loop over each array in the json object under the 'metric' key checking if each value matches the
# respective 'correct' value the route should have returned.
for i in range(len(json[key][metric])):
assert abs(json[key][metric][i][1] - expected_sum_values[i]) < 0.1
@pytest.mark.asyncio(scope='session')
async def test_thermal_characteristics_dwelling_types_after_rows_average_metric():
# Create a object containing the options the route expects.
options_object = [{"filter": "dwelling_type", "rows": "after", "metric": "average"}]
# Get the values from the options object.
filter = options_object[0]["filter"]
rows = options_object[0]["rows"]
metric = options_object[0]["metric"]
async with AsyncClient(app=app, base_url="http://localhost") as client:
response = await client.post("/api/Thermal_characteristics", json=options_object)
# Check if the response is 200. Indicating the request was successful.
assert response.status_code == 200
json = response.json()
# Check if the key exists in the json object. If it does not the response is malformed.
key = f'{filter}:{rows}'
assert key in json
expected_mean_values = [12920.912936647484, 4890.05743293047, 8432.818732430796, 7283.280129297719]
# Loop over each array in the json object under the 'metric' key checking if each value matches the
# respective 'correct' value the route should have returned.
for i in range(len(json[key][metric])):
print(json[key][metric])
assert abs(json[key][metric][i][1] - expected_mean_values[i]) < 0.1
@pytest.mark.asyncio(scope='session')
async def test_thermal_characteristics_dwelling_types_after_rows_sum_metric():
# Create a object containing the options the route expects.
options_object = [{"filter": "dwelling_type", "rows": "after", "metric": "sum"}]
# Get the values from the options object.
filter = options_object[0]["filter"]
rows = options_object[0]["rows"]
metric = options_object[0]["metric"]
async with AsyncClient(app=app, base_url="http://localhost") as client:
response = await client.post("/api/Thermal_characteristics", json=options_object)
# Check if the response is 200. Indicating the request was successful.
assert response.status_code == 200
json = response.json()
# Check if the key exists in the json object. If it does not the response is malformed.
key = f'{filter}:{rows}'
assert key in json
expected_sum_values = [3372784666.591903, 1170973152.8895304, 2381849650.9750786, 1850288183.7275686]
# Loop over each array in the json object under the 'metric' key checking if each value matches the
# respective 'correct' value the route should have returned.
for i in range(len(json[key][metric])):
assert abs(json[key][metric][i][1] - expected_sum_values[i]) < 0.1