diff --git a/ecoscope/io/async_earthranger.py b/ecoscope/io/async_earthranger.py index ecf1b901..21e56681 100644 --- a/ecoscope/io/async_earthranger.py +++ b/ecoscope/io/async_earthranger.py @@ -17,7 +17,7 @@ class AsyncEarthRangerIO(AsyncERClient): - def __init__(self, sub_page_size=4000, tcp_limit=5, **kwargs): + def __init__(self, sub_page_size=4000, tcp_limit=5, existing_session=None, **kwargs): if "server" in kwargs: server = kwargs.pop("server") kwargs["service_root"] = f"{server}/api/v1.0" @@ -30,6 +30,9 @@ def __init__(self, sub_page_size=4000, tcp_limit=5, **kwargs): kwargs["client_id"] = kwargs.get("client_id", "das_web_client") super().__init__(**kwargs) + if existing_session is not None: + self.auth = existing_session + async def get_sources( self, manufacturer_id=None, diff --git a/tests/test_asyncearthranger_io.py b/tests/test_asyncearthranger_io.py index 8eafb57d..5fb8782a 100644 --- a/tests/test_asyncearthranger_io.py +++ b/tests/test_asyncearthranger_io.py @@ -251,3 +251,14 @@ async def test_display_map(er_io_async): await er_io_async.get_event_type_display_name(event_type="shot_rep", event_property="shotrep_timeofshot") == "Time when shot was heard" ) + + +@pytest.mark.asyncio +async def test_existing_session(er_io_async): + await er_io_async.login() + new_client = ecoscope.io.AsyncEarthRangerIO( + service_root=er_io_async.service_root, token_url=er_io_async.token_url, existing_session=er_io_async.auth + ) + + patrols = await new_client.get_patrols_dataframe() + assert not patrols.empty