From eda0c708ae6fe944d7151e03270795fd8424a65d Mon Sep 17 00:00:00 2001 From: Vadzim Hushchanskou Date: Wed, 11 Oct 2023 18:11:21 +0300 Subject: [PATCH] Add more tests --- tests/aio/test_async_client.py | 42 ++++++++++++++++++++++++++++++++++ tests/conftest.py | 10 +++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/aio/test_async_client.py b/tests/aio/test_async_client.py index 6f5c2e29..70a742e5 100644 --- a/tests/aio/test_async_client.py +++ b/tests/aio/test_async_client.py @@ -12,6 +12,11 @@ # limitations under the License import pickle +import sys +from unittest import mock + +# noinspection PyPackageRequirements +import pytest from reportportal_client.aio import AsyncRPClient @@ -55,3 +60,40 @@ def test_clone(): ) assert cloned._item_stack.qsize() == 1 \ and async_client.current_item() == cloned.current_item() + + +@pytest.mark.skipif(sys.version_info < (3, 8), + reason='the test requires AsyncMock which was introduced in Python 3.8') +@pytest.mark.parametrize( + 'launch_uuid', + [ + 'test_launch_uuid', + None, + ] +) +@pytest.mark.asyncio +async def test_start_launch(launch_uuid): + aio_client = mock.AsyncMock() + client = AsyncRPClient('http://endpoint', 'project', api_key='api_key', + client=aio_client, launch_uuid=launch_uuid) + launch_name = 'Test Launch' + start_time = str(1696921416000) + description = 'Test Launch description' + attributes = {'attribute_key': 'attribute_value'} + rerun = True + rerun_of = 'test_prent_launch_uuid' + result = await client.start_launch(launch_name, start_time, description=description, + attributes=attributes, rerun=rerun, rerun_of=rerun_of) + if launch_uuid: + assert result == launch_uuid + aio_client.start_launch.assert_not_called() + else: + assert result is not None + aio_client.start_launch.assert_called_once() + args, kwargs = aio_client.start_launch.call_args_list[0] + assert args[0] == launch_name + assert args[1] == start_time + assert kwargs.get('description') == description + assert kwargs.get('attributes') == attributes + assert kwargs.get('rerun') == rerun + assert kwargs.get('rerun_of') == rerun_of diff --git a/tests/conftest.py b/tests/conftest.py index 503cfdd6..1572a2d6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,7 +19,7 @@ from pytest import fixture from reportportal_client.client import RPClient -from reportportal_client.aio.client import Client +from reportportal_client.aio.client import Client, AsyncRPClient @fixture @@ -57,3 +57,11 @@ def aio_client(): client._session = mock.AsyncMock() client._skip_analytics = True return client + + +@fixture +def async_client(): + """Prepare instance of the AsyncRPClient for testing.""" + client = AsyncRPClient('http://endpoint', 'project', api_key='api_key', + client=mock.AsyncMock()) + return client