-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_distance.py
More file actions
774 lines (633 loc) · 28.8 KB
/
test_distance.py
File metadata and controls
774 lines (633 loc) · 28.8 KB
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
"""
Unit tests for the Distance API implementation.
"""
import json
import pytest
import httpx
from geocodio import (
Geocodio,
Coordinate,
DISTANCE_MODE_STRAIGHTLINE,
DISTANCE_MODE_DRIVING,
DISTANCE_MODE_HAVERSINE,
DISTANCE_UNITS_MILES,
DISTANCE_UNITS_KM,
DISTANCE_ORDER_BY_DISTANCE,
DISTANCE_ORDER_BY_DURATION,
DISTANCE_SORT_ASC,
DISTANCE_SORT_DESC,
DistanceResponse,
DistanceMatrixResponse,
DistanceJobResponse,
)
# ──────────────────────────────────────────────────────────────────────────────
# Coordinate Class Tests
# ──────────────────────────────────────────────────────────────────────────────
class TestCoordinate:
"""Tests for the Coordinate class."""
def test_create_basic(self):
"""Test basic coordinate creation."""
coord = Coordinate(38.8977, -77.0365)
assert coord.lat == 38.8977
assert coord.lng == -77.0365
assert coord.id is None
def test_create_with_id(self):
"""Test coordinate creation with id."""
coord = Coordinate(38.8977, -77.0365, "white_house")
assert coord.lat == 38.8977
assert coord.lng == -77.0365
assert coord.id == "white_house"
def test_validation_lat_too_high(self):
"""Test latitude validation - too high."""
with pytest.raises(ValueError, match="Latitude must be between"):
Coordinate(91.0, -77.0365)
def test_validation_lat_too_low(self):
"""Test latitude validation - too low."""
with pytest.raises(ValueError, match="Latitude must be between"):
Coordinate(-91.0, -77.0365)
def test_validation_lng_too_high(self):
"""Test longitude validation - too high."""
with pytest.raises(ValueError, match="Longitude must be between"):
Coordinate(38.8977, 181.0)
def test_validation_lng_too_low(self):
"""Test longitude validation - too low."""
with pytest.raises(ValueError, match="Longitude must be between"):
Coordinate(38.8977, -181.0)
def test_from_string_basic(self):
"""Test creating coordinate from string 'lat,lng'."""
coord = Coordinate.from_input("38.8977,-77.0365")
assert coord.lat == 38.8977
assert coord.lng == -77.0365
assert coord.id is None
def test_from_string_with_id(self):
"""Test creating coordinate from string 'lat,lng,id'."""
coord = Coordinate.from_input("38.8977,-77.0365,white_house")
assert coord.lat == 38.8977
assert coord.lng == -77.0365
assert coord.id == "white_house"
def test_from_string_with_spaces(self):
"""Test creating coordinate from string with spaces."""
coord = Coordinate.from_input(" 38.8977 , -77.0365 , white_house ")
assert coord.lat == 38.8977
assert coord.lng == -77.0365
assert coord.id == "white_house"
def test_from_tuple(self):
"""Test creating coordinate from tuple (lat, lng)."""
coord = Coordinate.from_input((38.8977, -77.0365))
assert coord.lat == 38.8977
assert coord.lng == -77.0365
assert coord.id is None
def test_from_tuple_with_id(self):
"""Test creating coordinate from tuple (lat, lng, id)."""
coord = Coordinate.from_input((38.8977, -77.0365, "white_house"))
assert coord.lat == 38.8977
assert coord.lng == -77.0365
assert coord.id == "white_house"
def test_from_list(self):
"""Test creating coordinate from list [lat, lng]."""
coord = Coordinate.from_input([38.8977, -77.0365])
assert coord.lat == 38.8977
assert coord.lng == -77.0365
def test_from_dict(self):
"""Test creating coordinate from dict."""
coord = Coordinate.from_input({"lat": 38.8977, "lng": -77.0365})
assert coord.lat == 38.8977
assert coord.lng == -77.0365
assert coord.id is None
def test_from_dict_with_id(self):
"""Test creating coordinate from dict with id."""
coord = Coordinate.from_input({"lat": 38.8977, "lng": -77.0365, "id": "white_house"})
assert coord.lat == 38.8977
assert coord.lng == -77.0365
assert coord.id == "white_house"
def test_from_coordinate(self):
"""Test creating coordinate from another Coordinate object."""
original = Coordinate(38.8977, -77.0365, "white_house")
coord = Coordinate.from_input(original)
assert coord is original
def test_to_string_basic(self):
"""Test converting coordinate to string."""
coord = Coordinate(38.8977, -77.0365)
assert coord.to_string() == "38.8977,-77.0365"
def test_to_string_with_id(self):
"""Test converting coordinate with id to string."""
coord = Coordinate(38.8977, -77.0365, "white_house")
assert coord.to_string() == "38.8977,-77.0365,white_house"
def test_to_dict_basic(self):
"""Test converting coordinate to dict."""
coord = Coordinate(38.8977, -77.0365)
assert coord.to_dict() == {"lat": 38.8977, "lng": -77.0365}
def test_to_dict_with_id(self):
"""Test converting coordinate with id to dict."""
coord = Coordinate(38.8977, -77.0365, "white_house")
assert coord.to_dict() == {"lat": 38.8977, "lng": -77.0365, "id": "white_house"}
def test_str(self):
"""Test string representation."""
coord = Coordinate(38.8977, -77.0365, "white_house")
assert str(coord) == "38.8977,-77.0365,white_house"
# ──────────────────────────────────────────────────────────────────────────────
# Distance Method Tests
# ──────────────────────────────────────────────────────────────────────────────
def sample_distance_response():
"""Sample response for distance endpoint."""
return {
"origin": {
"query": "38.8977,-77.0365,white_house",
"location": [38.8977, -77.0365],
"id": "white_house"
},
"mode": "straightline",
"destinations": [
{
"query": "38.9072,-77.0369,capitol",
"location": [38.9072, -77.0369],
"id": "capitol",
"distance_miles": 0.7,
"distance_km": 1.1
},
{
"query": "38.8895,-77.0353,monument",
"location": [38.8895, -77.0353],
"id": "monument",
"distance_miles": 0.6,
"distance_km": 0.9
}
]
}
def sample_distance_driving_response():
"""Sample response for distance endpoint with driving mode."""
return {
"origin": {
"query": "38.8977,-77.0365",
"location": [38.8977, -77.0365]
},
"mode": "driving",
"destinations": [
{
"query": "38.9072,-77.0369",
"location": [38.9072, -77.0369],
"distance_miles": 1.2,
"distance_km": 1.9,
"duration_seconds": 294
}
]
}
class TestDistance:
"""Tests for the distance() method."""
def test_distance_basic(self, client, httpx_mock):
"""Test basic distance calculation."""
def response_callback(request):
assert request.method == "GET"
assert "/v1.10/distance" in str(request.url)
return httpx.Response(200, json=sample_distance_response())
httpx_mock.add_callback(callback=response_callback)
response = client.distance(
origin="38.8977,-77.0365,white_house",
destinations=["38.9072,-77.0369,capitol", "38.8895,-77.0353,monument"]
)
assert isinstance(response, DistanceResponse)
assert response.origin.id == "white_house"
assert response.mode == "straightline"
assert len(response.destinations) == 2
assert response.destinations[0].id == "capitol"
assert response.destinations[0].distance_miles == 0.7
def test_distance_with_coordinate_objects(self, client, httpx_mock):
"""Test distance with Coordinate objects."""
httpx_mock.add_callback(
callback=lambda request: httpx.Response(200, json=sample_distance_response())
)
origin = Coordinate(38.8977, -77.0365, "white_house")
destinations = [
Coordinate(38.9072, -77.0369, "capitol"),
Coordinate(38.8895, -77.0353, "monument")
]
response = client.distance(origin=origin, destinations=destinations)
assert isinstance(response, DistanceResponse)
assert len(response.destinations) == 2
def test_distance_with_tuples(self, client, httpx_mock):
"""Test distance with tuple coordinates."""
httpx_mock.add_callback(
callback=lambda request: httpx.Response(200, json=sample_distance_response())
)
response = client.distance(
origin=(38.8977, -77.0365),
destinations=[(38.9072, -77.0369), (38.8895, -77.0353)]
)
assert isinstance(response, DistanceResponse)
def test_distance_driving_mode(self, client, httpx_mock):
"""Test distance with driving mode returns duration."""
def response_callback(request):
assert "mode=driving" in str(request.url)
return httpx.Response(200, json=sample_distance_driving_response())
httpx_mock.add_callback(callback=response_callback)
response = client.distance(
origin="38.8977,-77.0365",
destinations=["38.9072,-77.0369"],
mode=DISTANCE_MODE_DRIVING
)
assert response.mode == "driving"
assert response.destinations[0].duration_seconds == 294
def test_distance_haversine_mapped_to_straightline(self, client, httpx_mock):
"""Test that haversine mode is mapped to straightline."""
def response_callback(request):
assert "mode=straightline" in str(request.url)
return httpx.Response(200, json=sample_distance_response())
httpx_mock.add_callback(callback=response_callback)
client.distance(
origin="38.8977,-77.0365",
destinations=["38.9072,-77.0369"],
mode=DISTANCE_MODE_HAVERSINE
)
def test_distance_with_filters(self, client, httpx_mock):
"""Test distance with filter parameters."""
def response_callback(request):
url_str = str(request.url)
assert "max_results=5" in url_str
assert "max_distance=10" in url_str # Changed from 10.0 due to URL encoding
return httpx.Response(200, json=sample_distance_response())
httpx_mock.add_callback(callback=response_callback)
client.distance(
origin="38.8977,-77.0365",
destinations=["38.9072,-77.0369"],
max_results=5,
max_distance=10.0
)
def test_distance_with_sorting(self, client, httpx_mock):
"""Test distance with sorting parameters."""
def response_callback(request):
url_str = str(request.url)
assert "order_by=duration" in url_str
assert "sort=desc" in url_str
return httpx.Response(200, json=sample_distance_response())
httpx_mock.add_callback(callback=response_callback)
client.distance(
origin="38.8977,-77.0365",
destinations=["38.9072,-77.0369"],
order_by=DISTANCE_ORDER_BY_DURATION,
sort_order=DISTANCE_SORT_DESC
)
# ──────────────────────────────────────────────────────────────────────────────
# Distance Matrix Method Tests
# ──────────────────────────────────────────────────────────────────────────────
def sample_distance_matrix_response():
"""Sample response for distance-matrix endpoint."""
return {
"mode": "straightline",
"results": [
{
"origin": {
"query": "38.8977,-77.0365",
"location": [38.8977, -77.0365],
"id": "origin1"
},
"destinations": [
{
"query": "38.8895,-77.0353",
"location": [38.8895, -77.0353],
"id": "dest1",
"distance_miles": 1.5,
"distance_km": 2.5
}
]
},
{
"origin": {
"query": "38.9072,-77.0369",
"location": [38.9072, -77.0369],
"id": "origin2"
},
"destinations": [
{
"query": "38.8895,-77.0353",
"location": [38.8895, -77.0353],
"id": "dest1",
"distance_miles": 1.3,
"distance_km": 2.1
}
]
}
]
}
class TestDistanceMatrix:
"""Tests for the distance_matrix() method."""
def test_distance_matrix_basic(self, client, httpx_mock):
"""Test basic distance matrix calculation."""
def response_callback(request):
assert request.method == "POST"
body = json.loads(request.content)
assert "origins" in body
assert "destinations" in body
assert body["mode"] == "straightline"
return httpx.Response(200, json=sample_distance_matrix_response())
httpx_mock.add_callback(callback=response_callback)
response = client.distance_matrix(
origins=[
(38.8977, -77.0365, "origin1"),
(38.9072, -77.0369, "origin2")
],
destinations=[
(38.8895, -77.0353, "dest1")
]
)
assert isinstance(response, DistanceMatrixResponse)
assert response.mode == "straightline"
assert len(response.results) == 2
assert response.results[0].origin.id == "origin1"
assert response.results[0].destinations[0].distance_miles == 1.5
def test_distance_matrix_uses_object_format(self, client, httpx_mock):
"""Test that distance_matrix uses object format in POST body."""
def response_callback(request):
body = json.loads(request.content)
# Origins and destinations should be dicts, not strings
assert isinstance(body["origins"][0], dict)
assert "lat" in body["origins"][0]
assert "lng" in body["origins"][0]
return httpx.Response(200, json=sample_distance_matrix_response())
httpx_mock.add_callback(callback=response_callback)
client.distance_matrix(
origins=["38.8977,-77.0365,origin1"],
destinations=["38.8895,-77.0353,dest1"]
)
def test_distance_matrix_preserves_ids(self, client, httpx_mock):
"""Test that IDs are preserved in request."""
def response_callback(request):
body = json.loads(request.content)
assert body["origins"][0]["id"] == "origin1"
assert body["destinations"][0]["id"] == "dest1"
return httpx.Response(200, json=sample_distance_matrix_response())
httpx_mock.add_callback(callback=response_callback)
client.distance_matrix(
origins=[Coordinate(38.8977, -77.0365, "origin1")],
destinations=[Coordinate(38.8895, -77.0353, "dest1")]
)
# ──────────────────────────────────────────────────────────────────────────────
# Distance Job Method Tests
# ──────────────────────────────────────────────────────────────────────────────
def sample_job_create_response():
"""Sample response for creating a distance job."""
return {
"id": 123,
"identifier": "abc123def456",
"status": "ENQUEUED",
"name": "My Job",
"created_at": "2025-01-15T12:00:00.000000Z",
"origins_count": 2,
"destinations_count": 2,
"total_calculations": 4
}
def sample_job_status_response():
"""Sample response for job status."""
return {
"data": {
"id": 123,
"identifier": "abc123def456",
"name": "My Job",
"status": "COMPLETED",
"progress": 100,
"download_url": "https://api.geocod.io/v1.10/distance-jobs/123/download",
"total_calculations": 4,
"calculations_completed": 4,
"origins_count": 2,
"destinations_count": 2,
"created_at": "2025-01-15T12:00:00.000000Z"
}
}
def sample_jobs_list_response():
"""Sample response for listing jobs."""
return {
"data": [
{
"id": 123,
"identifier": "abc123",
"status": "COMPLETED",
"name": "Job 1",
"created_at": "2025-01-15T12:00:00.000000Z",
"origins_count": 2,
"destinations_count": 2,
"total_calculations": 4
},
{
"id": 124,
"identifier": "def456",
"status": "PROCESSING",
"name": "Job 2",
"created_at": "2025-01-15T13:00:00.000000Z",
"origins_count": 3,
"destinations_count": 3,
"total_calculations": 9
}
],
"current_page": 1,
"from": 1,
"to": 2,
"path": "/v1.10/distance-jobs",
"per_page": 10
}
class TestDistanceJobs:
"""Tests for distance job methods."""
def test_create_job_with_coordinates(self, client, httpx_mock):
"""Test creating a distance job with coordinate lists."""
def response_callback(request):
assert request.method == "POST"
body = json.loads(request.content)
assert body["name"] == "My Job"
assert isinstance(body["origins"], list)
assert isinstance(body["destinations"], list)
return httpx.Response(200, json=sample_job_create_response())
httpx_mock.add_callback(callback=response_callback)
response = client.create_distance_matrix_job(
name="My Job",
origins=[(38.8977, -77.0365), (38.9072, -77.0369)],
destinations=[(38.8895, -77.0353), (39.2904, -76.6122)]
)
assert isinstance(response, DistanceJobResponse)
assert response.id == 123
assert response.status == "ENQUEUED"
assert response.total_calculations == 4
def test_create_job_with_list_ids(self, client, httpx_mock):
"""Test creating a distance job with list IDs."""
def response_callback(request):
body = json.loads(request.content)
assert body["origins"] == 12345
assert body["destinations"] == 67890
return httpx.Response(200, json=sample_job_create_response())
httpx_mock.add_callback(callback=response_callback)
client.create_distance_matrix_job(
name="My Job",
origins=12345,
destinations=67890
)
def test_create_job_with_callback_url(self, client, httpx_mock):
"""Test creating a job with callback URL."""
def response_callback(request):
body = json.loads(request.content)
assert body["callback_url"] == "https://example.com/webhook"
return httpx.Response(200, json=sample_job_create_response())
httpx_mock.add_callback(callback=response_callback)
client.create_distance_matrix_job(
name="My Job",
origins=[(38.8977, -77.0365)],
destinations=[(38.8895, -77.0353)],
callback_url="https://example.com/webhook"
)
def test_job_status(self, client, httpx_mock):
"""Test getting job status."""
httpx_mock.add_callback(
callback=lambda request: httpx.Response(200, json=sample_job_status_response())
)
response = client.distance_matrix_job_status(123)
assert response.id == 123
assert response.status == "COMPLETED"
assert response.progress == 100
def test_list_jobs(self, client, httpx_mock):
"""Test listing jobs."""
httpx_mock.add_callback(
callback=lambda request: httpx.Response(200, json=sample_jobs_list_response())
)
response = client.distance_matrix_jobs()
assert response.current_page == 1
assert len(response.data) == 2
def test_get_job_results(self, client, httpx_mock):
"""Test downloading job results."""
httpx_mock.add_callback(
callback=lambda request: httpx.Response(
200,
json=sample_distance_matrix_response(),
headers={"content-type": "application/json"}
)
)
response = client.get_distance_matrix_job_results(123)
assert isinstance(response, DistanceMatrixResponse)
assert len(response.results) == 2
def test_delete_job(self, client, httpx_mock):
"""Test deleting a job."""
def response_callback(request):
assert request.method == "DELETE"
return httpx.Response(204)
httpx_mock.add_callback(callback=response_callback)
# Should not raise
client.delete_distance_matrix_job(123)
# ──────────────────────────────────────────────────────────────────────────────
# Geocode with Distance Tests
# ──────────────────────────────────────────────────────────────────────────────
def sample_geocode_with_distance_response():
"""Sample geocode response with distance data."""
return {
"results": [{
"address_components": {
"number": "1600",
"street": "Pennsylvania",
"suffix": "Ave",
"city": "Washington",
"state": "DC",
"zip": "20500"
},
"formatted_address": "1600 Pennsylvania Ave NW, Washington, DC 20500",
"location": {"lat": 38.8977, "lng": -77.0365},
"accuracy": 1,
"accuracy_type": "rooftop",
"source": "DC",
"destinations": [
{
"query": "38.9072,-77.0369",
"location": [38.9072, -77.0369],
"distance_miles": 0.7,
"distance_km": 1.1
}
]
}]
}
class TestGeocodeWithDistance:
"""Tests for geocode() with distance parameters."""
def test_geocode_with_destinations(self, client, httpx_mock):
"""Test geocode with destination parameter."""
def response_callback(request):
url_str = str(request.url)
assert "/v1.10/geocode" in url_str
assert "destinations%5B%5D" in url_str or "destinations[]" in url_str.replace("%5B", "[").replace("%5D", "]")
return httpx.Response(200, json=sample_geocode_with_distance_response())
httpx_mock.add_callback(callback=response_callback)
response = client.geocode(
"1600 Pennsylvania Ave NW, Washington DC",
destinations=["38.9072,-77.0369"]
)
assert len(response.results) == 1
def test_geocode_with_distance_mode(self, client, httpx_mock):
"""Test geocode with distance mode parameter."""
def response_callback(request):
url_str = str(request.url)
assert "/v1.10/geocode" in url_str
assert "distance_mode=driving" in url_str
return httpx.Response(200, json=sample_geocode_with_distance_response())
httpx_mock.add_callback(callback=response_callback)
client.geocode(
"1600 Pennsylvania Ave NW, Washington DC",
destinations=["38.9072,-77.0369"],
distance_mode=DISTANCE_MODE_DRIVING
)
def test_geocode_with_distance_units(self, client, httpx_mock):
"""Test geocode with distance units parameter."""
def response_callback(request):
url_str = str(request.url)
assert "/v1.10/geocode" in url_str
assert "distance_units=km" in url_str
return httpx.Response(200, json=sample_geocode_with_distance_response())
httpx_mock.add_callback(callback=response_callback)
client.geocode(
"1600 Pennsylvania Ave NW, Washington DC",
destinations=["38.9072,-77.0369"],
distance_units=DISTANCE_UNITS_KM
)
# ──────────────────────────────────────────────────────────────────────────────
# Reverse with Distance Tests
# ──────────────────────────────────────────────────────────────────────────────
class TestReverseWithDistance:
"""Tests for reverse() with distance parameters."""
def test_reverse_with_destinations(self, client, httpx_mock):
"""Test reverse geocode with destination parameter."""
def response_callback(request):
url_str = str(request.url)
assert "/v1.10/reverse" in url_str
assert "destinations%5B%5D" in url_str or "destinations[]" in url_str.replace("%5B", "[").replace("%5D", "]")
return httpx.Response(200, json=sample_geocode_with_distance_response())
httpx_mock.add_callback(callback=response_callback)
response = client.reverse(
"38.8977,-77.0365",
destinations=["38.9072,-77.0369"]
)
assert len(response.results) == 1
def test_reverse_with_distance_mode(self, client, httpx_mock):
"""Test reverse geocode with distance mode parameter."""
def response_callback(request):
url_str = str(request.url)
assert "/v1.10/reverse" in url_str
assert "distance_mode=straightline" in url_str
return httpx.Response(200, json=sample_geocode_with_distance_response())
httpx_mock.add_callback(callback=response_callback)
client.reverse(
(38.8977, -77.0365),
destinations=[(38.9072, -77.0369)],
distance_mode=DISTANCE_MODE_STRAIGHTLINE
)
# ──────────────────────────────────────────────────────────────────────────────
# Constants Tests
# ──────────────────────────────────────────────────────────────────────────────
class TestConstants:
"""Tests for distance constants."""
def test_mode_constants(self):
"""Test distance mode constants."""
assert DISTANCE_MODE_STRAIGHTLINE == "straightline"
assert DISTANCE_MODE_DRIVING == "driving"
assert DISTANCE_MODE_HAVERSINE == "haversine"
def test_units_constants(self):
"""Test distance units constants."""
assert DISTANCE_UNITS_MILES == "miles"
assert DISTANCE_UNITS_KM == "km"
def test_order_by_constants(self):
"""Test order by constants."""
assert DISTANCE_ORDER_BY_DISTANCE == "distance"
assert DISTANCE_ORDER_BY_DURATION == "duration"
def test_sort_constants(self):
"""Test sort constants."""
assert DISTANCE_SORT_ASC == "asc"
assert DISTANCE_SORT_DESC == "desc"