diff --git a/streampipes-client-python/streampipes/endpoint/endpoint.py b/streampipes-client-python/streampipes/endpoint/endpoint.py index 2c491c6dd1..8f5d0d18b4 100644 --- a/streampipes-client-python/streampipes/endpoint/endpoint.py +++ b/streampipes-client-python/streampipes/endpoint/endpoint.py @@ -236,6 +236,26 @@ def post(self, resource: Resource) -> None: headers={"Content-type": "application/json"}, ) + def put(self, resource: Resource) -> None: + """Allows to put a resource to the StreamPipes API. + + Parameters + ---------- + resource: Resource + The resource to be updated. + + Returns + ------- + None + """ + + self._make_request( + request_method=self._parent_client.request_session.put, + url=f"{self.build_url()}", + data=json.dumps(resource.to_dict(use_source_names=True)), + headers={"Content-type": "application/json"}, + ) + class MessagingEndpoint(Endpoint): """Abstract implementation of a StreamPipes messaging endpoint. diff --git a/streampipes-client-python/tests/client/test_endpoint.py b/streampipes-client-python/tests/client/test_endpoint.py index 69ab569b8d..a7d1dab224 100644 --- a/streampipes-client-python/tests/client/test_endpoint.py +++ b/streampipes-client-python/tests/client/test_endpoint.py @@ -241,6 +241,29 @@ def test_endpoint_post(self, server_version: MagicMock, http_session: MagicMock) headers={"Content-type": "application/json"}, ) + @patch("streampipes.client.client.Session", autospec=True) + @patch("streampipes.client.client.StreamPipesClient._get_server_version", autospec=True) + def test_endpoint_put(self, server_version: MagicMock, http_session: MagicMock): + http_session_mock = MagicMock() + http_session.return_value = http_session_mock + + server_version.return_value = {"backendVersion": "0.x.y"} + + client = StreamPipesClient( + client_config=StreamPipesClientConfig( + credential_provider=StreamPipesApiKeyCredentials(username="user", api_key="key"), + host_address="localhost", + ) + ) + + client.dataStreamApi.put(DataStream(**self.data_stream_get)) + + http_session_mock.put.assert_called_with( + url="https://localhost:80/streampipes-backend/api/v2/streams", + data=json.dumps(self.data_stream_get), + headers={"Content-type": "application/json"}, + ) + @patch("streampipes.client.client.Session", autospec=True) @patch("streampipes.client.client.StreamPipesClient._get_server_version", autospec=True) def test_endpoint_data_stream_happy_path(self, server_version: MagicMock, http_session: MagicMock):