diff --git a/earthaccess/__init__.py b/earthaccess/__init__.py index 05e2192c..ef3715d0 100644 --- a/earthaccess/__init__.py +++ b/earthaccess/__init__.py @@ -2,6 +2,7 @@ from typing import Any from .api import ( + auth_environ, collection_query, download, get_fsspec_https_session, @@ -13,7 +14,6 @@ open, search_data, search_datasets, - auth_environ, ) from .auth import Auth from .search import DataCollections, DataGranules diff --git a/earthaccess/api.py b/earthaccess/api.py index 9a5594b3..7d8d1ca8 100644 --- a/earthaccess/api.py +++ b/earthaccess/api.py @@ -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} diff --git a/tests/integration/test_api.py b/tests/integration/test_api.py index 0eb6a59b..e762dc7a 100644 --- a/tests/integration/test_api.py +++ b/tests/integration/test_api.py @@ -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() \ No newline at end of file + earthaccess.auth_environ()