Skip to content

Commit 326d66d

Browse files
feat: add version api & test (#44)
* feat: add version api & test * delete print info
1 parent c415e30 commit 326d66d

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from pyhugegraph.api.common import HugeParamsBase
19+
from pyhugegraph.utils.exceptions import NotFoundError
20+
from pyhugegraph.utils.huge_requests import HugeSession
21+
from pyhugegraph.utils.util import check_if_success
22+
23+
24+
class VersionManager(HugeParamsBase):
25+
def __init__(self, graph_instance):
26+
super().__init__(graph_instance)
27+
self.__session = HugeSession.new_session()
28+
29+
def close(self):
30+
if self.__session:
31+
self.__session.close()
32+
33+
def version(self):
34+
url = f"{self._host}/versions"
35+
response = self.__session.get(
36+
url, auth=self._auth, headers=self._headers, timeout=self._timeout
37+
)
38+
if check_if_success(response, NotFoundError(response.content)):
39+
return response.json()
40+
return {}

hugegraph-python-client/src/pyhugegraph/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from pyhugegraph.api.task import TaskManager
2525
from pyhugegraph.api.traverser import TraverserManager
2626
from pyhugegraph.api.variable import VariableManager
27+
from pyhugegraph.api.version import VersionManager
2728
from pyhugegraph.structure.graph_instance import GraphInstance
2829

2930

@@ -40,6 +41,7 @@ def __init__(self, ip, port, graph, user, pwd, timeout=10):
4041
self._task = None
4142
self._metrics = None
4243
self._traverser = None
44+
self._version = None
4345

4446
def schema(self):
4547
self._schema = self._schema or SchemaManager(self._graph_instance)
@@ -76,3 +78,7 @@ def metrics(self):
7678
def traverser(self):
7779
self._traverser = self._traverser or TraverserManager(self._graph_instance)
7880
return self._traverser
81+
82+
def version(self):
83+
self._version = self._version or VersionManager(self._graph_instance)
84+
return self._version
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
import unittest
19+
20+
from tests.client_utils import ClientUtils
21+
22+
23+
class TestVersion(unittest.TestCase):
24+
client = None
25+
version = None
26+
27+
@classmethod
28+
def setUpClass(cls):
29+
cls.client = ClientUtils()
30+
cls.version = cls.client.version
31+
32+
@classmethod
33+
def tearDownClass(cls):
34+
cls.client.clear_graph_all_data()
35+
36+
def setUp(self):
37+
self.client.clear_graph_all_data()
38+
39+
def tearDown(self):
40+
pass
41+
42+
def test_version(self):
43+
version = self.version.version()
44+
self.assertIsInstance(version, dict)
45+
self.assertIn("version", version['versions'])
46+
self.assertIn("core", version['versions'])
47+
self.assertIn("gremlin", version['versions'])
48+
self.assertIn("api", version['versions'])

hugegraph-python-client/src/tests/client_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def __init__(self):
4141
self.task = self.client.task()
4242
self.metrics = self.client.metrics()
4343
self.traverser = self.client.traverser()
44+
self.version = self.client.version()
4445

4546
def init_property_key(self):
4647
schema = self.schema

0 commit comments

Comments
 (0)