From dc257240808f3612396805bbecd513436c43489c Mon Sep 17 00:00:00 2001 From: Laurent Mazuel Date: Thu, 18 Jun 2020 13:28:46 -0700 Subject: [PATCH] Make it better --- .../azure-core/azure/core/pipeline/transport/_base.py | 8 +++++++- sdk/core/azure-core/tests/test_pipeline.py | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sdk/core/azure-core/azure/core/pipeline/transport/_base.py b/sdk/core/azure-core/azure/core/pipeline/transport/_base.py index 5730c0b559b3..0f4b7534824c 100644 --- a/sdk/core/azure-core/azure/core/pipeline/transport/_base.py +++ b/sdk/core/azure-core/azure/core/pipeline/transport/_base.py @@ -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) diff --git a/sdk/core/azure-core/tests/test_pipeline.py b/sdk/core/azure-core/tests/test_pipeline.py index 8921302276aa..bbbd37c09f5e 100644 --- a/sdk/core/azure-core/tests/test_pipeline.py +++ b/sdk/core/azure-core/tests/test_pipeline.py @@ -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):