Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -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


Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Up @@ -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
Expand Down