You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by bo...@apache.org on 2023/12/21 09:20:44 UTC
(streampipes) 02/02: fix(#2329): enable Python client to communicate with StreamPipes core in development mode
This is an automated email from the ASF dual-hosted git repository.
bossenti pushed a commit to branch 2329-python-client-throws-exception-on-connection
in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit ba95337c7d2d9486091151e86e9661a94c02a3bb
Author: bossenti <bo...@posteo.de>
AuthorDate: Thu Dec 21 09:59:03 2023 +0100
fix(#2329): enable Python client to communicate with StreamPipes core in development mode
---
.../streampipes/model/resource/version.py | 11 +++--
.../tests/client/test_versions.py | 48 ++++++++++++++++++++++
2 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/streampipes-client-python/streampipes/model/resource/version.py b/streampipes-client-python/streampipes/model/resource/version.py
index 0ec557321..cfb5f085b 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, Field, validator
from streampipes.model.resource.resource import Resource
@@ -41,4 +41,9 @@ 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 set_name(cls, backend_version):
+ # if there is no version returned by the backend, StreamPipes is run locally in development mode
+ return backend_version or "development"
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)