diff --git a/src/client/Python/msrest/msrest/pipeline.py b/src/client/Python/msrest/msrest/pipeline.py index a376139a22f1a..04410ec19ca37 100644 --- a/src/client/Python/msrest/msrest/pipeline.py +++ b/src/client/Python/msrest/msrest/pipeline.py @@ -27,6 +27,10 @@ import functools import json import logging +try: + from urlparse import urlparse +except ImportError: + from urllib.parse import urlparse import requests from requests.packages.urllib3 import Retry @@ -195,6 +199,14 @@ def format_parameters(self, params): :param dict params: A dictionary of parameters. """ + query = urlparse(self.url).query + if query: + self.url = self.url.partition('?')[0] + existing_params = { + p[0]: p[-1] + for p in [p.partition('=') for p in query.split('&')] + } + params.update(existing_params) query_params = ["{}={}".format(k, v) for k, v in params.items()] query = '?' + '&'.join(query_params) self.url = self.url + query diff --git a/src/client/Python/msrest/readme.rst b/src/client/Python/msrest/readme.rst index 3ddf58e590307..214f6f7b5ae18 100644 --- a/src/client/Python/msrest/readme.rst +++ b/src/client/Python/msrest/readme.rst @@ -15,6 +15,13 @@ To install: Release History --------------- +2016-xx-xx Version xxxxx +++++++++++++++++++++++++ + +**Bugfixes** + +- Allow url of ClientRequest to have parameters (https://github.com/Azure/autorest/issues/1217) + 2016-05-25 Version 0.4.0 ++++++++++++++++++++++++ diff --git a/src/client/Python/msrest/test/unittest_pipeline.py b/src/client/Python/msrest/test/unittest_pipeline.py index dd757191befb5..cb5a1e7fb7a1f 100644 --- a/src/client/Python/msrest/test/unittest_pipeline.py +++ b/src/client/Python/msrest/test/unittest_pipeline.py @@ -167,6 +167,17 @@ def test_request_data(self): self.assertEqual(request.data, json.dumps(data)) self.assertEqual(request.headers.get('Content-Length'), 17) + def test_request_url_with_params(self): + + request = ClientRequest() + request.url = "a/b/c?t=y" + request.format_parameters({'g': 'h'}) + + self.assertIn(request.url, [ + 'a/b/c?g=h&t=y', + 'a/b/c?t=y&g=h' + ]) + class TestClientResponse(unittest.TestCase): class Colors(Enum): diff --git a/src/client/Python/msrest/tox.ini b/src/client/Python/msrest/tox.ini index 52dff903bbda4..7939eaafef286 100644 --- a/src/client/Python/msrest/tox.ini +++ b/src/client/Python/msrest/tox.ini @@ -7,7 +7,7 @@ changedir=test commands= coverage run -m unittest discover -s . -p unittest*.py -t .. -v coverage report --fail-under=40 --omit=unittest*,*.tox*.py - flake8 .. --exclude=unittest*.py,doc --statistics + flake8 .. --exclude=unittest*.py,doc,env --statistics [testenv:py27] deps=