Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Der-Henning
GitHub Repository: Der-Henning/tgtg
Path: blob/main/tests/test_location.py
725 views
1
from pytest_mock.plugin import MockerFixture
2
3
from tgtg_scanner.models import Location
4
5
6
def test_calculate_distance_time(mocker: MockerFixture):
7
google_api_key = "AIza123456"
8
location = "Hauptstraße 1, 20099 Hamburg, Germany"
9
10
mocker.patch("googlemaps.Client.geocode", return_value=[{}])
11
mocker.patch(
12
"googlemaps.Client.directions",
13
return_value=[{"legs": [{"distance": {"value": 1500}, "duration": {"value": 1200}}]}],
14
)
15
16
distance_time_calculator = Location(True, google_api_key, location)
17
distance_time = distance_time_calculator.calculate_distance_time("München", Location.WALKING_MODE)
18
19
assert distance_time is not None
20
assert distance_time.distance == 1500
21
assert distance_time.duration == 1200
22
assert distance_time.travel_mode == Location.WALKING_MODE
23
24