Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery committed Apr 10, 2024
1 parent 2afc06b commit 27cc1a4
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,9 @@ def response_mocker() -> ResponseMocker:
async def setup_integration(hass: HomeAssistant, check_report_issue: None) -> None:
## Assert the string to ensure the format did not change
if AwesomeVersion(HA_VERSION) >= "2023.11.0":
# Issues may be created because hacs accesses hass.components and hass.helpers
assert len(_async_suggest_report_issue_mock_call_tracker) in [0, 1, 2]
# Issues may be created because hacs accesses hass.components, hass.helpers and
# calls async_show_progress without passing a progress task
assert len(_async_suggest_report_issue_mock_call_tracker) in [0, 1, 2, 3]
_async_suggest_report_issue_mock_call_tracker.clear()
assert (
loader.async_suggest_report_issue(
Expand Down Expand Up @@ -349,8 +350,9 @@ async def setup_integration(hass: HomeAssistant, check_report_issue: None) -> No
async def check_report_issue() -> None:
"""Finish things up."""
yield
# Issues may be created because hacs accesses hass.components and hass.helpers
allowed = [0, 1, 2] if AwesomeVersion(HA_VERSION) > "2023.6.0" else [0]
# Issues may be created because hacs accesses hass.components, hass.helpers and
# calls async_show_progress without passing a progress task
allowed = [0, 1, 2, 3] if AwesomeVersion(HA_VERSION) > "2023.6.0" else [0]
if (times := len(_async_suggest_report_issue_mock_call_tracker)) not in allowed:
raise AssertionError(
f"homeassistant.loader.async_suggest_report_issue has been called {times} times"
Expand Down
14 changes: 14 additions & 0 deletions tests/output/proxy_calls.json
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,20 @@
"https://api.github.com/repos/hacs-test-org/theme-basic/releases": 1,
"https://data-v2.hacs.xyz/theme/data.json": 1
},
"tests/test_config_flow.py::test_flow_with_activation_failure": {
"https://github.com/login/device/code": 1,
"https://github.com/login/oauth/access_token": 1
},
"tests/test_config_flow.py::test_flow_with_registration_failure": {
"https://github.com/login/device/code": 1
},
"tests/test_config_flow.py::test_flow_with_remove_while_activating": {
"https://github.com/login/device/code": 1
},
"tests/test_config_flow.py::test_full_user_flow_implementation": {
"https://github.com/login/device/code": 1,
"https://github.com/login/oauth/access_token": 1
},
"tests/test_data_client.py::test_basic_functionality_data[hacs-test-org/appdaemon-basic]": {
"https://api.github.com/repos/hacs/integration": 1,
"https://api.github.com/repos/hacs/integration/contents/custom_components/hacs/manifest.json": 1,
Expand Down
6 changes: 6 additions & 0 deletions tests/snapshots/config_flow/test_already_configured.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"description_placeholders": null,
"handler": "hacs",
"reason": "single_instance_allowed",
"type": "abort"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"description_placeholders": null,
"handler": "hacs",
"reason": "could_not_register",
"type": "abort"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"description_placeholders": null,
"handler": "hacs",
"reason": "could_not_register",
"type": "abort"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"context": {
"source": "user"
},
"data": {
"token": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
"description": null,
"description_placeholders": null,
"handler": "hacs",
"options": {
"experimental": true
},
"result": {
"__type": "<class 'type'>",
"repr": "<class 'homeassistant.config_entries.ConfigEntry'>"
},
"title": "",
"type": "create_entry",
"version": 1
}
6 changes: 6 additions & 0 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
TOKEN,
MockedResponse,
ResponseMocker,
create_config_entry,
recursive_remove_key,
safe_json_dumps,
)
Expand Down Expand Up @@ -198,6 +199,7 @@ async def test_flow_with_registration_failure(
"experimental": True,
},
)
await hass.async_block_till_done()

assert result["type"] == FlowResultType.ABORT

Expand Down Expand Up @@ -273,10 +275,14 @@ async def test_already_configured(
check_report_issue: None,
) -> None:
"""Test we abort if already configured."""
config_entry = create_config_entry(data={"experimental": True})
config_entry.add_to_hass(hass)

result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USER},
)
await hass.async_block_till_done()

assert result["type"] == FlowResultType.ABORT
snapshots.assert_match(
Expand Down

0 comments on commit 27cc1a4

Please sign in to comment.