Skip to content

Commit

Permalink
equivalent for the async client
Browse files Browse the repository at this point in the history
  • Loading branch information
atmorling committed Oct 4, 2024
1 parent e83f139 commit 9891d9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ecoscope/io/async_earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_asyncearthranger_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9891d9a

Please sign in to comment.