|
22 | 22 | RetryPolicy, |
23 | 23 | HTTPPolicy, |
24 | 24 | ) |
25 | | -from corehttp.runtime._base import PipelineClientBase, _format_url_section |
| 25 | +from corehttp.runtime._base import PipelineClientBase, _format_url_section, _urljoin |
26 | 26 | from corehttp.transport import HttpTransport |
27 | 27 | from corehttp.transport.requests import RequestsTransport |
28 | 28 | from corehttp.transport.httpx import HttpXTransport |
@@ -90,6 +90,25 @@ def test_transport_socket_timeout(transport): |
90 | 90 | response = pipeline.run(request, connection_timeout=0.000001, read_timeout=0.000001) |
91 | 91 |
|
92 | 92 |
|
| 93 | +def test_url_join(): |
| 94 | + assert _urljoin("devstoreaccount1", "?testdir") == "devstoreaccount1?testdir" |
| 95 | + assert _urljoin("devstoreaccount1", "?testdir=foo") == "devstoreaccount1?testdir=foo" |
| 96 | + assert _urljoin("devstoreaccount1/api", "?a=1") == "devstoreaccount1/api?a=1" |
| 97 | + assert ( |
| 98 | + _urljoin("devstoreaccount1", "/?restype=service&comp=properties") |
| 99 | + == "devstoreaccount1/?restype=service&comp=properties" |
| 100 | + ) |
| 101 | + assert _urljoin("devstoreaccount1", "") == "devstoreaccount1" |
| 102 | + assert _urljoin("devstoreaccount1", "testdir/") == "devstoreaccount1/testdir/" |
| 103 | + assert _urljoin("devstoreaccount1/", "") == "devstoreaccount1/" |
| 104 | + assert _urljoin("devstoreaccount1/", "/testdir/") == "devstoreaccount1/testdir/" |
| 105 | + assert _urljoin("devstoreaccount1/", "testdir/") == "devstoreaccount1/testdir/" |
| 106 | + assert _urljoin("devstoreaccount1?a=1", "testdir/") == "devstoreaccount1/testdir/?a=1" |
| 107 | + assert _urljoin("devstoreaccount1", "testdir/?b=2") == "devstoreaccount1/testdir/?b=2" |
| 108 | + assert _urljoin("devstoreaccount1?a=1", "testdir/?b=2") == "devstoreaccount1/testdir/?a=1&b=2" |
| 109 | + assert _urljoin("devstoreaccount1", "documentModels:build") == "devstoreaccount1/documentModels:build" |
| 110 | + |
| 111 | + |
93 | 112 | def test_format_url_basic(): |
94 | 113 | client = PipelineClientBase("https://bing.com") |
95 | 114 | formatted = client.format_url("/{foo}", foo="bar") |
@@ -177,6 +196,39 @@ def test_format_incorrect_endpoint(): |
177 | 196 | ) |
178 | 197 |
|
179 | 198 |
|
| 199 | +def test_format_url_query_strings(): |
| 200 | + client = PipelineClientBase("https://foo.core.windows.net") |
| 201 | + formatted = client.format_url("/") |
| 202 | + assert formatted == "https://foo.core.windows.net/" |
| 203 | + |
| 204 | + formatted = client.format_url("/?a=X&c=Y") |
| 205 | + assert formatted == "https://foo.core.windows.net/?a=X&c=Y" |
| 206 | + |
| 207 | + formatted = client.format_url("?a=X&c=Y") |
| 208 | + assert formatted == "https://foo.core.windows.net?a=X&c=Y" |
| 209 | + |
| 210 | + formatted = client.format_url("/Tables/?a=X&c=Y") |
| 211 | + assert formatted == "https://foo.core.windows.net/Tables/?a=X&c=Y" |
| 212 | + |
| 213 | + formatted = client.format_url("/Tables?a=X&c=Y") |
| 214 | + assert formatted == "https://foo.core.windows.net/Tables?a=X&c=Y" |
| 215 | + |
| 216 | + |
| 217 | +def test_format_url_from_http_request(): |
| 218 | + client = PipelineClientBase("https://foo.core.windows.net") |
| 219 | + |
| 220 | + _url = "/" |
| 221 | + _params = {"foo": "bar"} |
| 222 | + request = HttpRequest("GET", _url, params=_params) |
| 223 | + formatted = client.format_url(request.url) |
| 224 | + assert formatted == "https://foo.core.windows.net/?foo=bar" |
| 225 | + |
| 226 | + _url = "?restype=service&comp=properties" |
| 227 | + request = HttpRequest("GET", _url) |
| 228 | + formatted = client.format_url(request.url) |
| 229 | + assert formatted == "https://foo.core.windows.net?restype=service&comp=properties" |
| 230 | + |
| 231 | + |
180 | 232 | def test_request_json(): |
181 | 233 |
|
182 | 234 | data = "Lots of dataaaa" |
|
0 commit comments