Skip to content

Commit 2ddaa27

Browse files
authored
Merge pull request #1865 from cmu-delphi/release/indicators_v0.3.42_utils_v0.3.17
Release covidcast-indicators 0.3.42
2 parents b2e1b0c + be246bf commit 2ddaa27

File tree

29 files changed

+335
-285
lines changed

29 files changed

+335
-285
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.3.41
2+
current_version = 0.3.42
33
commit = True
44
message = chore: bump covidcast-indicators to {new_version}
55
tag = False

_delphi_utils_python/.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.3.16
2+
current_version = 0.3.17
33
commit = True
44
message = chore: bump delphi_utils to {new_version}
55
tag = False

_delphi_utils_python/delphi_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
from .nancodes import Nans
1616
from .weekday import Weekday
1717

18-
__version__ = "0.3.16"
18+
__version__ = "0.3.17"

_delphi_utils_python/delphi_utils/validator/datafetcher.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ def get_geo_signal_combos(data_source):
111111
Cross references based on combinations reported available by COVIDcast metadata.
112112
"""
113113
# Maps data_source name with what's in the API, lists used in case of multiple names
114-
114+
meta_response = requests.get("https://api.covidcast.cmu.edu/epidata/covidcast/meta")
115+
meta_response.raise_for_status()
115116
source_signal_mappings = {i['source']:i['db_source'] for i in
116-
requests.get("https://api.covidcast.cmu.edu/epidata/covidcast/meta").json()}
117+
meta_response.json()}
117118
meta = covidcast.metadata()
118119
source_meta = meta[meta['data_source'] == data_source]
119120
# Need to convert np.records to tuples so they are hashable and can be used in sets and dicts.
@@ -139,6 +140,7 @@ def get_geo_signal_combos(data_source):
139140
epidata_signal = requests.get(
140141
"https://api.covidcast.cmu.edu/epidata/covidcast/meta",
141142
params={'signal': f"{src}:{sig}"})
143+
epidata_signal.raise_for_status()
142144
# Not an active signal
143145
active_status = [val['active'] for i in epidata_signal.json()
144146
for val in i['signals']]

_delphi_utils_python/delphi_utils/validator/run.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
when the module is run with `python -m delphi_utils.validator`.
66
"""
77
import argparse as ap
8+
import covidcast
89
from .. import read_params, get_structured_logger
910
from .validate import Validator
1011

@@ -17,6 +18,7 @@ def run_module():
1718
args = parser.parse_args()
1819
params = read_params()
1920
assert "validation" in params
21+
covidcast.use_api_key(params["validation"]["common"]["api_credentials"])
2022
dry_run_param = params["validation"]["common"].get("dry_run", False)
2123
params["validation"]["common"]["dry_run"] = args.dry_run or dry_run_param
2224
validator = Validator(params)

_delphi_utils_python/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
"pylint==2.8.3",
2020
"pytest",
2121
"pytest-cov",
22+
"requests-mock",
2223
"slackclient",
2324
"structlog",
2425
"xlrd"
2526
]
2627

