Skip to content

Commit 2a5e598

Browse files
committed
Decorator for fake endpoint
1 parent f6f3c5b commit 2a5e598

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

integrations/client/test_delphi_epidata.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
# py3tester coverage target
1818
__test_target__ = 'delphi.epidata.client.delphi_epidata'
1919

20+
def fake_epidata_endpoint(func):
21+
"""This can be used as a decorator to enable a bogus Epidata endpoint to return 404 responses."""
22+
def wrapper(*args):
23+
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/fake_api.php'
24+
func(*args)
25+
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
26+
return wrapper
27+
2028

2129
class DelphiEpidataPythonClientTests(unittest.TestCase):
2230
"""Tests the Python client."""
@@ -519,8 +527,8 @@ def test_async_epidata(self):
519527
Epidata.covidcast('src', 'sig', 'day', 'county', 20200414, '00000')]*12
520528
)
521529

530+
@fake_epidata_endpoint
522531
def test_async_epidata_fail(self):
523-
Epidata.BASE_URL = 'http://delphi_web_epidata/epidata/fake_api.php'
524532
with pytest.raises(ClientResponseError, match="404, message='Not Found'"):
525533
Epidata.async_epidata([
526534
{
@@ -532,4 +540,4 @@ def test_async_epidata_fail(self):
532540
'geo_value': '11111',
533541
'time_values': '20200414'
534542
}
535-
])
543+
])

0 commit comments

Comments
 (0)