Skip to content

Commit

Permalink
feat: add version api & test (#44)
Browse files Browse the repository at this point in the history
* feat: add version api & test

* delete print info
ChenZiHong-Gavin authored May 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c415e30 commit 326d66d
Showing 4 changed files with 95 additions and 0 deletions.
40 changes: 40 additions & 0 deletions hugegraph-python-client/src/pyhugegraph/api/version.py
Original file line number Diff line number Diff line change
@@ -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 {}
6 changes: 6 additions & 0 deletions hugegraph-python-client/src/pyhugegraph/client.py
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions hugegraph-python-client/src/tests/api/test_version.py
Original file line number Diff line number Diff line change
@@ -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'])
1 change: 1 addition & 0 deletions hugegraph-python-client/src/tests/client_utils.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 326d66d

Please sign in to comment.