Skip to content

Commit 987d990

Browse files
committed
Final adjustments
1 parent 7bdf683 commit 987d990

File tree

9 files changed

+237
-170
lines changed

9 files changed

+237
-170
lines changed

integrations/acquisition/covidcast/test_covidcast_meta_caching.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# standard library
44
import json
55

6-
# third party
7-
import requests
8-
96
# first party
107
from delphi_utils import Nans
118
from delphi.epidata.common.covidcast_test_base import CovidcastTestBase
@@ -17,21 +14,10 @@
1714
'covidcast_meta_cache_updater'
1815
)
1916

20-
# use the local instance of the Epidata API
21-
BASE_URL = 'http://delphi_web_epidata/epidata'
22-
AUTH = ("epidata", "key")
23-
2417

2518
class CovidcastMetaCacheTests(CovidcastTestBase):
2619
"""Tests covidcast metadata caching."""
2720

28-
@staticmethod
29-
def _make_request():
30-
params = {'cached': 'true'}
31-
response = requests.get(f"{BASE_URL}/covidcast_meta", params=params, auth=AUTH)
32-
response.raise_for_status()
33-
return response.json()
34-
3521
def test_caching(self):
3622
"""Populate, query, cache, query, and verify the cache."""
3723

@@ -110,7 +96,7 @@ def test_caching(self):
11096
self._db._connection.commit()
11197

11298
# fetch the cached version (manually)
113-
epidata4 = self._make_request()
99+
epidata4 = self._make_request(endpoint="covidcast_meta", json=True, params={'cached': 'true'}, auth=self.epidata_client.auth, raise_for_status=True)
114100

115101
# make sure the cache was actually served
116102
self.assertEqual(epidata4, {
@@ -130,7 +116,7 @@ def test_caching(self):
130116
self._db._connection.commit()
131117

132118
# fetch the cached version (manually)
133-
epidata5 = self._make_request()
119+
epidata5 = self._make_request(endpoint="covidcast_meta", json=True, params={'cached': 'true'}, auth=self.epidata_client.auth, raise_for_status=True)
134120

135121
# make sure the cache was returned anyhow
136122
self.assertEqual(epidata4, epidata5)

integrations/server/test_api_keys.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
"""Integration tests for the API Keys"""
2-
import requests
3-
42
# first party
53
from delphi.epidata.common.delphi_test_base import DelphiTestBase
64

@@ -11,12 +9,6 @@ class APIKeysTets(DelphiTestBase):
119
def localSetUp(self):
1210
self.role_name = "cdc"
1311

14-
def _make_request(self, url: str = None, endpoint: str = None, params: dict = {}, auth: tuple = None):
15-
if not url:
16-
url = self.epidata_client.BASE_URL
17-
response = requests.get(f"{url}/{endpoint}", params=params, auth=auth)
18-
return response
19-
2012
def test_public_route(self):
2113
"""Test public route"""
2214
status_codes = set()
@@ -36,7 +28,7 @@ def test_no_multiples_data_source(self):
3628
}
3729
status_codes = set()
3830
for _ in range(10):
39-
status_codes.add(self._make_request(params=params, endpoint="covidcast").status_code)
31+
status_codes.add(self._make_request(params=params).status_code)
4032
self.assertEqual(status_codes, {200})
4133

4234
def test_no_multiples_source_signal(self):
@@ -50,7 +42,7 @@ def test_no_multiples_source_signal(self):
5042
}
5143
status_codes = set()
5244
for _ in range(10):
53-
status_codes.add(self._make_request(params=params, endpoint="covidcast").status_code)
45+
status_codes.add(self._make_request(params=params).status_code)
5446
self.assertEqual(status_codes, {200})
5547

