This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
120 lines (83 loc) · 3.94 KB
/
test.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
from fastapi.testclient import TestClient
from app import app
client = TestClient(app)
def test_all_functions_country() -> None:
"""
Test all the functions in the routers/country.py file.
"""
# Test the get_country function with a continent parameter
print(client.get("/country?continent=asia").json())
print('-----------------------------------')
# Test the get_country function without a continent parameter
print(client.get("/country").json())
print('-----------------------------------')
# Test the get_country_detail function with a country parameter
print(client.get("/country/india").json())
print('-----------------------------------')
# Test the get_country_temperature function with a country parameter
print(client.get("/country/india/temperature").json())
print('-----------------------------------')
# Test the get_country_forecast function with a country and days parameter
print('Forecast for the next four days for India saved in forecast_india_4.png')
response = client.get("/country/india/forecast/4")
with open('forecast_india_4.png', 'wb') as file:
file.write(response.content)
print('-----------------------------------')
# Test the get_country_forecast function with a country and days parameter
print('Forecast for the next day for India saved in forecast_india_1.png')
response = client.get("/country/india/forecast/1")
with open('forecast_india_1.png', 'wb') as file:
file.write(response.content)
print('-----------------------------------')
def test_all_functions_favorite() -> None:
"""
Test all the functions in the routers/favorite.py file.
"""
# Test the get_favorite function
print(client.get("/favorite").json())
print('-----------------------------------')
# Test the add_favorite function with a country parameter
print(client.post("/favorite/india").json())
print('-----------------------------------')
# Test the get_favorite function
print(client.get("/favorite").json())
print('-----------------------------------')
# Test the remove_favorite function with a country parameter
print(client.delete("/favorite/india").json())
print('-----------------------------------')
# Test the get_favorite function
print(client.get("/favorite").json())
print('-----------------------------------')
def test_hottest_country_sa() -> None:
"""
Test the hottest country in South America and answer the query of which country in South America is currently the
warmest.
You should favorite that country and display a line graph containing the temperature forecast for the
following four days.
"""
response = client.get("/country?continent=south%20america")
list_of_temp = []
for country in response.json()["List of countries"]:
list_of_temp.append((client.get(f"/country/{country}/temperature").json()["Temperature"], country))
warmest_country = max(list_of_temp)
print(warmest_country[1])
print('-----------------------------------')
# Display the favorite list
response = client.get("/favorite")
print(response.json())
print('-----------------------------------')
# Favorite the warmest country
response = client.post(f"/favorite/{warmest_country[1]}")
print(response.json())
print('-----------------------------------')
# Display the favorite list
response = client.get("/favorite")
print(response.json())
print('-----------------------------------')
# Display the temperature forecast for the following four days
response = client.get(f"/country/{warmest_country[1]}/forecast/{4}")
# write image to a file
print(f'Forecast for the next 4 days for {warmest_country[1]} saved in forecast_{warmest_country[1]}_4.png')
with open(f'forecast_{warmest_country[1]}_4.png', 'wb') as file:
file.write(response.content)
print('-----------------------------------')