Improve testing of option flow in Coinbase (#52870)

This commit is contained in:
Tom Brien 2021-07-12 15:46:54 +01:00 committed by GitHub
parent 0f6a0f6bcd
commit 9308fa28e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 68 deletions

View file

@ -19,14 +19,7 @@ from .common import (
mock_get_exchange_rates,
mocked_get_accounts,
)
from .const import (
BAD_CURRENCY,
BAD_EXCHANGE_RATE,
GOOD_CURRENCY,
GOOD_CURRENCY_2,
GOOD_EXCHNAGE_RATE,
GOOD_EXCHNAGE_RATE_2,
)
from .const import BAD_CURRENCY, BAD_EXCHANGE_RATE, GOOD_CURRENCY, GOOD_EXCHNAGE_RATE
from tests.common import MockConfigEntry
@ -144,19 +137,8 @@ async def test_form_catch_all_exception(hass):
assert result2["errors"] == {"base": "unknown"}
async def test_option_good_account_currency(hass):
async def test_option_form(hass):
"""Test we handle a good wallet currency option."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
title="Test User",
data={CONF_API_KEY: "123456", CONF_API_TOKEN: "AbCDeF"},
options={
CONF_CURRENCIES: [GOOD_CURRENCY_2],
CONF_EXCHANGE_RATES: [],
},
)
config_entry.add_to_hass(hass)
with patch(
"coinbase.wallet.client.Client.get_current_user",
@ -166,8 +148,11 @@ async def test_option_good_account_currency(hass):
), patch(
"coinbase.wallet.client.Client.get_exchange_rates",
return_value=mock_get_exchange_rates(),
):
assert await hass.config_entries.async_setup(config_entry.entry_id)
), patch(
"homeassistant.components.coinbase.update_listener"
) as mock_update_listener:
config_entry = await init_mock_coinbase(hass)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_init(config_entry.entry_id)
await hass.async_block_till_done()
@ -175,10 +160,12 @@ async def test_option_good_account_currency(hass):
result["flow_id"],
user_input={
CONF_CURRENCIES: [GOOD_CURRENCY],
CONF_EXCHANGE_RATES: [],
CONF_EXCHANGE_RATES: [GOOD_EXCHNAGE_RATE],
},
)
assert result2["type"] == "create_entry"
assert result2["type"] == "create_entry"
await hass.async_block_till_done()
assert len(mock_update_listener.mock_calls) == 1
async def test_form_bad_account_currency(hass):
@ -207,43 +194,6 @@ async def test_form_bad_account_currency(hass):
assert result2["errors"] == {"base": "currency_unavaliable"}
async def test_option_good_exchange_rate(hass):
"""Test we handle a good exchange rate option."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="abcde12345",
title="Test User",
data={CONF_API_KEY: "123456", CONF_API_TOKEN: "AbCDeF"},
options={
CONF_CURRENCIES: [],
CONF_EXCHANGE_RATES: [GOOD_EXCHNAGE_RATE_2],
},
)
config_entry.add_to_hass(hass)
with patch(
"coinbase.wallet.client.Client.get_current_user",
return_value=mock_get_current_user(),
), patch(
"coinbase.wallet.client.Client.get_accounts", new=mocked_get_accounts
), patch(
"coinbase.wallet.client.Client.get_exchange_rates",
return_value=mock_get_exchange_rates(),
):
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)
await hass.async_block_till_done()
result2 = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
CONF_CURRENCIES: [],
CONF_EXCHANGE_RATES: [GOOD_EXCHNAGE_RATE],
},
)
assert result2["type"] == "create_entry"
async def test_form_bad_exchange_rate(hass):
"""Test we handle a bad exchange rate."""
with patch(