-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Description
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:
import urllib.parse
import pysnow
import pytest
import requests_mock
@pytest.fixture
def requests_mocker():
with requests_mock.Mocker(real_http=True) as m:
yield m
def test_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`` instantiation
instance = "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)
assert response._response.status_code == 200
assert response.one() == dino
# THEN ``pysnow.Resource.parameters.query`` is persisted
querystring = urllib.parse.urlencode(query)
assert resource.parameters.query == querystring
assert resource.parameters.query != ""Metadata
Metadata
Assignees
Labels
No labels