Skip to content

Commit 54743b8

Browse files
committed
Add tests for new properties
Also simplifies the loading of mock response in api status test, and adds missing requirement to setup.py
1 parent bef9ff0 commit 54743b8

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

overpass/api.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import json
88
import logging
99
import re
10-
from datetime import datetime
10+
from datetime import datetime, timezone
1111
from io import StringIO
1212
from math import ceil
1313
from typing import Optional
@@ -217,9 +217,14 @@ def slot_available_countdown(self) -> int:
217217
:returns: 0 if a slot is available now, or an int of seconds until the next slot is free
218218
"""
219219
try:
220-
return ceil(
221-
(self.slot_available_datetime -
222-
datetime.now().astimezone()).total_seconds()
220+
return max(
221+
ceil(
222+
(
223+
self.slot_available_datetime -
224+
datetime.now(timezone.utc)
225+
).total_seconds()
226+
),
227+
0
223228
)
224229
except TypeError:
225230
# Can't subtract from None, which means slot is available now

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
"Topic :: Utilities",
2121
],
2222
install_requires=["requests>=2.3.0", "geojson>=1.0.9", "shapely>=1.6.4"],
23-
extras_require={"test": ["pytest"]},
23+
extras_require={"test": ["pytest", "requests-mock[fixture]"]},
2424
)

tests/test_api.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ def test_geojson_live():
9090
"response,slots_available,slots_running,slots_waiting",
9191
[
9292
(
93-
"tests/overpass_status/no_slots_waiting.txt",
93+
Path("tests/overpass_status/no_slots_waiting.txt"),
9494
2,
9595
(),
9696
()
9797
),
9898
(
99-
"tests/overpass_status/one_slot_running.txt",
99+
Path("tests/overpass_status/one_slot_running.txt"),
100100
1,
101101
(
102102
datetime(
@@ -112,7 +112,7 @@ def test_geojson_live():
112112
()
113113
),
114114
(
115-
"tests/overpass_status/one_slot_waiting.txt",
115+
Path("tests/overpass_status/one_slot_waiting.txt"),
116116
1,
117117
(),
118118
(
@@ -128,7 +128,7 @@ def test_geojson_live():
128128
)
129129
),
130130
(
131-
"tests/overpass_status/two_slots_waiting.txt",
131+
Path("tests/overpass_status/two_slots_waiting.txt"),
132132
0,
133133
(),
134134
(
@@ -154,9 +154,8 @@ def test_geojson_live():
154154
),
155155
]
156156
)
157-
def test_api_status(response, slots_available, slots_running, slots_waiting, requests_mock):
158-
with open(response) as fp:
159-
mock_response = fp.read()
157+
def test_api_status(response: Path, slots_available: int, slots_running: tuple[datetime], slots_waiting: tuple[datetime], requests_mock):
158+
mock_response = response.read_text()
160159
requests_mock.get("https://overpass-api.de/api/status", text=mock_response)
161160

162161
api = overpass.API(debug=True)
@@ -175,3 +174,8 @@ def test_api_status(response, slots_available, slots_running, slots_waiting, req
175174

176175
assert isinstance(api.slots_waiting, tuple)
177176
assert api.slots_waiting == slots_waiting
177+
178+
assert isinstance(api.slot_available_countdown, int)
179+
assert api.slot_available_countdown >= 0
180+
181+
assert api.slot_available_datetime is None or isinstance(api.slot_available_datetime, datetime)

0 commit comments

Comments
 (0)