Skip to content

Commit

Permalink
Fix tests for real
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya committed Mar 8, 2024
1 parent 5d1cf99 commit b86166a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/notion/__init__.py
Expand Up @@ -181,7 +181,7 @@ def async_save_refresh_token(refresh_token: str) -> None:
entry.async_on_unload(client.add_refresh_token_callback(async_save_refresh_token))

# Save the client's refresh token if it's different than what we already have:
if (token := client.refresh_token) and token != entry.data.get(CONF_REFRESH_TOKEN):
if (token := client.refresh_token) and token != entry.data[CONF_REFRESH_TOKEN]:
async_save_refresh_token(token)

hass.config_entries.async_update_entry(entry, **entry_updates)
Expand Down
7 changes: 4 additions & 3 deletions tests/components/notion/conftest.py
Expand Up @@ -9,8 +9,8 @@
from aionotion.user.models import UserPreferences
import pytest

from homeassistant.components.notion import DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.components.notion import CONF_REFRESH_TOKEN, CONF_USER_UUID, DOMAIN
from homeassistant.const import CONF_USERNAME
from homeassistant.core import HomeAssistant

from tests.common import MockConfigEntry, load_fixture
Expand Down Expand Up @@ -81,7 +81,8 @@ def config_fixture():
"""Define a config entry data fixture."""
return {
CONF_USERNAME: TEST_USERNAME,
CONF_PASSWORD: TEST_PASSWORD,
CONF_USER_UUID: TEST_USER_UUID,
CONF_REFRESH_TOKEN: TEST_REFRESH_TOKEN,
}


Expand Down
16 changes: 12 additions & 4 deletions tests/components/notion/test_config_flow.py
Expand Up @@ -10,7 +10,7 @@
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant

from .conftest import TEST_REFRESH_TOKEN, TEST_USER_UUID, TEST_USERNAME
from .conftest import TEST_PASSWORD, TEST_REFRESH_TOKEN, TEST_USER_UUID, TEST_USERNAME

pytestmark = pytest.mark.usefixtures("mock_setup_entry")

Expand All @@ -26,7 +26,6 @@
async def test_create_entry(
hass: HomeAssistant,
client,
config,
errors,
get_client_with_exception,
mock_aionotion,
Expand All @@ -44,13 +43,22 @@ async def test_create_entry(
get_client_with_exception,
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=config
DOMAIN,
context={"source": SOURCE_USER},
data={
CONF_USERNAME: TEST_USERNAME,
CONF_PASSWORD: TEST_PASSWORD,
},
)
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["errors"] == errors

result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input=config
result["flow_id"],
user_input={
CONF_USERNAME: TEST_USERNAME,
CONF_PASSWORD: TEST_PASSWORD,
},
)
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result["title"] == TEST_USERNAME
Expand Down

0 comments on commit b86166a

Please sign in to comment.