-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathruntests.py
114 lines (104 loc) · 3.79 KB
/
runtests.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
import unittest
import requests
class TestParkingAPI(unittest.TestCase):
def setUp(self):
self.base_url = "http://localhost:8080"
self.sample_rates = {
"rates": [
{
"days": "mon,tues,thurs",
"times": "0900-2100",
"tz": "America/Chicago",
"price": 1500,
},
{
"days": "fri,sat,sun",
"times": "0900-2100",
"tz": "America/Chicago",
"price": 2000,
},
{
"days": "wed",
"times": "0600-1800",
"tz": "America/Chicago",
"price": 1750,
},
{
"days": "mon,wed,sat",
"times": "0100-0500",
"tz": "America/Chicago",
"price": 1000,
},
{
"days": "sun,tues",
"times": "0100-0700",
"tz": "America/Chicago",
"price": 925,
},
]
}
response = requests.put(f"{self.base_url}/rates", json=self.sample_rates)
self.assertEqual(response.status_code, 200, "Failed to load initial rates")
def test_price_available(self):
response = requests.get(
f"{self.base_url}/price?start=2015-07-01T07:00:00-05:00&end=2015-07-01T12:00:00-05:00"
)
self.assertEqual(response.status_code, 200)
price_data = response.json()
self.assertEqual(
price_data["price"], 1750, "Price does not match expected value"
)
def test_price_unavailable_multiple_days(self):
response = requests.get(
f"{self.base_url}/price?start=2015-07-01T07:00:00-05:00&end=2015-07-02T12:00:00-05:00"
)
self.assertEqual(response.status_code, 200)
price_data = response.json()
self.assertEqual(
price_data["price"],
"unavailable",
"Expected 'unavailable' for multiple days",
)
def test_price_unavailable_multiple_rates(self):
response = requests.get(
f"{self.base_url}/price?start=2015-07-01T07:00:00-05:00&end=2015-07-01T19:00:00-05:00"
)
self.assertEqual(response.status_code, 200)
price_data = response.json()
self.assertEqual(
price_data["price"],
"unavailable",
"Expected 'unavailable' for multiple rates",
)
def test_price_unavailable_no_matching_rate(self):
response = requests.get(
f"{self.base_url}/price?start=2015-07-01T00:00:00-05:00&end=2015-07-01T01:00:00-05:00",
)
self.assertEqual(response.status_code, 200)
price_data = response.json()
self.assertEqual(
price_data["price"],
"unavailable",
"Expected 'unavailable' for no matching rate",
)
def test_update_rates(self):
new_rates = {
"rates": [
{
"days": "mon",
"times": "0000-2359",
"tz": "America/New_York",
"price": 5000,
}
]
}
response = requests.put(f"{self.base_url}/rates", json=new_rates)
self.assertEqual(response.status_code, 200)
response = requests.get(
f"{self.base_url}/price?start=2024-08-05T00:00:00-04:00&end=2024-08-05T23:59:00-04:00",
)
self.assertEqual(response.status_code, 200)
price_data = response.json()
self.assertEqual(price_data["price"], 5000, "Price does not match updated rate")
if __name__ == "__main__":
unittest.main()