Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Oct 11, 2023
1 parent 85d187a commit eda0c70
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
42 changes: 42 additions & 0 deletions tests/aio/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
10 changes: 9 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit eda0c70

Please sign in to comment.