1+ """
2+ End-to-end tests for batch reverse geocoding functionality.
3+ """
4+
5+ import pytest
6+ from geocodio import GeocodioClient
7+
8+
9+ def test_batch_reverse_geocoding (client ):
10+ """Test batch reverse geocoding against real API."""
11+ # Arrange
12+ coordinates = [
13+ (38.886665 , - 77.094733 ), # Arlington, VA
14+ (38.897676 , - 77.036530 ), # White House
15+ (37.331669 , - 122.030090 ) # Apple Park
16+ ]
17+
18+ # Act
19+ response = client .reverse (coordinates )
20+
21+ # Assert
22+ assert response is not None
23+ assert len (response .results ) == 3
24+
25+ # Check first result (Arlington, VA)
26+ arlington = response .results [0 ]
27+ assert "Arlington" in arlington .formatted_address
28+ assert "VA" in arlington .formatted_address
29+ assert arlington .location .lat == pytest .approx (38.886672 , abs = 0.001 )
30+ assert arlington .location .lng == pytest .approx (- 77.094735 , abs = 0.001 )
31+
32+ # Check second result (White House)
33+ white_house = response .results [1 ]
34+ assert "Pennsylvania" in white_house .formatted_address
35+ assert "Washington" in white_house .formatted_address or "DC" in white_house .formatted_address
36+
37+ # Check third result (Apple Park)
38+ apple_park = response .results [2 ]
39+ assert "Cupertino" in apple_park .formatted_address or "CA" in apple_park .formatted_address
40+
41+
42+ def test_batch_reverse_with_strings (client ):
43+ """Test batch reverse geocoding with string coordinates."""
44+ # Arrange
45+ coordinates = [
46+ "38.886665,-77.094733" , # Arlington, VA
47+ "38.897676,-77.036530" # White House
48+ ]
49+
50+ # Act
51+ response = client .reverse (coordinates )
52+
53+ # Assert
54+ assert response is not None
55+ assert len (response .results ) == 2
56+ assert "Arlington" in response .results [0 ].formatted_address
57+ assert "Pennsylvania" in response .results [1 ].formatted_address or "Washington" in response .results [1 ].formatted_address
58+
59+
60+ def test_batch_reverse_with_fields (client ):
61+ """Test batch reverse geocoding with additional fields."""
62+ # Arrange
63+ coordinates = [
64+ (38.886665 , - 77.094733 ), # Arlington, VA
65+ (38.897676 , - 77.036530 ) # White House
66+ ]
67+
68+ # Act
69+ response = client .reverse (coordinates , fields = ["timezone" , "cd" ])
70+
71+ # Assert
72+ assert response is not None
73+ assert len (response .results ) == 2
74+
75+ # Check that fields are populated
76+ for result in response .results :
77+ assert result .fields is not None
78+ if result .fields .timezone :
79+ assert result .fields .timezone .name is not None
80+ if result .fields .congressional_districts :
81+ assert len (result .fields .congressional_districts ) > 0
82+
83+
84+ def test_empty_batch_reverse (client ):
85+ """Test batch reverse geocoding with empty list."""
86+ # Arrange
87+ coordinates = []
88+
89+ # Act & Assert
90+ with pytest .raises (Exception ):
91+ client .reverse (coordinates )
92+
93+
94+ def test_mixed_batch_reverse_formats (client ):
95+ """Test batch reverse geocoding with mixed coordinate formats."""
96+ # Note: The API expects consistent format, so this tests error handling
97+ # Arrange
98+ coordinates = [
99+ (38.886665 , - 77.094733 ), # Tuple format
100+ "38.897676,-77.036530" # String format
101+ ]
102+
103+ # Act
104+ # The library should handle converting these to a consistent format
105+ response = client .reverse (coordinates )
106+
107+ # Assert
108+ assert response is not None
109+ assert len (response .results ) == 2
0 commit comments