Skip to content

Commit d0d0f03

Browse files
committed
Add enhydris_api_client.put_timeseries() (fixes DEV-130)
1 parent e2bd1b9 commit d0d0f03

10 files changed

Lines changed: 36 additions & 6 deletions

File tree

docs/enhydris_api_client.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ Reference
6767
.. method:: list_timeseries(self, station_id, timeseries_group_id)
6868
get_timeseries(self, station_id, timeseries_group_id, timeseries_id)
6969
post_timeseries(self, station_id, timeseries_group_id, data)
70+
put_timeseries(self, station_id, timeseries_group_id, timeseries_id, data)
7071
delete_timeseries(self, station_id, timeseries_group_id, timeseries_id)
7172

72-
Methods that create, retrieve or delete time series. Similar to
73-
the ones for station. :meth:`~EnhydrisApiClient.list_timeseries`
74-
returns a list of dictionaries.
73+
Methods that create, retrieve, update or delete time series.
74+
Similar to the ones for station.
75+
:meth:`~EnhydrisApiClient.list_timeseries` returns a list of
76+
dictionaries.
7577

7678
.. method:: read_tsdata(self, station_id, timeseries_group_id, timeseries_id, start_date=None, end_date=None, timezone=None)
7779
.post_tsdata(self, station_id, timeseries_group_id, timeseries_id, ts)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ skip = ["_version.py"]
7979
extra_standard_library = ["cpython", "libc"]
8080

8181
[tool.pyright]
82-
ignore = ["osgeo.*", "django.contrib.gis.*"]
82+
ignore = ["osgeo.*"]

src/enhydris_api_client/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,23 @@ def post_timeseries(
244244
self.check_response()
245245
return self.response.json()["id"]
246246

247+
def put_timeseries(
248+
self,
249+
station_id: int,
250+
timeseries_group_id: int,
251+
timeseries_id: int,
252+
data: JSONDict,
253+
) -> None:
254+
self.response = self.session.put(
255+
urljoin(
256+
self.base_url,
257+
f"api/stations/{station_id}/timeseriesgroups/{timeseries_group_id}/"
258+
f"timeseries/{timeseries_id}/",
259+
),
260+
data=data,
261+
)
262+
self.check_response()
263+
247264
def delete_timeseries(
248265
self, station_id: int, timeseries_group_id: int, timeseries_id: int
249266
) -> None:

src/evaporation/py.typed

Whitespace-only changes.

src/hspatial/py.typed

Whitespace-only changes.

src/htimeseries/py.typed

Whitespace-only changes.

src/rocc/py.typed

Whitespace-only changes.

src/textbisect/py.typed

Whitespace-only changes.

tests/enhydris_api_client/test_timeseries.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ def test_returns_id(self) -> None:
8787
self.assertEqual(self.data, 43)
8888

8989

90+
@mock_session()
91+
class PutTimeseriesTestCase(TestCase):
92+
def test_makes_request(self, m: mock.MagicMock) -> None:
93+
client = EnhydrisApiClient("https://mydomain.com")
94+
client.put_timeseries(41, 42, 43, data={"location": "Syria"})
95+
m.return_value.put.assert_called_once_with(
96+
"https://mydomain.com/api/stations/41/timeseriesgroups/42/timeseries/43/",
97+
data={"location": "Syria"},
98+
)
99+
100+
90101
class FailedPostTimeseriesTestCase(TestCase):
91102
@mock_session(**{"post.return_value.status_code": 404})
92103
def test_raises_exception_on_error(self, m: mock.MagicMock) -> None:

tests/hspatial/test_hspatial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import numpy as np
1515
import pandas as pd
16-
from django.contrib.gis.gdal import GDALRaster # type: ignore
16+
from django.contrib.gis.gdal import GDALRaster
1717
from django.contrib.gis.geos import Point as GeoDjangoPoint
1818
from osgeo import gdal, ogr, osr
1919

@@ -154,7 +154,7 @@ def setUp(self) -> None:
154154
)
155155

156156
# Our grid represents a 70x150m area, lower-left co-ordinates (0, 0).
157-
self.dataset.geotransform = (0, 10, 0, 70, 0, -10)
157+
self.dataset.geotransform = [0, 10, 0, 70, 0, -10]
158158

159159
self.target_band = self.dataset.bands[1]
160160

0 commit comments

Comments
 (0)