feat: add version api & test (#44)
* feat: add version api & test
* delete print info
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 0000000..67fc5a5
--- /dev/null
+++ b/hugegraph-python-client/src/pyhugegraph/api/version.py
@@ -0,0 +1,40 @@
+# 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"
+ 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 2398f7f..b833415 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 @@
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 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 0000000..1d6325d
--- /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 cc3c108..12b35db 100644
--- a/hugegraph-python-client/src/tests/client_utils.py
+++ b/hugegraph-python-client/src/tests/client_utils.py
@@ -41,6 +41,7 @@
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