5648
def test_multiples_allowed_signal_two_multiples(self):
@@ -64,7 +56,7 @@ def test_multiples_allowed_signal_two_multiples(self):
6456
}
6557
status_codes = set()
6658
for _ in range(10):
67-
status_codes.add(self._make_request(params=params, endpoint="covidcast").status_code)
59+
status_codes.add(self._make_request(params=params).status_code)
6860
self.assertEqual(status_codes, {200})
6961

7062
def test_multiples_non_allowed_signal(self):
@@ -78,7 +70,7 @@ def test_multiples_non_allowed_signal(self):
7870
}
7971
status_codes = set()
8072
for _ in range(10):
81-
status_codes.add(self._make_request(params=params, endpoint="covidcast").status_code)
73+
status_codes.add(self._make_request(params=params).status_code)
8274
self.assertEqual(status_codes, {200, 429})
8375

8476
def test_multiples_mixed_allowed_signal_two_multiples(self):
@@ -92,7 +84,7 @@ def test_multiples_mixed_allowed_signal_two_multiples(self):
9284
}
9385
status_codes = set()
9486
for _ in range(10):
95-
status_codes.add(self._make_request(params=params, endpoint="covidcast").status_code)
87+
status_codes.add(self._make_request(params=params).status_code)
9688
self.assertEqual(status_codes, {200, 429})
9789

9890
def test_multiples_allowed_signal_three_multiples(self):
@@ -106,7 +98,7 @@ def test_multiples_allowed_signal_three_multiples(self):
10698
}
10799
status_codes = set()
108100
for _ in range(10):
109-
status_codes.add(self._make_request(params=params, endpoint="covidcast").status_code)
101+
status_codes.add(self._make_request(params=params).status_code)
110102
self.assertEqual(status_codes, {401})
111103

112104
def test_multiples_mixed_allowed_signal_three_multiples(self):
@@ -120,7 +112,7 @@ def test_multiples_mixed_allowed_signal_three_multiples(self):
120112
}
121113
status_codes = set()
122114
for _ in range(10):
123-
status_codes.add(self._make_request(params=params, endpoint="covidcast").status_code)
115+
status_codes.add(self._make_request(params=params).status_code)
124116
self.assertEqual(status_codes, {401})
125117

126118
def test_multiples_mixed_allowed_signal_api_key(self):
@@ -135,7 +127,7 @@ def test_multiples_mixed_allowed_signal_api_key(self):
135127
status_codes = set()
136128
for _ in range(10):
137129
status_codes.add(
138-
self._make_request(params=params, auth=self.epidata_client.auth, endpoint="covidcast").status_code
130+
self._make_request(params=params, auth=self.epidata_client.auth).status_code
139131
)
140132
self.assertEqual(status_codes, {200})
141133

@@ -151,7 +143,7 @@ def test_multiples_allowed_signal_api_key(self):
151143
status_codes = set()
152144
for _ in range(10):
153145
status_codes.add(
154-
self._make_request(params=params, auth=self.epidata_client.auth, endpoint="covidcast").status_code
146+
self._make_request(params=params, auth=self.epidata_client.auth).status_code
155147
)
156148
self.assertEqual(status_codes, {200})
157149

@@ -167,7 +159,7 @@ def test_no_multiples_allowed_signal_api_key(self):
167159
status_codes = set()
168160
for _ in range(10):
169161
status_codes.add(
170-
self._make_request(params=params, auth=self.epidata_client.auth, endpoint="covidcast").status_code
162+
self._make_request(params=params, auth=self.epidata_client.auth).status_code
171163
)
172164
self.assertEqual(status_codes, {200})
173165

@@ -184,7 +176,7 @@ def test_no_multiples_allowed_signal_bad_api_key(self):
184176
for _ in range(10):
185177
status_codes.add(
186178
self._make_request(
187-
params=params, auth=("bad_key", "bad_email"), endpoint="covidcast"
179+
params=params, auth=("bad_key", "bad_email")
188180
).status_code
189181
)
190182
self.assertEqual(status_codes, {200})

0 commit comments

Comments
 (0)