Use snapshot assertion for Coinbase diagnostics test (#98906)
This commit is contained in:
parent
faa4489f4c
commit
c39f6b3bea
4 changed files with 77 additions and 50 deletions
|
@ -68,6 +68,7 @@ async def init_mock_coinbase(hass, currencies=None, rates=None):
|
||||||
"""Init Coinbase integration for testing."""
|
"""Init Coinbase integration for testing."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
entry_id="080272b77a4f80c41b94d7cdc86fd826",
|
||||||
unique_id=None,
|
unique_id=None,
|
||||||
title="Test User",
|
title="Test User",
|
||||||
data={CONF_API_KEY: "123456", CONF_API_TOKEN: "AbCDeF"},
|
data={CONF_API_KEY: "123456", CONF_API_TOKEN: "AbCDeF"},
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""Constants for testing the Coinbase integration."""
|
"""Constants for testing the Coinbase integration."""
|
||||||
|
|
||||||
from homeassistant.components.diagnostics import REDACTED
|
|
||||||
|
|
||||||
GOOD_CURRENCY = "BTC"
|
GOOD_CURRENCY = "BTC"
|
||||||
GOOD_CURRENCY_2 = "USD"
|
GOOD_CURRENCY_2 = "USD"
|
||||||
|
@ -36,43 +35,3 @@ MOCK_ACCOUNTS_RESPONSE = [
|
||||||
"type": "fiat",
|
"type": "fiat",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
MOCK_ACCOUNTS_RESPONSE_REDACTED = [
|
|
||||||
{
|
|
||||||
"balance": {"amount": REDACTED, "currency": GOOD_CURRENCY},
|
|
||||||
"currency": GOOD_CURRENCY,
|
|
||||||
"id": REDACTED,
|
|
||||||
"name": "BTC Wallet",
|
|
||||||
"native_balance": {"amount": REDACTED, "currency": GOOD_CURRENCY_2},
|
|
||||||
"type": "wallet",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"balance": {"amount": REDACTED, "currency": GOOD_CURRENCY},
|
|
||||||
"currency": GOOD_CURRENCY,
|
|
||||||
"id": REDACTED,
|
|
||||||
"name": "BTC Vault",
|
|
||||||
"native_balance": {"amount": REDACTED, "currency": GOOD_CURRENCY_2},
|
|
||||||
"type": "vault",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"balance": {"amount": REDACTED, "currency": GOOD_CURRENCY_2},
|
|
||||||
"currency": "USD",
|
|
||||||
"id": REDACTED,
|
|
||||||
"name": "USD Wallet",
|
|
||||||
"native_balance": {"amount": REDACTED, "currency": GOOD_CURRENCY_2},
|
|
||||||
"type": "fiat",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
MOCK_ENTRY_REDACTED = {
|
|
||||||
"version": 1,
|
|
||||||
"domain": "coinbase",
|
|
||||||
"title": REDACTED,
|
|
||||||
"data": {"api_token": REDACTED, "api_key": REDACTED},
|
|
||||||
"options": {"account_balance_currencies": [], "exchange_rate_currencies": []},
|
|
||||||
"pref_disable_new_entities": False,
|
|
||||||
"pref_disable_polling": False,
|
|
||||||
"source": "user",
|
|
||||||
"unique_id": None,
|
|
||||||
"disabled_by": None,
|
|
||||||
}
|
|
||||||
|
|
70
tests/components/coinbase/snapshots/test_diagnostics.ambr
Normal file
70
tests/components/coinbase/snapshots/test_diagnostics.ambr
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
# serializer version: 1
|
||||||
|
# name: test_entry_diagnostics
|
||||||
|
dict({
|
||||||
|
'accounts': list([
|
||||||
|
dict({
|
||||||
|
'balance': dict({
|
||||||
|
'amount': '**REDACTED**',
|
||||||
|
'currency': 'BTC',
|
||||||
|
}),
|
||||||
|
'currency': 'BTC',
|
||||||
|
'id': '**REDACTED**',
|
||||||
|
'name': 'BTC Wallet',
|
||||||
|
'native_balance': dict({
|
||||||
|
'amount': '**REDACTED**',
|
||||||
|
'currency': 'USD',
|
||||||
|
}),
|
||||||
|
'type': 'wallet',
|
||||||
|
}),
|
||||||
|
dict({
|
||||||
|
'balance': dict({
|
||||||
|
'amount': '**REDACTED**',
|
||||||
|
'currency': 'BTC',
|
||||||
|
}),
|
||||||
|
'currency': 'BTC',
|
||||||
|
'id': '**REDACTED**',
|
||||||
|
'name': 'BTC Vault',
|
||||||
|
'native_balance': dict({
|
||||||
|
'amount': '**REDACTED**',
|
||||||
|
'currency': 'USD',
|
||||||
|
}),
|
||||||
|
'type': 'vault',
|
||||||
|
}),
|
||||||
|
dict({
|
||||||
|
'balance': dict({
|
||||||
|
'amount': '**REDACTED**',
|
||||||
|
'currency': 'USD',
|
||||||
|
}),
|
||||||
|
'currency': 'USD',
|
||||||
|
'id': '**REDACTED**',
|
||||||
|
'name': 'USD Wallet',
|
||||||
|
'native_balance': dict({
|
||||||
|
'amount': '**REDACTED**',
|
||||||
|
'currency': 'USD',
|
||||||
|
}),
|
||||||
|
'type': 'fiat',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
'entry': dict({
|
||||||
|
'data': dict({
|
||||||
|
'api_key': '**REDACTED**',
|
||||||
|
'api_token': '**REDACTED**',
|
||||||
|
}),
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'coinbase',
|
||||||
|
'entry_id': '080272b77a4f80c41b94d7cdc86fd826',
|
||||||
|
'options': dict({
|
||||||
|
'account_balance_currencies': list([
|
||||||
|
]),
|
||||||
|
'exchange_rate_currencies': list([
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
'pref_disable_new_entities': False,
|
||||||
|
'pref_disable_polling': False,
|
||||||
|
'source': 'user',
|
||||||
|
'title': '**REDACTED**',
|
||||||
|
'unique_id': None,
|
||||||
|
'version': 1,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
# ---
|
|
@ -1,6 +1,8 @@
|
||||||
"""Test the Coinbase diagnostics."""
|
"""Test the Coinbase diagnostics."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from syrupy import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .common import (
|
from .common import (
|
||||||
|
@ -9,14 +11,15 @@ from .common import (
|
||||||
mock_get_exchange_rates,
|
mock_get_exchange_rates,
|
||||||
mocked_get_accounts,
|
mocked_get_accounts,
|
||||||
)
|
)
|
||||||
from .const import MOCK_ACCOUNTS_RESPONSE_REDACTED, MOCK_ENTRY_REDACTED
|
|
||||||
|
|
||||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
from tests.typing import ClientSessionGenerator
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
async def test_entry_diagnostics(
|
async def test_entry_diagnostics(
|
||||||
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we handle a and redact a diagnostics request."""
|
"""Test we handle a and redact a diagnostics request."""
|
||||||
|
|
||||||
|
@ -34,10 +37,4 @@ async def test_entry_diagnostics(
|
||||||
|
|
||||||
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||||
|
|
||||||
# Remove the ID to match the constant
|
assert result == snapshot
|
||||||
result["entry"].pop("entry_id")
|
|
||||||
|
|
||||||
assert result == {
|
|
||||||
"entry": MOCK_ENTRY_REDACTED,
|
|
||||||
"accounts": MOCK_ACCOUNTS_RESPONSE_REDACTED,
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue