Use snapshot assertion for Coinbase diagnostics test (#98906)

This commit is contained in:
Joost Lekkerkerker 2023-08-24 01:23:31 +02:00 committed by GitHub
parent faa4489f4c
commit c39f6b3bea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 50 deletions

View file

@ -68,6 +68,7 @@ async def init_mock_coinbase(hass, currencies=None, rates=None):
"""Init Coinbase integration for testing."""
config_entry = MockConfigEntry(
domain=DOMAIN,
entry_id="080272b77a4f80c41b94d7cdc86fd826",
unique_id=None,
title="Test User",
data={CONF_API_KEY: "123456", CONF_API_TOKEN: "AbCDeF"},

View file

@ -1,6 +1,5 @@
"""Constants for testing the Coinbase integration."""
from homeassistant.components.diagnostics import REDACTED
GOOD_CURRENCY = "BTC"
GOOD_CURRENCY_2 = "USD"
@ -36,43 +35,3 @@ MOCK_ACCOUNTS_RESPONSE = [
"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,
}

View 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,
}),
})
# ---

View file

@ -1,6 +1,8 @@
"""Test the Coinbase diagnostics."""
from unittest.mock import patch
from syrupy import SnapshotAssertion
from homeassistant.core import HomeAssistant
from .common import (
@ -9,14 +11,15 @@ from .common import (
mock_get_exchange_rates,
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.typing import ClientSessionGenerator
async def test_entry_diagnostics(
hass: HomeAssistant, hass_client: ClientSessionGenerator
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
snapshot: SnapshotAssertion,
) -> None:
"""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)
# Remove the ID to match the constant
result["entry"].pop("entry_id")
assert result == {
"entry": MOCK_ENTRY_REDACTED,
"accounts": MOCK_ACCOUNTS_RESPONSE_REDACTED,
}
assert result == snapshot