Skip to content

Commit

Permalink
Fix errors in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Jun 29, 2022
1 parent 5846605 commit 38a338f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion custom_components/integration_blueprint/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async def async_step_user(self, user_input: Optional[ConfigType] = None):
step_id="user",
data_schema=vol.Schema(
{
vol.Required(x, default=self.options.get(x, True)): bool
vol.Required(str(x), default=self.options.get(str(x), True)): bool
for x in sorted(PLATFORMS)
}
),
Expand Down
2 changes: 0 additions & 2 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ good-names=id,i,j,k,ex,Run,_,fp,T
# locally-disabled - it spams too much
# duplicate-code - unavoidable
# cyclic-import - doesn't test if both import on load
# abstract-class-little-used - prevents from setting right foundation
# unused-argument - generic callbacks and setup methods create a lot of warnings
# too-many-* - are not enforced for the sake of readability
# too-few-* - same as too-many-*
Expand All @@ -26,7 +25,6 @@ good-names=id,i,j,k,ex,Run,_,fp,T
# wrong-import-order - isort guards this
disable=
format,
abstract-class-little-used,
abstract-method,
cyclic-import,
duplicate-code,
Expand Down
2 changes: 1 addition & 1 deletion tests/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Constants for tests."""
from typing import Final

from custom_components.integration_blueprint.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME

# Mock config data to be used across multiple tests
MOCK_CONFIG: Final = {CONF_USERNAME: "test_username", CONF_PASSWORD: "test_password"}
17 changes: 8 additions & 9 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@

import pytest
from homeassistant import config_entries, data_entry_flow
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from pytest_homeassistant_custom_component.common import MockConfigEntry

from custom_components.integration_blueprint.const import (
BINARY_SENSOR,
DOMAIN,
PLATFORMS,
SENSOR,
SWITCH,
)
from custom_components.integration_blueprint.const import DOMAIN, PLATFORMS

from .const import MOCK_CONFIG

Expand Down Expand Up @@ -102,12 +97,16 @@ async def test_options_flow(hass: HomeAssistant):
# Enter some fake data into the form
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={platform: platform != SENSOR for platform in PLATFORMS},
user_input={platform: platform != Platform.SENSOR for platform in PLATFORMS},
)

# Verify that the flow finishes
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "test_username"

# Verify that the options were updated
assert entry.options == {BINARY_SENSOR: True, SENSOR: False, SWITCH: True}
assert entry.options == {
Platform.BINARY_SENSOR: True,
Platform.SENSOR: False,
Platform.SWITCH: True,
}
20 changes: 12 additions & 8 deletions tests/test_switch.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# pylint: disable=protected-access,redefined-outer-name
"""Test integration_blueprint switch."""
"""Test integration_blueprint Platform.SWITCH."""

from unittest.mock import call, patch

from homeassistant.components.switch import SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.const import ATTR_ENTITY_ID, Platform
from homeassistant.core import HomeAssistant
from pytest_homeassistant_custom_component.common import MockConfigEntry

from custom_components.integration_blueprint import (
IntegrationBlueprintApiClient,
async_setup_entry,
)
from custom_components.integration_blueprint.const import DEFAULT_NAME, DOMAIN, SWITCH
from custom_components.integration_blueprint.const import DEFAULT_NAME, DOMAIN

from .const import MOCK_CONFIG


async def test_switch_services(hass: HomeAssistant, bypass_get_data):
"""Test switch services."""
"""Test Platform.SWITCH services."""
# Create a mock entry so we don't have to go through config flow
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")
assert await async_setup_entry(hass, config_entry)
Expand All @@ -28,9 +28,11 @@ async def test_switch_services(hass: HomeAssistant, bypass_get_data):
# additional things, like whether a function was called or what arguments it was called with
with patch.object(IntegrationBlueprintApiClient, "async_set_title") as title_func:
await hass.services.async_call(
SWITCH,
Platform.SWITCH,
SERVICE_TURN_OFF,
service_data={ATTR_ENTITY_ID: f"{SWITCH}.{DEFAULT_NAME}_{SWITCH}"},
service_data={
ATTR_ENTITY_ID: f"{Platform.SWITCH}.{DEFAULT_NAME}_{Platform.SWITCH}"
},
blocking=True,
)
assert title_func.called
Expand All @@ -39,9 +41,11 @@ async def test_switch_services(hass: HomeAssistant, bypass_get_data):
title_func.reset_mock()

await hass.services.async_call(
SWITCH,
Platform.SWITCH,
SERVICE_TURN_ON,
service_data={ATTR_ENTITY_ID: f"{SWITCH}.{DEFAULT_NAME}_{SWITCH}"},
service_data={
ATTR_ENTITY_ID: f"{Platform.SWITCH}.{DEFAULT_NAME}_{Platform.SWITCH}"
},
blocking=True,
)
assert title_func.called
Expand Down

0 comments on commit 38a338f

Please sign in to comment.