Skip to content

Commit

Permalink
Make it better
Browse files Browse the repository at this point in the history
  • Loading branch information
lmazuel committed Jun 18, 2020
1 parent fa39b65 commit dc25724
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion sdk/core/azure-core/azure/core/pipeline/transport/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,13 @@ def format_url(self, url_template, **kwargs):
parsed = urlparse(url)
if not parsed.scheme or not parsed.netloc:
url = url.lstrip("/")
base = _format_url_section(self._base_url, **kwargs).rstrip("/")
try:
base = self._base_url.format(**kwargs).rstrip("/")
except KeyError as key:
raise ValueError(
"The value provided for the url part {} was incorrect, and resulted in an invalid url".format(key.args[0])
)

url = _urljoin(base, url)
else:
url = self._base_url.format(**kwargs)
Expand Down
6 changes: 3 additions & 3 deletions sdk/core/azure-core/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ def test_format_url_no_base_url(self):
def test_format_incorrect_endpoint(self):
# https://github.com/Azure/azure-sdk-for-python/pull/12106
client = PipelineClientBase('{Endpoint}/text/analytics/v3.0')
formatted = client.format_url("foo/bar")
# We don't care about the value, we care it doesn't fail
assert formatted is not None
with pytest.raises(ValueError) as exp:
client.format_url("foo/bar")
assert str(exp.value) == "The value provided for the url part Endpoint was incorrect, and resulted in an invalid url"

class TestClientRequest(unittest.TestCase):
def test_request_json(self):
Expand Down

0 comments on commit dc25724

Please sign in to comment.