From 24792744f9660063e1a3abb9ed8e925fea9a5e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elisi=C3=A1rio=20Couto?= Date: Wed, 24 Sep 2025 20:04:44 +0100 Subject: [PATCH] fix(api): Fix banks API test fixtures to match GoCardless response format. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated test fixtures to correctly mock GoCardless API response format with "results" key for institutions data. Fixed API client test to use processed institutions data instead of raw GoCardless format. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- tests/conftest.py | 34 ++++++++++++++++++---------------- tests/unit/test_api_banks.py | 2 +- tests/unit/test_api_client.py | 5 ++++- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7ebff10..2ce67d6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -103,22 +103,24 @@ def mock_db_path(temp_db_path): @pytest.fixture def sample_bank_data(): """Sample bank/institution data for testing.""" - return [ - { - "id": "REVOLUT_REVOLT21", - "name": "Revolut", - "bic": "REVOLT21", - "transaction_total_days": 90, - "countries": ["GB", "LT"], - }, - { - "id": "BANCOBPI_BBPIPTPL", - "name": "Banco BPI", - "bic": "BBPIPTPL", - "transaction_total_days": 90, - "countries": ["PT"], - }, - ] + return { + "results": [ + { + "id": "REVOLUT_REVOLT21", + "name": "Revolut", + "bic": "REVOLT21", + "transaction_total_days": 90, + "countries": ["GB", "LT"], + }, + { + "id": "BANCOBPI_BBPIPTPL", + "name": "Banco BPI", + "bic": "BBPIPTPL", + "transaction_total_days": 90, + "countries": ["PT"], + }, + ] + } @pytest.fixture diff --git a/tests/unit/test_api_banks.py b/tests/unit/test_api_banks.py index f3f97cd..1e08456 100644 --- a/tests/unit/test_api_banks.py +++ b/tests/unit/test_api_banks.py @@ -50,7 +50,7 @@ class TestBanksAPI: # Mock empty institutions response for invalid country respx.get("https://bankaccountdata.gocardless.com/api/v2/institutions/").mock( - return_value=httpx.Response(200, json=[]) + return_value=httpx.Response(200, json={"results": []}) ) with patch("leggen.utils.config.config", mock_config): diff --git a/tests/unit/test_api_client.py b/tests/unit/test_api_client.py index ce61d40..8a36689 100644 --- a/tests/unit/test_api_client.py +++ b/tests/unit/test_api_client.py @@ -37,9 +37,12 @@ class TestLeggenAPIClient: """Test getting institutions via API client.""" client = LeggenAPIClient("http://localhost:8000") + # The API returns processed institutions, not raw GoCardless data + processed_institutions = sample_bank_data["results"] + api_response = { "success": True, - "data": sample_bank_data, + "data": processed_institutions, "message": "Found 2 institutions for PT", }