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

Improve AsusWRT integration tests #102810

Merged
merged 5 commits into from Nov 9, 2023

Conversation

ollo69
Copy link
Contributor

@ollo69 ollo69 commented Oct 25, 2023

Proposed change

Review AsusWRT integration tests adding common.py and conftest.py for shared constants and patches. Added test_diagnostics to complete codecov requirement.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @kennedyshead, mind taking a look at this pull request as it has been labeled with an integration (asuswrt) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of asuswrt can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign asuswrt Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@ollo69 ollo69 mentioned this pull request Oct 25, 2023
20 tasks
tests/components/asuswrt/conftest.py Outdated Show resolved Hide resolved
tests/components/asuswrt/conftest.py Outdated Show resolved Hide resolved
tests/components/asuswrt/conftest.py Outdated Show resolved Hide resolved
@pytest.fixture(name="connect_legacy")
def mock_controller_connect_legacy(mock_devices_legacy, mock_available_temps):
"""Mock a successful connection with legacy library."""
with patch(ASUSWRT_LEGACY_LIB) as service_mock:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
with patch(ASUSWRT_LEGACY_LIB) as service_mock:
with patch(ASUSWRT_LEGACY_LIB, spec_set=AsusWrtLegacy) as service_mock:

Will create a mock with the same functions as AsusWrtLegacy
See https://docs.python.org/3/library/unittest.mock.html#patch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to use spec instead of spec_set to be able to define connection attribute, otherwise it was always returning to me AttributeError: Mock object has no attribute 'connection'. May be this is due to way that connection is defined in the library.

tests/components/asuswrt/conftest.py Outdated Show resolved Hide resolved
tests/components/asuswrt/conftest.py Outdated Show resolved Hide resolved
tests/components/asuswrt/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/asuswrt/test_config_flow.py Outdated Show resolved Hide resolved
tests/components/asuswrt/test_init.py Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft October 27, 2023 07:40
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@ollo69 ollo69 marked this pull request as ready for review October 28, 2023 18:21
@ollo69 ollo69 marked this pull request as draft October 28, 2023 21:53
@ollo69 ollo69 marked this pull request as ready for review October 28, 2023 23:18
@ollo69
Copy link
Contributor Author

ollo69 commented Nov 6, 2023

Any news here? There is something tat I miss to do?

Comment on lines 220 to 222
connect_legacy.return_value.connection.async_connect = AsyncMock(
side_effect=side_effect
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
connect_legacy.return_value.connection.async_connect = AsyncMock(
side_effect=side_effect
)
connect_legacy.return_value.connection.async_connect.side_effect=side_effect

connect_legacy.return_value.connection.async_connect = AsyncMock(
side_effect=side_effect
)
connect_legacy.return_value.async_get_nvram = AsyncMock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it isn't, I don''t remember why it was here😉.

@home-assistant home-assistant bot marked this pull request as draft November 8, 2023 08:01
@edenhaus edenhaus changed the title Review AsusWRT integration tests Improve AsusWRT integration tests Nov 8, 2023
@ollo69 ollo69 marked this pull request as ready for review November 8, 2023 18:34
Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks @ollo69 👍

@edenhaus edenhaus merged commit 143e114 into home-assistant:dev Nov 9, 2023
23 checks passed
@ollo69 ollo69 deleted the asuswrt-review-tests branch November 9, 2023 08:34
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants