From d9a37de55df5d6f216e465d5d29f4d76461f8f5c Mon Sep 17 00:00:00 2001 From: chenzihong <522023320011@smail.nju.edu.cn> Date: Mon, 20 May 2024 11:32:06 +0800 Subject: [PATCH 1/2] feat: add version api & test --- .../src/pyhugegraph/api/version.py | 41 ++++++++++++++++ .../src/pyhugegraph/client.py | 6 +++ .../src/tests/api/test_version.py | 48 +++++++++++++++++++ .../src/tests/client_utils.py | 1 + 4 files changed, 96 insertions(+) create mode 100644 hugegraph-python-client/src/pyhugegraph/api/version.py create mode 100644 hugegraph-python-client/src/tests/api/test_version.py diff --git a/hugegraph-python-client/src/pyhugegraph/api/version.py b/hugegraph-python-client/src/pyhugegraph/api/version.py new file mode 100644 index 000000000..2edb44572 --- /dev/null +++ b/hugegraph-python-client/src/pyhugegraph/api/version.py @@ -0,0 +1,41 @@ +# 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 pyhugegraph.api.common import HugeParamsBase +from pyhugegraph.utils.exceptions import NotFoundError +from pyhugegraph.utils.huge_requests import HugeSession +from pyhugegraph.utils.util import check_if_success + + +class VersionManager(HugeParamsBase): + def __init__(self, graph_instance): + super().__init__(graph_instance) + self.__session = HugeSession.new_session() + + def close(self): + if self.__session: + self.__session.close() + + def version(self): + url = f"{self._host}/versions" + print(url) + response = self.__session.get( + url, auth=self._auth, headers=self._headers, timeout=self._timeout + ) + if check_if_success(response, NotFoundError(response.content)): + return response.json() + return {} diff --git a/hugegraph-python-client/src/pyhugegraph/client.py b/hugegraph-python-client/src/pyhugegraph/client.py index 2398f7fa4..b83341583 100644 --- a/hugegraph-python-client/src/pyhugegraph/client.py +++ b/hugegraph-python-client/src/pyhugegraph/client.py @@ -24,6 +24,7 @@ from pyhugegraph.api.task import TaskManager from pyhugegraph.api.traverser import TraverserManager from pyhugegraph.api.variable import VariableManager +from pyhugegraph.api.version import VersionManager from pyhugegraph.structure.graph_instance import GraphInstance @@ -40,6 +41,7 @@ def __init__(self, ip, port, graph, user, pwd, timeout=10): self._task = None self._metrics = None self._traverser = None + self._version = None def schema(self): self._schema = self._schema or SchemaManager(self._graph_instance) @@ -76,3 +78,7 @@ def metrics(self): def traverser(self): self._traverser = self._traverser or TraverserManager(self._graph_instance) return self._traverser + + def version(self): + self._version = self._version or VersionManager(self._graph_instance) + return self._version diff --git a/hugegraph-python-client/src/tests/api/test_version.py b/hugegraph-python-client/src/tests/api/test_version.py new file mode 100644 index 000000000..1d6325dfd --- /dev/null +++ b/hugegraph-python-client/src/tests/api/test_version.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. + +import unittest + +from tests.client_utils import ClientUtils + + +class TestVersion(unittest.TestCase): + client = None + version = None + + @classmethod + def setUpClass(cls): + cls.client = ClientUtils() + cls.version = cls.client.version + + @classmethod + def tearDownClass(cls): + cls.client.clear_graph_all_data() + + def setUp(self): + self.client.clear_graph_all_data() + + def tearDown(self): + pass + + def test_version(self): + version = self.version.version() + self.assertIsInstance(version, dict) + self.assertIn("version", version['versions']) + self.assertIn("core", version['versions']) + self.assertIn("gremlin", version['versions']) + self.assertIn("api", version['versions']) diff --git a/hugegraph-python-client/src/tests/client_utils.py b/hugegraph-python-client/src/tests/client_utils.py index cc3c108eb..12b35db17 100644 --- a/hugegraph-python-client/src/tests/client_utils.py +++ b/hugegraph-python-client/src/tests/client_utils.py @@ -41,6 +41,7 @@ def __init__(self): self.task = self.client.task() self.metrics = self.client.metrics() self.traverser = self.client.traverser() + self.version = self.client.version() def init_property_key(self): schema = self.schema From e2ef2a53260aa6188f217854c3369be26e4d6f90 Mon Sep 17 00:00:00 2001 From: chenzihong <522023320011@smail.nju.edu.cn> Date: Mon, 20 May 2024 11:38:34 +0800 Subject: [PATCH 2/2] delete print info --- hugegraph-python-client/src/pyhugegraph/api/version.py | 1 - 1 file changed, 1 deletion(-) diff --git a/hugegraph-python-client/src/pyhugegraph/api/version.py b/hugegraph-python-client/src/pyhugegraph/api/version.py index 2edb44572..67fc5a52d 100644 --- a/hugegraph-python-client/src/pyhugegraph/api/version.py +++ b/hugegraph-python-client/src/pyhugegraph/api/version.py @@ -32,7 +32,6 @@ def close(self): def version(self): url = f"{self._host}/versions" - print(url) response = self.__session.get( url, auth=self._auth, headers=self._headers, timeout=self._timeout )