Skip to content

Commit

Permalink
update test_api_error now that we have csv fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
bdamokos committed Dec 28, 2024

Verified

This commit was signed with the committer’s verified signature.
torkelrogstad Torkel Rogstad
1 parent ee7cff6 commit bf2a42a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tests/test_downloads.py
Original file line number Diff line number Diff line change
@@ -286,7 +286,7 @@ def mock_get(*args, **kwargs):
shutil.rmtree(test_dir)

def test_api_error(monkeypatch):
"""Test handling of API errors"""
"""Test handling of API errors with CSV fallback"""
def mock_get(*args, **kwargs):
response = requests.Response()
response.status_code = 500
@@ -302,9 +302,18 @@ def mock_post(*args, **kwargs):
monkeypatch.setattr(requests, "post", mock_post)
api = MobilityAPI()

# Test provider search with API error
# Test provider search with API error - should fall back to CSV
providers = api.get_providers_by_country("HU")
assert len(providers) == 0
assert len(providers) > 0 # Should get providers from CSV
assert api._use_csv is True # Should switch to CSV mode after API error

# Create a new API instance to test with forced CSV mode
api_csv = MobilityAPI(force_csv_mode=True)
providers_csv = api_csv.get_providers_by_country("HU")

# Results should be the same as the fallback
assert len(providers) == len(providers_csv)
assert [p['id'] for p in providers] == [p['id'] for p in providers_csv]

def test_missing_feed_info():
"""Test handling of missing feed_info.txt"""

0 comments on commit bf2a42a

Please sign in to comment.