From 55cbdd57bbc8f7ddb0fcaf096480c1a72206ba31 Mon Sep 17 00:00:00 2001 From: Ruben Hesselink Date: Wed, 24 Jul 2024 14:14:47 +0200 Subject: [PATCH] Unpack params before performing an api call --- mollie/api/objects/balance.py | 4 ++-- tests/test_balances.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/mollie/api/objects/balance.py b/mollie/api/objects/balance.py index a2ea543a..b101101f 100644 --- a/mollie/api/objects/balance.py +++ b/mollie/api/objects/balance.py @@ -57,9 +57,9 @@ def pending_amount(self): def get_report(self, **params: Any) -> BalanceReport: from ..resources import BalanceReports - return BalanceReports(self.client, self).get_report(params=params) + return BalanceReports(self.client, self).get_report(**params) def get_transactions(self, **params: Any) -> PaginationList: from ..resources import BalanceTransactions - return BalanceTransactions(self.client, self).list(params=params) + return BalanceTransactions(self.client, self).list(**params) diff --git a/tests/test_balances.py b/tests/test_balances.py index 375efb74..3df1af51 100644 --- a/tests/test_balances.py +++ b/tests/test_balances.py @@ -1,3 +1,5 @@ +from unittest.mock import patch + import pytest from mollie.api.error import IdentifierError @@ -95,6 +97,27 @@ def test_get_balance_transactions(client, response): assert balance_transaction.context == {"paymentId": "tr_7UhSN1zuXS", "refundId": "re_4qqhO89gsT"} +def test_get_balance_transactions_with_params(client, response): + """Get a list of balance transactions with parameters.""" + response.get(f"https://api.mollie.com/v2/balances/{BALANCE_ID}", "balance_single") + + balance = client.balances.get(BALANCE_ID) + params = {"limit": 5, "sort": "asc"} + + with patch("mollie.api.resources.base.ResourceListMixin.perform_api_call") as mock_perform_api_call: + balance.get_transactions(**params) + + # Assert perform_api_call was called + mock_perform_api_call.assert_called_once() + + # Extract the parameters passed to perform_api_call + _, called_kwargs = mock_perform_api_call.call_args + called_params = called_kwargs.get("params") + + # Assert the params are what we expect + assert called_params == params + + def test_get_balance_invalid_id(client): """Test that the balance ID is validated upon retrieving a balance.