From 27cc1a45dbb87229d19ef3f6efcf982cb2752a87 Mon Sep 17 00:00:00 2001 From: Erik Date: Mon, 8 Apr 2024 10:49:32 +0200 Subject: [PATCH] Adjust tests --- tests/conftest.py | 10 +++++---- tests/output/proxy_calls.json | 14 +++++++++++++ .../config_flow/test_already_configured.json | 6 ++++++ .../test_flow_with_activation_failure.json | 6 ++++++ .../test_flow_with_registration_failure.json | 6 ++++++ .../test_full_user_flow_implementation.json | 21 +++++++++++++++++++ tests/test_config_flow.py | 6 ++++++ 7 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 tests/snapshots/config_flow/test_already_configured.json create mode 100644 tests/snapshots/config_flow/test_flow_with_activation_failure.json create mode 100644 tests/snapshots/config_flow/test_flow_with_registration_failure.json create mode 100644 tests/snapshots/config_flow/test_full_user_flow_implementation.json diff --git a/tests/conftest.py b/tests/conftest.py index 98d87d90872..40c29d752c5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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( @@ -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" diff --git a/tests/output/proxy_calls.json b/tests/output/proxy_calls.json index 45edbf44822..6a13f670df9 100644 --- a/tests/output/proxy_calls.json +++ b/tests/output/proxy_calls.json @@ -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, diff --git a/tests/snapshots/config_flow/test_already_configured.json b/tests/snapshots/config_flow/test_already_configured.json new file mode 100644 index 00000000000..f6c1881bd47 --- /dev/null +++ b/tests/snapshots/config_flow/test_already_configured.json @@ -0,0 +1,6 @@ +{ + "description_placeholders": null, + "handler": "hacs", + "reason": "single_instance_allowed", + "type": "abort" +} \ No newline at end of file diff --git a/tests/snapshots/config_flow/test_flow_with_activation_failure.json b/tests/snapshots/config_flow/test_flow_with_activation_failure.json new file mode 100644 index 00000000000..d64f8c1e98f --- /dev/null +++ b/tests/snapshots/config_flow/test_flow_with_activation_failure.json @@ -0,0 +1,6 @@ +{ + "description_placeholders": null, + "handler": "hacs", + "reason": "could_not_register", + "type": "abort" +} \ No newline at end of file diff --git a/tests/snapshots/config_flow/test_flow_with_registration_failure.json b/tests/snapshots/config_flow/test_flow_with_registration_failure.json new file mode 100644 index 00000000000..d64f8c1e98f --- /dev/null +++ b/tests/snapshots/config_flow/test_flow_with_registration_failure.json @@ -0,0 +1,6 @@ +{ + "description_placeholders": null, + "handler": "hacs", + "reason": "could_not_register", + "type": "abort" +} \ No newline at end of file diff --git a/tests/snapshots/config_flow/test_full_user_flow_implementation.json b/tests/snapshots/config_flow/test_full_user_flow_implementation.json new file mode 100644 index 00000000000..7ccfe057756 --- /dev/null +++ b/tests/snapshots/config_flow/test_full_user_flow_implementation.json @@ -0,0 +1,21 @@ +{ + "context": { + "source": "user" + }, + "data": { + "token": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + }, + "description": null, + "description_placeholders": null, + "handler": "hacs", + "options": { + "experimental": true + }, + "result": { + "__type": "", + "repr": "" + }, + "title": "", + "type": "create_entry", + "version": 1 +} \ No newline at end of file diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index 5b83107bed6..56eddaf0e43 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -14,6 +14,7 @@ TOKEN, MockedResponse, ResponseMocker, + create_config_entry, recursive_remove_key, safe_json_dumps, ) @@ -198,6 +199,7 @@ async def test_flow_with_registration_failure( "experimental": True, }, ) + await hass.async_block_till_done() assert result["type"] == FlowResultType.ABORT @@ -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(