Skip to content

Commit

Permalink
Fix runtime part of #1217 (#1224)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmazuel authored and fearthecowboy committed Jul 11, 2016
1 parent 6226c15 commit a9acdd5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/client/Python/msrest/msrest/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/client/Python/msrest/readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
++++++++++++++++++++++++

Expand Down
11 changes: 11 additions & 0 deletions src/client/Python/msrest/test/unittest_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/client/Python/msrest/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit a9acdd5

Please sign in to comment.