Skip to content

Commit

Permalink
apache#3042 added put method to Python client Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaakKrut committed Aug 20, 2024
1 parent 6cce352 commit 84d6082
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
20 changes: 20 additions & 0 deletions streampipes-client-python/streampipes/endpoint/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions streampipes-client-python/tests/client/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 84d6082

Please sign in to comment.