Skip to content
Myr

Replace httpx.URL for str in tests (#1237)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Eduardo Enriquez · committed by GitHub · parent 9200cb0 · Browse files · 4 files+26 added−32 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Eduardo Enriquez (eduzen) <eduardo.enriquez@freshbooks.com>

Diff stats

4 files+26 added−32 removed

  • tests:+26 added−32 removed

4 files+26 added−32 removed

modified:tests/client/test_client.py+4 added-4 removed
176 unmodified lines
177178def test_merge_absolute_url():179 client = httpx.Client(base_url="https://www.example.com/")180 request = client.build_request("GET", "http://www.example.com/")181 assert request.url == httpx.URL("http://www.example.com/")181 assert request.url == "http://www.example.com/"182 with pytest.warns(DeprecationWarning):183 assert not request.url.is_ssl184185186def test_merge_relative_url():187 client = httpx.Client(base_url="https://www.example.com/")188 request = client.build_request("GET", "/testing/123")189 assert request.url == httpx.URL("https://www.example.com/testing/123")189 assert request.url == "https://www.example.com/testing/123"190191192def test_merge_relative_url_with_path():193 client = httpx.Client(base_url="https://www.example.com/some/path")194 request = client.build_request("GET", "/testing/123")195 assert request.url == httpx.URL("https://www.example.com/some/path/testing/123")195 assert request.url == "https://www.example.com/some/path/testing/123"196197198def test_merge_relative_url_with_dotted_path():199 client = httpx.Client(base_url="https://www.example.com/some/path")200 request = client.build_request("GET", "../testing/123")201 assert request.url == httpx.URL("https://www.example.com/some/testing/123")201 assert request.url == "https://www.example.com/some/testing/123"202203204def test_pool_limits_deprecated():205 limits = httpx.Limits()
44 unmodified lines
modified:tests/client/test_properties.py+3 added-3 removed
3 unmodified lines
4def test_client_base_url():5 client = httpx.Client()6 client.base_url = "https://www.example.org/" # type: ignore7 assert isinstance(client.base_url, httpx.URL)8 assert client.base_url == httpx.URL("https://www.example.org/")8 assert client.base_url == "https://www.example.org/"91011def test_client_base_url_without_trailing_slash():12 client = httpx.Client()13 client.base_url = "https://www.example.org/path" # type: ignore14 assert isinstance(client.base_url, httpx.URL)15 assert client.base_url == httpx.URL("https://www.example.org/path/")15 assert client.base_url == "https://www.example.org/path/"161718def test_client_base_url_with_trailing_slash():19 client = httpx.Client()20 client.base_url = "https://www.example.org/path/" # type: ignore21 assert isinstance(client.base_url, httpx.URL)22 assert client.base_url == httpx.URL("https://www.example.org/path/")22 assert client.base_url == "https://www.example.org/path/"232425def test_client_headers():26 client = httpx.Client()
25 unmodified lines
modified:tests/client/test_queryparams.py+1 added-3 removed
44 unmodified lines
45 client = httpx.Client(transport=MockTransport(), params=client_queryparams)46 response = client.get(url, params=request_queryparams)4748 assert response.status_code == 20049 assert response.url == httpx.URL(50 "http://example.org/echo_queryparams?first=str&second=dict"51 )49 assert response.url == "http://example.org/echo_queryparams?first=str&second=dict"
modified:tests/client/test_redirects.py+18 added-22 removed
184 unmodified lines
185def test_redirect_301():186 client = httpx.Client(transport=SyncMockTransport())187 response = client.post("https://example.org/redirect_301")188 assert response.status_code == httpx.codes.OK189 assert response.url == httpx.URL("https://example.org/")189 assert response.url == "https://example.org/"190 assert len(response.history) == 1191192193def test_redirect_302():194 client = httpx.Client(transport=SyncMockTransport())195 response = client.post("https://example.org/redirect_302")196 assert response.status_code == httpx.codes.OK197 assert response.url == httpx.URL("https://example.org/")197 assert response.url == "https://example.org/"198 assert len(response.history) == 1199200201def test_redirect_303():202 client = httpx.Client(transport=SyncMockTransport())203 response = client.get("https://example.org/redirect_303")204 assert response.status_code == httpx.codes.OK205 assert response.url == httpx.URL("https://example.org/")205 assert response.url == "https://example.org/"206 assert len(response.history) == 1207208209def test_disallow_redirects():210 client = httpx.Client(transport=SyncMockTransport())211 response = client.post("https://example.org/redirect_303", allow_redirects=False)212 assert response.status_code == httpx.codes.SEE_OTHER213 assert response.url == httpx.URL("https://example.org/redirect_303")213 assert response.url == "https://example.org/redirect_303"214 assert response.is_redirect is True215 assert len(response.history) == 0216217 response = response.next()218 assert response.status_code == httpx.codes.OK219 assert response.url == httpx.URL("https://example.org/")219 assert response.url == "https://example.org/"220 assert response.is_redirect is False221 assert len(response.history) == 1222223
3 unmodified lines
227 """228 client = httpx.Client(transport=SyncMockTransport())229 response = client.head("https://example.org/redirect_302")230 assert response.status_code == httpx.codes.OK231 assert response.url == httpx.URL("https://example.org/")231 assert response.url == "https://example.org/"232 assert response.request.method == "HEAD"233 assert len(response.history) == 1234 assert response.text == ""235
1 unmodified line
237def test_relative_redirect():238 client = httpx.Client(transport=SyncMockTransport())239 response = client.get("https://example.org/relative_redirect")240 assert response.status_code == httpx.codes.OK241 assert response.url == httpx.URL("https://example.org/")241 assert response.url == "https://example.org/"242 assert len(response.history) == 1243244245def test_malformed_redirect():246 # https://github.com/encode/httpx/issues/771247 client = httpx.Client(transport=SyncMockTransport())248 response = client.get("http://example.org/malformed_redirect")249 assert response.status_code == httpx.codes.OK250 assert response.url == httpx.URL("https://example.org:443/")250 assert response.url == "https://example.org:443/"251 assert len(response.history) == 1252253254def test_invalid_redirect():
5 unmodified lines
260def test_no_scheme_redirect():261 client = httpx.Client(transport=SyncMockTransport())262 response = client.get("https://example.org/no_scheme_redirect")263 assert response.status_code == httpx.codes.OK264 assert response.url == httpx.URL("https://example.org/")264 assert response.url == "https://example.org/"265 assert len(response.history) == 1266267268def test_fragment_redirect():269 client = httpx.Client(transport=SyncMockTransport())270 response = client.get("https://example.org/relative_redirect#fragment")271 assert response.status_code == httpx.codes.OK272 assert response.url == httpx.URL("https://example.org/#fragment")272 assert response.url == "https://example.org/#fragment"273 assert len(response.history) == 1274275276def test_multiple_redirects():277 client = httpx.Client(transport=SyncMockTransport())278 response = client.get("https://example.org/multiple_redirects?count=20")279 assert response.status_code == httpx.codes.OK280 assert response.url == httpx.URL("https://example.org/multiple_redirects")280 assert response.url == "https://example.org/multiple_redirects"281 assert len(response.history) == 20282 assert response.history[0].url == httpx.URL(283 "https://example.org/multiple_redirects?count=20"284 )285 assert response.history[1].url == httpx.URL(286 "https://example.org/multiple_redirects?count=19"287 )282 assert response.history[0].url == "https://example.org/multiple_redirects?count=20"283 assert response.history[1].url == "https://example.org/multiple_redirects?count=19"284 assert len(response.history[0].history) == 0285 assert len(response.history[1].history) == 1286287
39 unmodified lines
327 client = httpx.Client(transport=SyncMockTransport())328 url = "https://example.com/cross_domain"329 headers = {"Authorization": "abc"}330 response = client.get(url, headers=headers)335 assert response.url == httpx.URL("https://example.org/cross_domain_target")331 assert response.url == "https://example.org/cross_domain_target"332 assert "authorization" not in response.json()["headers"]333334335def test_same_domain_redirect():336 client = httpx.Client(transport=SyncMockTransport())337 url = "https://example.org/cross_domain"338 headers = {"Authorization": "abc"}339 response = client.get(url, headers=headers)344 assert response.url == httpx.URL("https://example.org/cross_domain_target")340 assert response.url == "https://example.org/cross_domain_target"341 assert response.json()["headers"]["authorization"] == "abc"342343344def test_body_redirect():
3 unmodified lines
348 client = httpx.Client(transport=SyncMockTransport())349 url = "https://example.org/redirect_body"350 data = b"Example request body"351 response = client.post(url, data=data)356 assert response.url == httpx.URL("https://example.org/redirect_body_target")352 assert response.url == "https://example.org/redirect_body_target"353 assert response.json()["body"] == "Example request body"354 assert "content-length" in response.json()["headers"]355356
4 unmodified lines
361 client = httpx.Client(transport=SyncMockTransport())362 url = "https://example.org/redirect_no_body"363 data = b"Example request body"364 response = client.post(url, data=data)369 assert response.url == httpx.URL("https://example.org/redirect_body_target")365 assert response.url == "https://example.org/redirect_body_target"366 assert response.json()["body"] == ""367 assert "content-length" not in response.json()["headers"]368369
20 unmodified lines
390def test_cross_subdomain_redirect():391 client = httpx.Client(transport=SyncMockTransport())392 url = "https://example.com/cross_subdomain"393 response = client.get(url)398 assert response.url == httpx.URL("https://www.example.org/cross_subdomain")394 assert response.url == "https://www.example.org/cross_subdomain"395396397class MockCookieTransport(httpcore.SyncHTTPTransport):398 def request(
82 unmodified lines