Skip to content

Commit

Permalink
Create source providers (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Wu authored Dec 19, 2024
1 parent fbb36b5 commit d2a851f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
32 changes: 31 additions & 1 deletion ecoscope/io/earthranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
dataframe_to_dict,
filter_bad_geojson,
format_iso_time,
pack_columns,
to_gdf,
to_hex,
pack_columns,
)


Expand Down Expand Up @@ -1040,6 +1040,36 @@ def post_source(
response = self._post("sources", payload=payload)
return pd.DataFrame([response])

def post_sourceproviders(
self,
provider_key: str,
display_name: str,
additional: typing.Dict = {},
**kwargs,
) -> pd.DataFrame:
"""
Parameters
----------
provider_key
display_name
Returns
-------
pd.DataFrame
"""

payload = {
"provider_key": provider_key,
"display_name": display_name,
"additional": additional,
}

if kwargs:
payload.update(kwargs)

response = self._post("sourceproviders", payload=payload)
return pd.DataFrame([response])

def post_subject(
self,
subject_name: str,
Expand Down
10 changes: 8 additions & 2 deletions tests/test_earthranger_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import pandas as pd
import pytest
import pytz
from erclient import ERClientException
from shapely.geometry import Point

import ecoscope
from erclient import ERClientException

from ecoscope.io.earthranger import EarthRangerIO
from ecoscope.io.earthranger_utils import TIME_COLS

Expand Down Expand Up @@ -205,6 +204,13 @@ def test_get_patrol_events_empty(patrols_mock, er_io):
assert events.empty


def test_post_sourceproviders(er_io):
response = er_io.post_sourceproviders(provider_key="test_provider_key", display_name="Test Provider Key")
assert "id" in response
assert "provider_key" in response
assert "display_name" in response


def test_post_observations(er_io):
observations = gpd.GeoDataFrame.from_dict(
[
Expand Down

0 comments on commit d2a851f

Please sign in to comment.