From c39f6b3bea37139b842b47b8750b0cde80cbc64e Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Thu, 24 Aug 2023 01:23:31 +0200 Subject: [PATCH] Use snapshot assertion for Coinbase diagnostics test (#98906) --- tests/components/coinbase/common.py | 1 + tests/components/coinbase/const.py | 41 ----------- .../coinbase/snapshots/test_diagnostics.ambr | 70 +++++++++++++++++++ tests/components/coinbase/test_diagnostics.py | 15 ++-- 4 files changed, 77 insertions(+), 50 deletions(-) create mode 100644 tests/components/coinbase/snapshots/test_diagnostics.ambr diff --git a/tests/components/coinbase/common.py b/tests/components/coinbase/common.py index 4866039f310..6ab33f3bc7c 100644 --- a/tests/components/coinbase/common.py +++ b/tests/components/coinbase/common.py @@ -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"}, diff --git a/tests/components/coinbase/const.py b/tests/components/coinbase/const.py index 4db6abca37d..2b437e15478 100644 --- a/tests/components/coinbase/const.py +++ b/tests/components/coinbase/const.py @@ -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, -} diff --git a/tests/components/coinbase/snapshots/test_diagnostics.ambr b/tests/components/coinbase/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..c214330d5f9 --- /dev/null +++ b/tests/components/coinbase/snapshots/test_diagnostics.ambr @@ -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, + }), + }) +# --- diff --git a/tests/components/coinbase/test_diagnostics.py b/tests/components/coinbase/test_diagnostics.py index 73978790441..897722b32b4 100644 --- a/tests/components/coinbase/test_diagnostics.py +++ b/tests/components/coinbase/test_diagnostics.py @@ -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