-
Notifications
You must be signed in to change notification settings - Fork 317
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
feat: add optional param for passing an unique_id to call method. #438
feat: add optional param for passing an unique_id to call method. #438
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
Can you add or modify a unit test to cover the change?
081ffae
to
c0eea1a
Compare
@OrangeTux I added some tests that cover this new functionality. To maintain consistency with the existing codebase, I followed the same approach used in the repository and duplicated the same tests for the different OCPP versions. |
@santiagosalamandri not sure this is a SonarCloud bug (it happened in the past) but can you try to reduce duplication by using parametrized python testing? For example, this code: @pytest.mark.asyncio
async def test_call_with_unique_id_should_return_same_id(
mock_boot_request, mock_base_central_system
):
expected_unique_id = "12345"
# Call the method being tested with a unique_id as a parameter
await mock_base_central_system.call(mock_boot_request, unique_id=expected_unique_id)
(
actual_unique_id,
_,
) = mock_base_central_system._get_specific_response.call_args_list[0][0]
# Check the actual unique id is equals to the one passed to the call method
assert actual_unique_id == expected_unique_id
@pytest.mark.asyncio
async def test_call_without_unique_id_should_return_a_random_value(
mock_boot_request, mock_base_central_system
):
expected_unique_id = str(mock_base_central_system._unique_id_generator())
# Call the method being tested without passing a unique_id as a parameter
await mock_base_central_system.call(mock_boot_request)
(
actual_unique_id,
_,
) = mock_base_central_system._get_specific_response.call_args_list[0][0]
# Check the actual unique id is equals to the one internally generated
assert actual_unique_id == expected_unique_id could be reduced to one test with the |
Hi @tropxy , yes, that will reduce the code duplication but it won't reduce the percentage duplication(which has to be less than 3% to pass), as it is calculated based on new code among the files that have changed. So, to overcome this, I could create different PRs for each test, what do you think @OrangeTux ? |
Yup, understood, on the light of this I think we can just ignore the sound cloud analysis. All tests pass, which is good. |
This PR adds:
-An additional optional parameter to the
call
method.This is needed for requirement E-13 on OCPP2.0.1 when the CS needs to retry sending a transaction message with the same ID.
Currently, when the
call
method is called, aCall
object is created with a new random ID.