2728
setup(
2829
name="delphi_utils",
29-
version="0.3.16",
30+
version="0.3.17",
3031
description="Shared Utility Functions for Indicators",
3132
long_description=long_description,
3233
long_description_content_type="text/markdown",

_delphi_utils_python/tests/validator/test_datafetcher.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
import mock
55
import numpy as np
66
import pandas as pd
7+
import pytest
8+
from requests.exceptions import HTTPError
9+
import requests_mock
710
from delphi_utils.validator.datafetcher import (FILENAME_REGEX,
811
make_date_filter,
912
get_geo_signal_combos,
1013
threaded_api_calls)
1114
from delphi_utils.validator.errors import ValidationFailure
1215

1316

17+
1418
class TestDataFetcher:
1519
"""Tests for various data fetching utilities."""
1620
def test_make_date_filter(self):
@@ -24,20 +28,34 @@ def test_make_date_filter(self):
2428
# Solution from https://stackoverflow.com/questions/15753390/
2529
#how-can-i-mock-requests-and-the-response
2630
def mocked_requests_get(*args, **kwargs):
31+
# TODO #1863: convert to requests_mock
2732
class MockResponse:
2833
def __init__(self, json_data, status_code):
2934
self.json_data = json_data
3035
self.status_code = status_code
3136

3237
def json(self):
3338
return self.json_data
39+
40+
def raise_for_status(self):
41+
if self.status_code != 200:
42+
raise HTTPError()
3443
if len(kwargs) == 0:
3544
return MockResponse([{'source': 'chng', 'db_source': 'chng'},
3645
{'source': 'covid-act-now', 'db_source': 'covid-act-now'}], 200)
3746
elif kwargs["params"] == {'signal': 'chng:inactive'}:
3847
return MockResponse([{"signals": [{"active": False}]}], 200)
3948
else:
4049
return MockResponse([{"signals": [{"active": True}]}], 200)
50+
51+
# the `kw` approach is needed here because otherwise pytest thinks the
52+
# requests_mock arg is supposed to be a fixture
53+
@requests_mock.Mocker(kw="mock_requests")
54+
def test_bad_api_key(self, **kwargs):
55+
kwargs["mock_requests"].get("https://api.covidcast.cmu.edu/epidata/covidcast/meta", status_code=429)
56+
with pytest.raises(HTTPError):
57+
get_geo_signal_combos("chng")
58+
4159
@mock.patch('requests.get', side_effect=mocked_requests_get)
4260
@mock.patch("covidcast.metadata")
4361
def test_get_geo_signal_combos(self, mock_metadata, mock_get):

ansible/templates/changehc-params-prod.json.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"validation": {
3838
"common": {
3939
"data_source": "chng",
40+
"api_credentials": "{{ validation_api_key }}",
4041
"span_length": 14,
4142
"min_expected_lag": {"all": "4"},
4243
"max_expected_lag": {"all": "6"},

ansible/templates/claims_hosp-params-prod.json.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"validation": {
2929
"common": {
3030
"data_source": "hospital-admissions",
31+
"api_credentials": "{{ validation_api_key }}",
3132
"span_length": 14,
3233
"min_expected_lag": {"all": "3"},
3334
"max_expected_lag": {"all": "4"},

ansible/templates/doctor_visits-params-prod.json.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"validation": {
2323
"common": {
2424
"data_source": "doctor-visits",
25+
"api_credentials": "{{ validation_api_key }}",
2526
"span_length": 14,
2627
"min_expected_lag": {"all": "3"},
2728
"max_expected_lag": {"all": "4"},

ansible/templates/dsew_community_profile-params-prod.json.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"validation": {
1919
"common": {
2020
"data_source": "dsew-cpr",
21+
"api_credentials": "{{ validation_api_key }}",
2122
"span_length": 14,
2223
"min_expected_lag": {"all": "3"},
2324
"max_expected_lag": {"all": "9"},

ansible/templates/google_symptoms-params-prod.json.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"indicator": {
77
"export_start_date": "2020-02-20",
88
"num_export_days": null,
9+
"api_credentials": "{{ google_symptoms_api_key }}",
910
"bigquery_credentials": {
1011
"type": "{{ google_symptoms_account_type }}",
1112
"project_id": "{{ google_symptoms_project_id }}",
@@ -22,6 +23,7 @@
2223
"validation": {
2324
"common": {
2425
"data_source": "google-symptoms",
26+
"api_credentials": "{{ validation_api_key }}",
2527
"validation_failure_dir": "./validation_failures",
2628
"span_length": 14,
2729
"min_expected_lag": {"all": "3"},

ansible/templates/hhs_hosp-params-prod.json.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"validation": {
77
"common": {
88
"data_source": "hhs",
9+
"api_credentials": "{{ validation_api_key }}",
910
"span_length": 14,
1011
"min_expected_lag": {"all": "1"},
1112
"max_expected_lag": {"all": "7"},

ansible/templates/quidel_covidtest-params-prod.json.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"validation": {
2626
"common": {
2727
"data_source": "quidel",
28+
"api_credentials": "{{ validation_api_key }}",
2829
"span_length": 14,
2930
"min_expected_lag": {"all": "5"},
3031
"max_expected_lag": {"all": "5"},

ansible/templates/sir_complainsalot-params-prod.json.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"log_filename": "/var/log/indicators/sircal.log",
33
"slack_token": "{{ sir_complainsalot_slack_token }}",
4+
"api_credentials": "{{ sir_complainsalot_api_key }}",
45
"sources": {
56
"doctor-visits": {
67
"max_age": 5,

ansible/vars.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pyenv_python_path: "/home/{{ runtime_user }}/.pyenv/versions/{{ python_version }
1414
#
1515
# Indicators variables
1616
#
17+
# Validation
18+
validation_api_key: "{{ vault_validator_api_key }}"
1719
# Google Health
1820
google_health_api_key: "{{ vault_google_health_api_key }}"
1921
delphi_aws_access_key_id: "{{ vault_delphi_aws_access_key_id }}"
@@ -52,6 +54,7 @@ doctor_visits_midas_password: "{{ vault_doctor_visits_midas_password }}"
5254
nchs_mortality_token: "{{ vault_nchs_mortality_token }}"
5355

5456
# SirCAL
57+
sir_complainsalot_api_key: "{{ vault_sir_complainsalot_api_key }}"
5558
sir_complainsalot_slack_token: "{{ vault_sir_complainsalot_slack_token }}"
5659

5760
# Survey
@@ -62,6 +65,7 @@ fb_survey_sftp_password: "{{ vault_fb_survey_sftp_password }}"
6265
fb_survey_sftp_user: "{{ vault_fb_survey_sftp_user }}"
6366

6467
## Google Symptoms
68+
google_symptoms_api_key: "{{ vault_google_symptoms_api_key }}"
6569
google_symptoms_account_type: "{{ vault_google_symptoms_account_type }}"
6670
google_symptoms_project_id: "{{ vault_google_symptoms_project_id }}"
6771
google_symptoms_private_key_id: "{{ vault_google_symptoms_private_key_id }}"

0 commit comments

Comments
 (0)