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
c7f66307
Unverified
Commit
c7f66307
authored
3 months ago
by
Maikel Punie
Committed by
GitHub
3 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Velbus add init testcases (#134533)
parent
afa95293
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/components/velbus/test_init.py
+43
-9
43 additions, 9 deletions
tests/components/velbus/test_init.py
with
43 additions
and
9 deletions
tests/components/velbus/test_init.py
+
43
−
9
View file @
c7f66307
"""
Tests for the Velbus component initialisation.
"""
"""
Tests for the Velbus component initialisation.
"""
from
unittest.mock
import
patch
from
unittest.mock
import
MagicMock
,
patch
import
pytest
from
velbusaio.exceptions
import
VelbusConnectionFailed
from
homeassistant.components.velbus
import
VelbusConfigEntry
from
homeassistant.components.velbus.const
import
DOMAIN
from
homeassistant.components.velbus.const
import
DOMAIN
from
homeassistant.config_entries
import
ConfigEntry
,
ConfigEntryState
from
homeassistant.config_entries
import
ConfigEntry
,
ConfigEntryState
from
homeassistant.const
import
CONF_NAME
,
CONF_PORT
from
homeassistant.const
import
CONF_NAME
,
CONF_PORT
from
homeassistant.core
import
HomeAssistant
from
homeassistant.core
import
HomeAssistant
from
homeassistant.helpers
import
device_registry
as
dr
from
homeassistant.helpers
import
device_registry
as
dr
,
entity_registry
as
er
from
.
import
init_integration
from
tests.common
import
MockConfigEntry
from
tests.common
import
MockConfigEntry
@pytest.mark.usefixtures
(
"
controller
"
)
async
def
test_setup_connection_failed
(
async
def
test_unload_entry
(
hass
:
HomeAssistant
,
config_entry
:
ConfigEntry
)
->
None
:
hass
:
HomeAssistant
,
config_entry
:
VelbusConfigEntry
,
controller
:
MagicMock
,
)
->
None
:
"""
Test the setup that fails during velbus connect.
"""
controller
.
return_value
.
connect
.
side_effect
=
VelbusConnectionFailed
()
await
hass
.
config_entries
.
async_setup
(
config_entry
.
entry_id
)
assert
config_entry
.
state
is
ConfigEntryState
.
SETUP_RETRY
async
def
test_setup_start_failed
(
hass
:
HomeAssistant
,
config_entry
:
VelbusConfigEntry
,
controller
:
MagicMock
,
entity_registry
:
er
.
EntityRegistry
,
)
->
None
:
"""
Test the setup that fails during velbus start task, should result in no entries.
"""
controller
.
return_value
.
start
.
side_effect
=
ConnectionError
()
await
init_integration
(
hass
,
config_entry
)
assert
config_entry
.
state
is
ConfigEntryState
.
LOADED
assert
(
er
.
async_entries_for_config_entry
(
entity_registry
,
config_entry
.
entry_id
)
==
[]
)
async
def
test_unload_entry
(
hass
:
HomeAssistant
,
config_entry
:
ConfigEntry
,
)
->
None
:
"""
Test being able to unload an entry.
"""
"""
Test being able to unload an entry.
"""
await
hass
.
config_entries
.
async_setup
(
config_entry
.
entry_id
)
await
hass
.
config_entries
.
async_setup
(
config_entry
.
entry_id
)
await
hass
.
async_block_till_done
()
await
hass
.
async_block_till_done
()
...
@@ -29,9 +60,10 @@ async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> N
...
@@ -29,9 +60,10 @@ async def test_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> N
assert
not
hass
.
data
.
get
(
DOMAIN
)
assert
not
hass
.
data
.
get
(
DOMAIN
)
@pytest.mark.usefixtures
(
"
controller
"
)
async
def
test_device_identifier_migration
(
async
def
test_device_identifier_migration
(
hass
:
HomeAssistant
,
config_entry
:
ConfigEntry
,
device_registry
:
dr
.
DeviceRegistry
hass
:
HomeAssistant
,
config_entry
:
ConfigEntry
,
device_registry
:
dr
.
DeviceRegistry
,
)
->
None
:
)
->
None
:
"""
Test being able to unload an entry.
"""
"""
Test being able to unload an entry.
"""
original_identifiers
=
{(
DOMAIN
,
"
module_address
"
,
"
module_serial
"
)}
original_identifiers
=
{(
DOMAIN
,
"
module_address
"
,
"
module_serial
"
)}
...
@@ -64,8 +96,10 @@ async def test_device_identifier_migration(
...
@@ -64,8 +96,10 @@ async def test_device_identifier_migration(
assert
device_entry
.
sw_version
==
"
module_sw_version
"
assert
device_entry
.
sw_version
==
"
module_sw_version
"
@pytest.mark.usefixtures
(
"
controller
"
)
async
def
test_migrate_config_entry
(
async
def
test_migrate_config_entry
(
hass
:
HomeAssistant
)
->
None
:
hass
:
HomeAssistant
,
controller
:
MagicMock
,
)
->
None
:
"""
Test successful migration of entry data.
"""
"""
Test successful migration of entry data.
"""
legacy_config
=
{
CONF_NAME
:
"
fake_name
"
,
CONF_PORT
:
"
1.2.3.4:5678
"
}
legacy_config
=
{
CONF_NAME
:
"
fake_name
"
,
CONF_PORT
:
"
1.2.3.4:5678
"
}
entry
=
MockConfigEntry
(
domain
=
DOMAIN
,
unique_id
=
"
my own id
"
,
data
=
legacy_config
)
entry
=
MockConfigEntry
(
domain
=
DOMAIN
,
unique_id
=
"
my own id
"
,
data
=
legacy_config
)
...
...
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