Skip to content

Commit 0041c80

Browse files
committed
Add get_api_info method
1 parent a63f303 commit 0041c80

7 files changed

Lines changed: 114 additions & 0 deletions

File tree

reportportal_client/aio/client.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,15 @@ async def get_project_settings(self) -> Optional[dict]:
683683
response = await AsyncHttpRequest((await self.session()).get, url=url, name="get_project_settings").make()
684684
return await response.json if response else None
685685

686+
async def get_api_info(self) -> Optional[dict]:
687+
"""Get server information, like version.
688+
689+
:return: server information.
690+
"""
691+
url = root_uri_join("api/info")
692+
response = await AsyncHttpRequest((await self.session()).get, url=url, name="get_api_info").make()
693+
return await response.json if response else None
694+
686695
async def log_batch(self, log_batch: Optional[list[AsyncRPRequestLog]]) -> Optional[tuple[str, ...]]:
687696
"""Send batch logging message to the ReportPortal.
688697
@@ -1109,6 +1118,13 @@ async def get_project_settings(self) -> Optional[dict]:
11091118
"""
11101119
return await self.__client.get_project_settings()
11111120

1121+
async def get_api_info(self) -> Optional[dict]:
1122+
"""Get server information, like version.
1123+
1124+
:return: server information.
1125+
"""
1126+
return await self.__client.get_api_info()
1127+
11121128
async def log(
11131129
self,
11141130
time: Union[str, datetime],
@@ -1565,6 +1581,15 @@ def get_project_settings(self) -> Task[Optional[str]]:
15651581
result_task = self.create_task(result_coro)
15661582
return result_task
15671583

1584+
def get_api_info(self) -> Task[Optional[dict]]:
1585+
"""Get server information, like version.
1586+
1587+
:return: server information.
1588+
"""
1589+
result_coro = self.__client.get_api_info()
1590+
result_task = self.create_task(result_coro)
1591+
return result_task
1592+
15681593
async def _log_batch(self, log_rq: Optional[list[AsyncRPRequestLog]]) -> Optional[tuple[str, ...]]:
15691594
return await self.__client.log_batch(log_rq)
15701595

reportportal_client/client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ def get_project_settings(self) -> Optional[dict]:
316316
"""
317317
raise NotImplementedError('"get_project_settings" method is not implemented!')
318318

319+
@abstractmethod
320+
def get_api_info(self) -> Optional[dict]:
321+
"""Get server information, like version.
322+
323+
:return: server information.
324+
"""
325+
raise NotImplementedError('"get_api_info" method is not implemented!')
326+
319327
@abstractmethod
320328
def log(
321329
self,
@@ -1055,6 +1063,21 @@ def get_project_settings(self) -> Optional[dict]:
10551063
).make()
10561064
return response.json if response else None
10571065

1066+
def get_api_info(self) -> Optional[dict]:
1067+
"""Get server information, like version.
1068+
1069+
:return: server information.
1070+
"""
1071+
url = uri_join(self.__endpoint, "api/info")
1072+
response = HttpRequest(
1073+
self.session.get,
1074+
url=url,
1075+
verify_ssl=self.verify_ssl,
1076+
http_timeout=self.http_timeout,
1077+
name="get_api_info",
1078+
).make()
1079+
return response.json if response else None
1080+
10581081
def _add_current_item(self, item: str) -> None:
10591082
"""Add the last item from the self._items queue."""
10601083
self._item_stack.put(item)

tests/aio/test_aio_client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ def request_error(*_, **__):
565565
("get", "get_launch_ui_id", ["launch_uuid"]),
566566
("get", "get_launch_ui_url", ["launch_uuid"]),
567567
("get", "get_project_settings", []),
568+
("get", "get_api_info", []),
568569
(
569570
"post",
570571
"log_batch",
@@ -909,6 +910,21 @@ async def test_get_launch_ui_url(aio_client: Client):
909910
assert expected_uri == call_args[0][0]
910911

911912

913+
@pytest.mark.asyncio
914+
async def test_get_api_info(aio_client: Client):
915+
# noinspection PyTypeChecker
916+
session: mock.AsyncMock = await aio_client.session()
917+
mock_basic_get_response(session)
918+
919+
expected_uri = "/api/info"
920+
921+
result = await aio_client.get_api_info()
922+
assert result == RETURN_GET_JSON
923+
session.get.assert_called_once()
924+
call_args = session.get.call_args_list[0]
925+
assert expected_uri == call_args[0][0]
926+
927+
912928
@pytest.mark.parametrize(
913929
"method, mock_method, call_method, arguments",
914930
[

tests/aio/test_async_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,16 @@ async def test_logs_flush_on_close(async_client: AsyncRPClient):
193193
batcher.flush.assert_called_once()
194194
client.log_batch.assert_called_once()
195195
client.close.assert_called_once()
196+
197+
198+
@pytest.mark.asyncio
199+
async def test_get_api_info(async_client: AsyncRPClient):
200+
# noinspection PyTypeChecker
201+
client: mock.AsyncMock = async_client.client
202+
expected_info = {"version": "5.14.0"}
203+
client.get_api_info.return_value = expected_info
204+
205+
result = await async_client.get_api_info()
206+
207+
assert result == expected_info
208+
client.get_api_info.assert_called_once_with()

tests/aio/test_batched_client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,15 @@ def test_logs_flush_on_close(batched_client: BatchedRPClient):
167167
batcher.flush.assert_called_once()
168168
client.log_batch.assert_called_once()
169169
client.close.assert_called_once()
170+
171+
172+
def test_get_api_info():
173+
aio_client = mock.AsyncMock()
174+
expected_info = {"version": "5.14.0"}
175+
aio_client.get_api_info.return_value = expected_info
176+
client = BatchedRPClient("http://endpoint", "project", api_key="api_key", client=aio_client)
177+
178+
result = client.get_api_info().blocking_result()
179+
180+
assert result == expected_info
181+
aio_client.get_api_info.assert_called_once_with()

tests/aio/test_threaded_client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,15 @@ def test_logs_flush_on_close(batched_client: ThreadedRPClient):
165165
batcher.flush.assert_called_once()
166166
client.log_batch.assert_called_once()
167167
client.close.assert_called_once()
168+
169+
170+
def test_get_api_info():
171+
aio_client = mock.AsyncMock()
172+
expected_info = {"version": "5.14.0"}
173+
aio_client.get_api_info.return_value = expected_info
174+
client = ThreadedRPClient("http://endpoint", "project", api_key="api_key", client=aio_client)
175+
176+
result = client.get_api_info().blocking_result()
177+
178+
assert result == expected_info
179+
aio_client.get_api_info.assert_called_once_with()

tests/test_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def invalid_response(*args, **kwargs):
5454
("get", "get_launch_ui_id", []),
5555
("get", "get_launch_ui_url", []),
5656
("get", "get_project_settings", []),
57+
("get", "get_api_info", []),
5758
("post", "start_launch", ["Test Launch", timestamp()]),
5859
("post", "start_test_item", ["Test Item", timestamp(), "STEP"]),
5960
("put", "update_test_item", ["test_item_id"]),
@@ -297,6 +298,7 @@ def test_attribute_sanitization_binary_and_number_limit(rp_client: RPClient):
297298
("update_test_item", "put", ["test_item_uuid"]),
298299
("get_launch_info", "get", []),
299300
("get_project_settings", "get", []),
301+
("get_api_info", "get", []),
300302
("get_item_id_by_uuid", "get", ["test_item_uuid"]),
301303
("log", "post", [timestamp(), "Test Message"]),
302304
],
@@ -344,6 +346,17 @@ def test_logs_flush_on_close(rp_client: RPClient):
344346
session.close.assert_called_once()
345347

346348

349+
def test_get_api_info_url(rp_client: RPClient):
350+
# noinspection PyTypeChecker
351+
session: mock.Mock = rp_client.session
352+
353+
rp_client.get_api_info()
354+
355+
session.get.assert_called_once()
356+
request_args = session.get.call_args_list[0][0]
357+
assert request_args[0] == "http://endpoint/api/info"
358+
359+
347360
def test_oauth_authentication_parameters():
348361
"""Test that OAuth 2.0 authentication parameters work correctly."""
349362
client = RPClient(

0 commit comments

Comments
 (0)