Clarify behaviour of InternalClient.make_request params arg

Update make_request docstring to clarify that if the params argument
is used it will override any query_string component of the path
argument.

Add a unit test to verify this.

No intended behavioural change.

Change-Id: I4b3f525fdbe6c67132384901071d6824c2964011
This commit is contained in:
Alistair Coles 2024-04-02 15:13:07 +01:00
parent d61e472936
commit f0e1713c8e
3 changed files with 29 additions and 2 deletions

View File

@ -199,8 +199,10 @@ class InternalClient(object):
:param acceptable_statuses: List of acceptable statuses for request.
:param body_file: Body file to be passed along with request,
defaults to None.
:param params: A dict of params to be set in request query string,
defaults to None.
:param params: A dict of params to be set in request query string. If
the ``path`` argument includes a query string, that
query string will be replaced by any params set by the
``params`` argument. Defaults to None.
:returns: Response object on success.

View File

@ -720,6 +720,25 @@ class TestInternalClient(unittest.TestCase):
self.assertEqual(client.app._pipeline_final_app.backend_user_agent,
'some_agent')
def test_make_request_query_string(self):
fake_swift = FakeSwift()
fake_swift.register('PUT', '/path', swob.HTTPOk, {})
client = internal_client.InternalClient(
None, 'some_agent', 3, use_replication_network=False,
app=fake_swift)
client.make_request('PUT', '/path?query=string', {}, (200,))
self.assertEqual([('PUT', '/path?query=string')], fake_swift.calls)
fake_swift.clear_calls()
client.make_request('PUT', '/path?query=string', {}, (200,), params={})
self.assertEqual([('PUT', '/path?query=string')], fake_swift.calls)
fake_swift.clear_calls()
client.make_request('PUT', '/path?query=string', {}, (200,),
params={'param1': 'one'})
self.assertEqual([('PUT', '/path?param1=one')], fake_swift.calls)
def test_make_request_error_case(self):
class FakeApp(FakeSwift):
def __call__(self, env, start_response):

View File

@ -610,6 +610,12 @@ class TestRequest(unittest.TestCase):
req.params = new_params
self.assertDictEqual(dict(new_params), req.params)
req = swob.Request.blank('/?a=b&c=d', params={'x': 'y'})
self.assertEqual(req.params, {'x': 'y'})
req = swob.Request.blank('/?a=b&c=d', params={})
self.assertFalse(req.params)
def test_unicode_params(self):
# NB: all of these strings are WSGI strings
req = swob.Request.blank(