Skip to content

Commit 3dea05e

Browse files
committed
refactor: make auth function private
1 parent b8f24dd commit 3dea05e

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

epidatpy/_auth.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import os
22
import warnings
3-
from typing import Optional
43

54

6-
def get_api_key() -> Optional[str]:
7-
key = os.environ.get("DELPHI_EPIDATA_KEY", None)
5+
def _get_api_key() -> str:
6+
key = os.environ.get("DELPHI_EPIDATA_KEY", "")
87

98
if not key:
109
warnings.warn(

epidatpy/request.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from requests.auth import HTTPBasicAuth
1515
from tenacity import retry, stop_after_attempt
1616

17-
from ._auth import get_api_key
17+
from ._auth import _get_api_key
1818
from ._constants import BASE_URL, HTTP_HEADERS
1919
from ._covidcast import CovidcastDataSources, define_covidcast_fields
2020
from ._endpoints import AEpiDataEndpoints
@@ -41,7 +41,7 @@ def _request_with_retry(
4141
stream: bool = False,
4242
) -> Response:
4343
"""Make request with a retry if an exception is thrown."""
44-
basic_auth = HTTPBasicAuth("epidata", get_api_key())
44+
basic_auth = HTTPBasicAuth("epidata", _get_api_key())
4545

4646
def call_impl(s: Session) -> Response:
4747
res = s.get(url, params=params, headers=HTTP_HEADERS, stream=stream, auth=basic_auth)

tests/test_auth.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from pytest import warns, MonkeyPatch
1+
from pytest import MonkeyPatch, warns
22

3-
from epidatpy import get_api_key
3+
from epidatpy._auth import _get_api_key
44

55

66
def test_get_api_key(monkeypatch: MonkeyPatch) -> None:
77
with monkeypatch.context() as m:
88
m.setenv("DELPHI_EPIDATA_KEY", "test")
9-
assert get_api_key() == "test"
9+
assert _get_api_key() == "test"
1010
m.delenv("DELPHI_EPIDATA_KEY")
1111
with warns(UserWarning):
12-
assert get_api_key() is None
12+
assert _get_api_key() == ""

0 commit comments

Comments
 (0)