Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbourbeau committed Oct 13, 2023
1 parent fbaad1e commit 270201d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion earthaccess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any

from .api import (
auth_environ,
collection_query,
download,
get_fsspec_https_session,
Expand All @@ -13,7 +14,6 @@
open,
search_data,
search_datasets,
auth_environ,
)
from .auth import Auth
from .search import DataCollections, DataGranules
Expand Down
5 changes: 4 additions & 1 deletion earthaccess/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,11 @@ def get_edl_token() -> str:
token = earthaccess.__auth__.token
return token


def auth_environ() -> Dict[str, str]:
auth = earthaccess.__auth__
if not auth.authenticated:
raise RuntimeError("`auth_environ()` requires you to first authenticate with `earthaccess.login()`")
raise RuntimeError(
"`auth_environ()` requires you to first authenticate with `earthaccess.login()`"
)
return {"EARTHDATA_USERNAME": auth.username, "EARTHDATA_PASSWORD": auth.password}
9 changes: 7 additions & 2 deletions tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ def test_earthaccess_api_can_download_granules():
assertions.assertIsInstance(files, list)
shutil.rmtree(local_path)


def test_auth_environ():
environ = earthaccess.auth_environ()
assert environ == {"EARTHDATA_USERNAME": os.environ["EARTHDATA_USERNAME"], "EARTHDATA_PASSWORD": os.environ["EARTHDATA_PASSWORD"]}
assert environ == {
"EARTHDATA_USERNAME": os.environ["EARTHDATA_USERNAME"],
"EARTHDATA_PASSWORD": os.environ["EARTHDATA_PASSWORD"],
}


def test_auth_environ_raises(monkeypatch):
monkeypatch.setattr(earthaccess.__auth__, "authenticated", False)
with pytest.raises(RuntimeError, match="authenticate"):
earthaccess.auth_environ()
earthaccess.auth_environ()

0 comments on commit 270201d

Please sign in to comment.