Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
2f1ff5ab
Unverified
Commit
2f1ff5ab
authored
1 week ago
by
Austin Mroczek
Committed by
GitHub
1 week ago
Browse files
Options
Downloads
Patches
Plain Diff
TotalConnect refactor tests (#140240)
* refactor button * refactor test_options_flow
parent
593ae48a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/components/totalconnect/test_button.py
+16
-10
16 additions, 10 deletions
tests/components/totalconnect/test_button.py
tests/components/totalconnect/test_config_flow.py
+13
-35
13 additions, 35 deletions
tests/components/totalconnect/test_config_flow.py
with
29 additions
and
45 deletions
tests/components/totalconnect/test_button.py
+
16
−
10
View file @
2f1ff5ab
...
...
@@ -11,12 +11,7 @@ from homeassistant.const import ATTR_ENTITY_ID
from
homeassistant.core
import
HomeAssistant
from
homeassistant.helpers
import
entity_registry
as
er
from
.common
import
(
RESPONSE_ZONE_BYPASS_FAILURE
,
RESPONSE_ZONE_BYPASS_SUCCESS
,
TOTALCONNECT_REQUEST
,
setup_platform
,
)
from
.common
import
setup_platform
from
tests.common
import
snapshot_platform
...
...
@@ -34,12 +29,23 @@ async def test_entity_registry(
await
snapshot_platform
(
hass
,
entity_registry
,
snapshot
,
entry
.
entry_id
)
@pytest.mark.parametrize
(
"
entity_id
"
,
[
ZONE_BYPASS_ID
,
PANEL_BYPASS_ID
])
async
def
test_bypass_button
(
hass
:
HomeAssistant
,
entity_id
:
str
)
->
None
:
@pytest.mark.parametrize
(
(
"
entity_id
"
,
"
tcc_request
"
),
[
(
ZONE_BYPASS_ID
,
"
total_connect_client.zone.TotalConnectZone.bypass
"
),
(
PANEL_BYPASS_ID
,
"
total_connect_client.location.TotalConnectLocation.zone_bypass_all
"
,
),
],
)
async
def
test_bypass_button
(
hass
:
HomeAssistant
,
entity_id
:
str
,
tcc_request
:
str
)
->
None
:
"""
Test pushing a bypass button.
"""
responses
=
[
RESPONSE_ZONE_BYPASS_FAILURE
,
RESPONSE_ZONE_BYPASS_SUCCESS
]
responses
=
[
FailedToBypassZone
,
None
]
await
setup_platform
(
hass
,
BUTTON
)
with
patch
(
TOTALCONNECT_REQUEST
,
side_effect
=
responses
)
as
mock_request
:
with
patch
(
tcc_request
,
side_effect
=
responses
)
as
mock_request
:
# try to bypass, but fails
with
pytest
.
raises
(
FailedToBypassZone
):
await
hass
.
services
.
async_call
(
...
...
This diff is collapsed.
Click to expand it.
tests/components/totalconnect/test_config_flow.py
+
13
−
35
View file @
2f1ff5ab
...
...
@@ -28,6 +28,7 @@ from .common import (
TOTALCONNECT_REQUEST
,
TOTALCONNECT_REQUEST_TOKEN
,
USERNAME
,
init_integration
,
)
from
tests.common
import
MockConfigEntry
...
...
@@ -219,42 +220,19 @@ async def test_no_locations(hass: HomeAssistant) -> None:
async
def
test_options_flow
(
hass
:
HomeAssistant
)
->
None
:
"""
Test config flow options.
"""
config_entry
=
MockConfigEntry
(
domain
=
DOMAIN
,
data
=
CONFIG_DATA
,
unique_id
=
USERNAME
,
)
config_entry
.
add_to_hass
(
hass
)
responses
=
[
RESPONSE_SESSION_DETAILS
,
RESPONSE_PARTITION_DETAILS
,
RESPONSE_GET_ZONE_DETAILS_SUCCESS
,
RESPONSE_DISARMED
,
RESPONSE_DISARMED
,
RESPONSE_DISARMED
,
]
config_entry
=
await
init_integration
(
hass
)
result
=
await
hass
.
config_entries
.
options
.
async_init
(
config_entry
.
entry_id
)
with
(
patch
(
TOTALCONNECT_REQUEST
,
side_effect
=
responses
),
patch
(
TOTALCONNECT_GET_CONFIG
,
side_effect
=
None
),
patch
(
TOTALCONNECT_REQUEST_TOKEN
,
side_effect
=
None
),
):
assert
await
hass
.
config_entries
.
async_setup
(
config_entry
.
entry_id
)
await
hass
.
async_block_till_done
()
result
=
await
hass
.
config_entries
.
options
.
async_init
(
config_entry
.
entry_id
)
assert
result
[
"
type
"
]
is
FlowResultType
.
FORM
assert
result
[
"
step_id
"
]
==
"
init
"
assert
result
[
"
type
"
]
is
FlowResultType
.
FORM
assert
result
[
"
step_id
"
]
==
"
init
"
result
=
await
hass
.
config_entries
.
options
.
async_configure
(
result
[
"
flow_id
"
],
user_input
=
{
AUTO_BYPASS
:
True
,
CODE_REQUIRED
:
False
}
)
result
=
await
hass
.
config_entries
.
options
.
async_configure
(
result
[
"
flow_id
"
],
user_input
=
{
AUTO_BYPASS
:
True
,
CODE_REQUIRED
:
False
}
)
assert
result
[
"
type
"
]
is
FlowResultType
.
CREATE_ENTRY
assert
config_entry
.
options
==
{
AUTO_BYPASS
:
True
,
CODE_REQUIRED
:
False
}
await
hass
.
async_block_till_done
()
assert
result
[
"
type
"
]
is
FlowResultType
.
CREATE_ENTRY
assert
config_entry
.
options
==
{
AUTO_BYPASS
:
True
,
CODE_REQUIRED
:
False
}
await
hass
.
async_block_till_done
()
assert
await
hass
.
config_entries
.
async_unload
(
config_entry
.
entry_id
)
await
hass
.
async_block_till_done
()
assert
await
hass
.
config_entries
.
async_unload
(
config_entry
.
entry_id
)
await
hass
.
async_block_till_done
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment