Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance tests for client [WIP] #239

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

VicGrygorchyk
Copy link

@VicGrygorchyk VicGrygorchyk commented Oct 9, 2024

The exercise is done within the experiment of AI unittest generation
Unitttest generated for the client.py https://github.com/reportportal/client-Python/blob/develop/reportportal_client/client.py

@VicGrygorchyk VicGrygorchyk changed the title Enhance tests for client Enhance tests for client [WIP] Oct 9, 2024
from reportportal_client.core.rp_issues import Issue
from reportportal_client.errors import RPInvalidStepUsage, RetentionError
from reportportal_client.steps import step

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some methods are not imported

from reportportal_client.client import RP, ProjectSettings
from reportportal_client.core.rp_issues import Issue
from reportportal_client.core.rp_requests import RPFile
from tests import REPORT_ENDPOINT_V1, ROOT_URI, PROJECT_NAME, LAUNCH_ID, NO_OP
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure where these imports came from, can't find these in the tests/init.py

rp.log_batch_size = 2
rp.log_batch_payload_size = 3
result = rp.log(None, None, 'TEST')
assert result
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it check also something else but assert result?

Copy link

@oleksiidonchakkf oleksiidonchakkf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a quick glance over the code, feel free to ignore :)

from reportportal_client.aio.client import TaskInfo
from reportportal_client.aio.client import DEFAULT_TASK_TIMEOUT
from reportportal_client.aio.client import DEFAULT_SHUTDOWN_TASK_TIMEOUT
from reportportal_client.aio.multiplexer import Multiplexer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which Multiplexer? I can't find any in the related module

from tests import REPORT_ENDPOINT_V1, ROOT_URI, PROJECT_NAME, LAUNCH_ID, NO_OP


def test_mp_init():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test as a whole looks strange:

  1. Create a mock locally (even though the line itself looks incorrect, mocking usually is done in a different way, see https://docs.python.org/3/library/unittest.mock.html
  2. Create a multiplexer
  3. Check its private (!) variable to be the mock. Check by reference
  4. Create an instance of a non-imported class
  5. Assert something again

assert rp.shutdown.called


class RpChild(Multiplexer):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class created in the middle of a test suite

These things "shutdown", "add_child" and "remove_child" are static variables when declared like this, if I'm not mistaken

mock_loop.sock_coro = NO_OP
task = Task(0.0001, NO_OP)
result = yield from task.execute(mock_loop)
assert result

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No mentions of any "retries" here


def test_task_info():
ti = TaskInfo(0, 1, 2, 3)
assert ti.attempt is 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not write tests for a data class

By the way, it's better to compare by value (==), not by reference (is)


@pytest.mark.asyncio
async def test_aio_init_default_values():
client = RetryingClient('https://endpoint')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class doesn't exist at all. However, the tests are better than in the file 1

At least, I can't find anything obviously wrong without looking into the implementation

def test_client_init_verify_ignore_connectivity_true(mock_session):
client = Client('http://endpoint', 'project', 'api_key',
verify_ssl=False, ignore_connectivity=True)
expect(lambda: assert_that(client.session, has_properties({'verify': False})))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here a different framework is used

From what I can see, for tests like this there is no need for any delayed asserts

Just "assert client.session.verify == False" and that's it

def test_client_init_verify_ignore_connectivity_false(mock_session):
client = Client('http://endpoint', 'project', 'api_key',
verify_ssl=False, ignore_connectivity=False)
expect(contains('[DEFAULT]\ndisable_warnings = True\nverify_ssl = False')).one_of(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what these test methods come from

If from https://github.com/pr4bh4sh/delayed-assert than I thought it contained only "expect"...

The machine is clearly hallucinating with ".empty()", ".ending_with()" and their connections

"str" and "map" are python methods that definitely mean something different to what the machine were trying to say


@mock.patch('reportportal_client.aio.client.requests.Session')
def test_rp_client_start_with_overriding_launch_attributes(self, mock_session):
rp_truncation_msg = 'Attribute values cannot exceed 128 characters in length. Value got: veryverylongattributevalue'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value "veryverylongattributevalue", it's definitely for shorter than 128 characters

@mock.patch('reportportal_client.aio.client.requests.Session')
def test_rp_client_set_attributes_without_values(self, mock_session):
mock_finish = mock_session().post
mock_finish.return_value = mock.Mock(json=lambda: {}, status_code=200)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of lines like these. Need to collapse them to a function

As for the lines that do testing, they look better but I can't tell you if they are correct without launching them first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants