Skip to content

Commit

Permalink
Unpack params before performing an api call
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenhesselink committed Jul 24, 2024
1 parent aedc634 commit 452c59a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mollie/api/objects/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
23 changes: 23 additions & 0 deletions tests/test_balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from mollie.api.objects.balance_report import BalanceReport
from mollie.api.objects.balance_transaction import BalanceTransaction

from unittest.mock import patch

from .utils import assert_list_object

BALANCE_ID = "bal_gVMhHKqSSRYJyPsuoPNFH"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 452c59a

Please sign in to comment.