From e2c66c91cd6465e9ef429ee7045cbcf5830b5ca2 Mon Sep 17 00:00:00 2001 From: Scott Henderson Date: Fri, 22 Nov 2024 17:53:13 +0100 Subject: [PATCH] better maxar authentication handling --- pixi.lock | 2 +- src/coincident/search/stac.py | 5 +++++ tests/test_search.py | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pixi.lock b/pixi.lock index a25054e..c9035d5 100644 --- a/pixi.lock +++ b/pixi.lock @@ -3407,7 +3407,7 @@ packages: requires_python: '>=3.8' - kind: pypi name: coincident - version: 0.1.dev33+g478116f.d20241103 + version: 0.1.dev34+g878d275 path: . sha256: 6633999f089774b476b998b82343a056f3e34bbdcd675946c74922e8a2b3a042 requires_dist: diff --git a/src/coincident/search/stac.py b/src/coincident/search/stac.py index 0f5fabc..410cfbb 100644 --- a/src/coincident/search/stac.py +++ b/src/coincident/search/stac.py @@ -25,6 +25,11 @@ except maxar_platform.session.NoSessionCredentials: msg_noauth = "Unable to authenticate with Maxar API. Please set MAXAR_API_KEY environment variable." warnings.warn(msg_noauth, stacklevel=2) +except maxar_platform.exceptions.UnAuthorizedException: + msg_noauth = ( + "Unable to authenticate with Maxar API. Please check MAXAR_API_KEY is valid." + ) + warnings.warn(msg_noauth, stacklevel=2) def _filter_assets(assets: gpd.GeoDataFrame) -> dict[str, str]: diff --git a/tests/test_search.py b/tests/test_search.py index b7611e7..911d7b7 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -9,6 +9,13 @@ # Decorate tests requiring internet (slow & flaky) network = pytest.mark.network +try: + import maxar_platform.discovery # noqa: F401 +except: # noqa: E722 + maxar_authenticated = pytest.mark.skip( + reason="unable to authenticate with maxar API" + ) + @pytest.fixture def aoi(): @@ -75,6 +82,7 @@ def test_cascading_search(aoi): # TODO: add more assertions / tests for this section @network +@maxar_authenticated @pytest.mark.filterwarnings("ignore:Server does not conform") def test_maxar_search(aoi): gf = coincident.search.search( @@ -91,6 +99,7 @@ def test_maxar_search(aoi): @network +@maxar_authenticated def test_maxar_large_aoi(large_aoi): gf = coincident.search.search( dataset="maxar",