Skip to content

Fix testmode when following pagination and _links URLs - #398

Open
ratomirjovanovic wants to merge 1 commit into
mollie:mainfrom
ratomirjovanovic:fix/testmode-params-none
Open

ratomirjovanovic wants to merge 1 commit into
mollie:mainfrom
ratomirjovanovic:fix/testmode-params-none

Conversation

@ratomirjovanovic

Copy link
Copy Markdown

With set_testmode(True) on an OAuth or access token client, any GET made without params fails in _get_testmode, because params is None there and the code does params["testmode"] = params.get(...):

AttributeError: 'NoneType' object has no attribute 'get'

PaginationList.get_next() / get_previous() and ResourceBase.from_url() all call perform_api_call without params, so in testmode you can't go past the first page of a list or follow a link like payment.customer. #390 was the same crash for data=None, fixed in #387; this is the params side.

Fixing only that isn't enough: those URLs already have a querystring (.../customers?from=cst_...&limit=5), and _format_request_data appends the extra params with another ?, so the request would go to ...&limit=5?testmode=true. This change:

  • treats params=None as {} in _get_testmode
  • appends params to a URL that already has a querystring with &, and skips params the URL already contains

Tests: added the None params cases to test__get_testmode_sets_data_or_params_correctly, a test that pages through customers in testmode and checks the second request is ?from=cst_8pknKQJzJa&limit=5&testmode=true, and a test that a param already in the URL isn't added twice. All of them fail on main and pass with this change.

Ran pytest (285 passed), flake8 and mypy --config mypy.ini mollie/ locally.

_get_testmode assumed params was a dict, so with testmode enabled every
request made without params (PaginationList.get_next/get_previous and
from_url) failed with an AttributeError. Links from the API also already
carry a querystring, so append extra params with "&" and skip the ones
the link already has.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant