This is an automated email from the ASF dual-hosted git repository.

bossenti pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new 75714c4ca fix(#2329): python client throws exception on connection 
(#2360)
75714c4ca is described below

commit 75714c4ca246969bb8a5e8145d58914219070ac5
Author: Tim <[email protected]>
AuthorDate: Thu Dec 21 16:22:57 2023 +0100

    fix(#2329): python client throws exception on connection (#2360)
    
    * fix(#2329): remove trailing whitespaces in URLs
    
    * fix(#2329): enable Python client to communicate with StreamPipes core in 
development mode
    
    * style: adapt formatting
    
    * style: adapt formatting
---
 streampipes-client-python/Makefile                 |  1 -
 .../streampipes/endpoint/endpoint.py               | 11 +++--
 .../streampipes/model/resource/version.py          | 14 +++++--
 .../tests/client/test_endpoint.py                  |  2 +-
 .../tests/client/test_versions.py                  | 48 ++++++++++++++++++++++
 5 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/streampipes-client-python/Makefile 
b/streampipes-client-python/Makefile
index 682c6c56d..dc8d5b7ac 100644
--- a/streampipes-client-python/Makefile
+++ b/streampipes-client-python/Makefile
@@ -17,7 +17,6 @@
 
 .PHONY: check
 check: mypy lint unit-tests
-       poetry run interrogate -c pyproject.toml
 
 .PHONY: doc
 doc:
diff --git a/streampipes-client-python/streampipes/endpoint/endpoint.py 
b/streampipes-client-python/streampipes/endpoint/endpoint.py
index fa96df79a..b3572d9d1 100644
--- a/streampipes-client-python/streampipes/endpoint/endpoint.py
+++ b/streampipes-client-python/streampipes/endpoint/endpoint.py
@@ -205,9 +205,12 @@ class APIEndpoint(Endpoint):
             The specified resource as an instance of the corresponding model 
class.
         """
 
-        response = self._make_request(
-            request_method=self._parent_client.request_session.get, 
url=f"{self.build_url()}/{identifier}"
-        )
+        query_url = f"{self.build_url()}"
+
+        if identifier:
+            query_url += f"/{identifier}"
+
+        response = 
self._make_request(request_method=self._parent_client.request_session.get, 
url=query_url)
 
         return self._container_cls._resource_cls()(**response.json())
 
@@ -226,7 +229,7 @@ class APIEndpoint(Endpoint):
 
         self._make_request(
             request_method=self._parent_client.request_session.post,
-            url=f"{self.build_url()}/",
+            url=f"{self.build_url()}",
             data=json.dumps(resource.to_dict(use_source_names=True)),
             headers={"Content-type": "application/json"},
         )
diff --git a/streampipes-client-python/streampipes/model/resource/version.py 
b/streampipes-client-python/streampipes/model/resource/version.py
index 0ec557321..734955c13 100644
--- a/streampipes-client-python/streampipes/model/resource/version.py
+++ b/streampipes-client-python/streampipes/model/resource/version.py
@@ -19,9 +19,9 @@ __all__ = [
     "Version",
 ]
 
-from typing import Dict
+from typing import Dict, Optional
 
-from pydantic import StrictStr
+from pydantic import StrictStr, validator
 
 from streampipes.model.resource.resource import Resource
 
@@ -41,4 +41,12 @@ class Version(Resource):
         """
         return self.to_dict(use_source_names=False)
 
-    backend_version: StrictStr
+    backend_version: Optional[StrictStr] = None
+
+    @validator("backend_version", always=True)
+    def validate_backend_version(cls, backend_version):
+        """Validates the backend version of the StreamPipes.
+        Sets 'development' if none is returned since this the behavior of 
StreamPipes backend running
+        in development mode.
+        """
+        return backend_version or "development"
diff --git a/streampipes-client-python/tests/client/test_endpoint.py 
b/streampipes-client-python/tests/client/test_endpoint.py
index c610339ee..2f63a781e 100644
--- a/streampipes-client-python/tests/client/test_endpoint.py
+++ b/streampipes-client-python/tests/client/test_endpoint.py
@@ -235,7 +235,7 @@ class TestStreamPipesEndpoints(TestCase):
         client.dataStreamApi.post(DataStream(**self.data_stream_get))
 
         http_session_mock.post.assert_called_with(
-            url="https://localhost:80/streampipes-backend/api/v2/streams/";,
+            url="https://localhost:80/streampipes-backend/api/v2/streams";,
             data=json.dumps(self.data_stream_get),
             headers={"Content-type": "application/json"},
         )
diff --git a/streampipes-client-python/tests/client/test_versions.py 
b/streampipes-client-python/tests/client/test_versions.py
new file mode 100644
index 000000000..0dc78a3f3
--- /dev/null
+++ b/streampipes-client-python/tests/client/test_versions.py
@@ -0,0 +1,48 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from unittest import TestCase
+from unittest.mock import patch, MagicMock, call
+
+from streampipes.client import StreamPipesClient
+from streampipes.client.config import StreamPipesClientConfig
+from streampipes.client.credential_provider import StreamPipesApiKeyCredentials
+
+
+class TestVersions(TestCase):
+
+    @patch("streampipes.client.client.Session", autospec=True)
+    def test_get_development_version(self, http_session: MagicMock) -> None:
+        http_session_mock = MagicMock()
+        http_session_mock.get.return_value.json.return_value = 
{"backendVersion": None}
+        http_session.return_value = http_session_mock
+
+        client = StreamPipesClient(
+            client_config=StreamPipesClientConfig(
+                
credential_provider=StreamPipesApiKeyCredentials(username="user", 
api_key="key"),
+                host_address="localhost"
+            )
+        )
+
+        result = client.versionApi.get("")
+
+        http_session.assert_has_calls(
+            
[call().get(url="https://localhost:80/streampipes-backend/api/v2/info/versions";)],
+            any_order=True
+        )
+
+        self.assertEqual("development", result.backend_version)

Reply via email to