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
importurllib.parseimportpysnowimportpytestimportrequests_mock@pytest.fixturedefrequests_mocker():
withrequests_mock.Mocker(real_http=True) asm:
yieldmdeftest_resource_get_parameters_persist(requests_mocker):
"""Identify and track a bug where ``pysnow.Resource.parameters.query`` is persisted on the resource instance. A shallow copy of ``pysnow.Resource.parameters`` (see [1]) is passed to ``pysnow.request.SnowRequest`` and any parameters passed to ``pysnow.Resource.get`` (i.e., ``pysnow.request.SnowRequest.get``; see [2]) will be persisted due to ``pysnow.request.SnowRequest.parameters`` being a shallow copy of ``pysnow.Resource.parameters``. Also see ``tests/unit/limpbot/servicenow/test_client_resource.py:test_resource_get_parameters_do_not_persist``. [1]: https://github.com/rbw/pysnow/blob/caad5bf/pysnow/resource.py#L82 [2]: https://github.com/rbw/pysnow/blob/caad5bf/pysnow/request.py#L99 """# GIVEN a ``pysnow.Resource`` instantiationinstance="eggspam"dino= {"sys_id": "1234", "name": "Dino", "breed": "ACD"}
requests_mocker.get(
f"https://{instance}.service-now.com/api/now/table/u_dog",
json={"result": [dino]},
)
client=pysnow.Client(instance=instance, user="foo", password="bar")
resource=client.resource(api_path="/table/u_dog")
# WHEN passing a ``query`` paraemeter to ``pysnow.Resource.get``query= {"name": "Dino"}
response=resource.get(query=query)
assertresponse._response.status_code==200assertresponse.one() ==dino# THEN ``pysnow.Resource.parameters.query`` is persistedquerystring=urllib.parse.urlencode(query)
assertresource.parameters.query==querystringassertresource.parameters.query!=""
The text was updated successfully, but these errors were encountered:
Ran into an issue where I noticed URLs including query parameters from previous requests. Tracked it down to a shallow copy of parameters which gets persisted on the resource.
I reproduced with the following test file:
The text was updated successfully, but these errors were encountered: