You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Passing any of the query parameter settings to the Mock constructor results in the following error:
> pook.get(url="https://example.com", params={"a": "b"})
src/pook/api.py:342: in get
return mock(url, method="GET", **kw)
src/pook/api.py:326: in mock
return _engine.mock(url, **kw)
src/pook/engine.py:150: in mock
mock = Mock(url=url, **kw)
src/pook/mock.py:130: in __init__
trigger_methods(self, kw)
src/pook/helpers.py:41: in trigger_methods
member(value)
src/pook/mock.py:355: in params
url = furl(self._request.rawurl)
src/pook/request.py:81: in rawurl
return self._url if isregex(self._url) else urlunparse(self._url)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
components = None
def urlunparse(components):
"""Put a parsed URL back together again. This may result in a
slightly different, but equivalent URL, if the URL that was parsed
originally had redundant delimiters, e.g. a ? with an empty query
(the draft states that these are equivalent)."""
scheme, netloc, url, params, query, fragment, _coerce_result = (
> _coerce_args(*components))
E TypeError: urllib.parse._coerce_args() argument after * must be an iterable, not NoneType
/usr/lib64/python3.12/urllib/parse.py:515: TypeError
This is because params is called on the Mock instance by trigger_methods without a url necessarily being present. The implementation of Mock::params is such that a urlmust be set on the request object before. This happens even if url is passed to the constructor because this line sorts the keys before iteration, causing params to get handled before url:
A better solution than sorting the list would be to keep a static list of the methods that should be executed in the order they're meant to be. For consistency, this should start with the alphabetical order to maintain the current behaviour, but include the fix to move url forward ahead of other methods that depend on it.
Ideally, the mock would be lazy in these cases and wait to process the param inputs until the URL is set. This would be more flexible overall anyway, as it would allow for the creation of a mock factory function in testing code that sets up params without the URL, and wouldn't behave in such an unexpected way.
The text was updated successfully, but these errors were encountered:
Passing any of the query parameter settings to the
Mock
constructor results in the following error:This is because
params
is called on theMock
instance bytrigger_methods
without aurl
necessarily being present. The implementation ofMock::params
is such that aurl
must be set on the request object before. This happens even ifurl
is passed to the constructor because this line sorts the keys before iteration, causingparams
to get handled beforeurl
:pook/src/pook/helpers.py
Line 18 in 16ecba6
A better solution than sorting the list would be to keep a static list of the methods that should be executed in the order they're meant to be. For consistency, this should start with the alphabetical order to maintain the current behaviour, but include the fix to move
url
forward ahead of other methods that depend on it.Ideally, the mock would be lazy in these cases and wait to process the param inputs until the URL is set. This would be more flexible overall anyway, as it would allow for the creation of a mock factory function in testing code that sets up params without the URL, and wouldn't behave in such an unexpected way.
The text was updated successfully, but these errors were encountered: