Skip to content
Myr

Tidy up redirect tests

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

authored by Tom Christie · committed by Tom Christie · parent 3d997af · Browse files · 1 file+17 added−19 removed
This commit

State

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

Diff stats

1 file+17 added−19 removed

  • tests:+17 added−19 removed

1 file+17 added−19 removed

modified:tests/client/test_redirects.py+17 added-19 removed
87 unmodified lines
8889@pytest.mark.asyncio90async def test_redirect_301():91 client = AsyncClient(dispatch=MockDispatch())92 response = await client.request("POST", "https://example.org/redirect_301")92 response = await client.post("https://example.org/redirect_301")93 assert response.status_code == codes.OK94 assert response.url == URL("https://example.org/")95 assert len(response.history) == 1969798@pytest.mark.asyncio99async def test_redirect_302():100 client = AsyncClient(dispatch=MockDispatch())101 response = await client.request("POST", "https://example.org/redirect_302")101 response = await client.post("https://example.org/redirect_302")102 assert response.status_code == codes.OK103 assert response.url == URL("https://example.org/")104 assert len(response.history) == 1105106107@pytest.mark.asyncio108async def test_redirect_303():109 client = AsyncClient(dispatch=MockDispatch())110 response = await client.request("GET", "https://example.org/redirect_303")110 response = await client.get("https://example.org/redirect_303")111 assert response.status_code == codes.OK112 assert response.url == URL("https://example.org/")113 assert len(response.history) == 1114115116@pytest.mark.asyncio117async def test_disallow_redirects():118 client = AsyncClient(dispatch=MockDispatch())119 response = await client.request(120 "POST", "https://example.org/redirect_303", allow_redirects=False119 response = await client.post(120 "https://example.org/redirect_303", allow_redirects=False121 )122 assert response.status_code == codes.SEE_OTHER123 assert response.url == URL("https://example.org/redirect_303")124 assert len(response.history) == 0
6 unmodified lines
131132@pytest.mark.asyncio133async def test_relative_redirect():134 client = AsyncClient(dispatch=MockDispatch())135 response = await client.request("GET", "https://example.org/relative_redirect")135 response = await client.get("https://example.org/relative_redirect")136 assert response.status_code == codes.OK137 assert response.url == URL("https://example.org/")138 assert len(response.history) == 1139140141@pytest.mark.asyncio142async def test_no_scheme_redirect():143 client = AsyncClient(dispatch=MockDispatch())144 response = await client.request("GET", "https://example.org/no_scheme_redirect")144 response = await client.get("https://example.org/no_scheme_redirect")145 assert response.status_code == codes.OK146 assert response.url == URL("https://example.org/")147 assert len(response.history) == 1148149150@pytest.mark.asyncio151async def test_fragment_redirect():152 client = AsyncClient(dispatch=MockDispatch())153 url = "https://example.org/relative_redirect#fragment"154 response = await client.request("GET", url)153 response = await client.get("https://example.org/relative_redirect#fragment")154 assert response.status_code == codes.OK155 assert response.url == URL("https://example.org/#fragment")156 assert len(response.history) == 1157158159@pytest.mark.asyncio160async def test_multiple_redirects():161 client = AsyncClient(dispatch=MockDispatch())163 url = "https://example.org/multiple_redirects?count=20"164 response = await client.request("GET", url)162 response = await client.get("https://example.org/multiple_redirects?count=20")163 assert response.status_code == codes.OK164 assert response.url == URL("https://example.org/multiple_redirects")165 assert len(response.history) == 20166
1 unmodified line
168@pytest.mark.asyncio169async def test_too_many_redirects():170 client = AsyncClient(dispatch=MockDispatch())171 with pytest.raises(TooManyRedirects):174 await client.request("GET", "https://example.org/multiple_redirects?count=21")172 await client.get("https://example.org/multiple_redirects?count=21")173174175@pytest.mark.asyncio176async def test_too_many_redirects_calling_next():177 client = AsyncClient(dispatch=MockDispatch())178 url = "https://example.org/multiple_redirects?count=21"181 response = await client.request("GET", url, allow_redirects=False)179 response = await client.get(url, allow_redirects=False)180 with pytest.raises(TooManyRedirects):181 while response.is_redirect:182 response = await response.next()183
1 unmodified line
185@pytest.mark.asyncio186async def test_redirect_loop():187 client = AsyncClient(dispatch=MockDispatch())188 with pytest.raises(RedirectLoop):191 await client.request("GET", "https://example.org/redirect_loop")189 await client.get("https://example.org/redirect_loop")190191192@pytest.mark.asyncio193async def test_redirect_loop_calling_next():194 client = AsyncClient(dispatch=MockDispatch())195 url = "https://example.org/redirect_loop"198 response = await client.request("GET", url, allow_redirects=False)196 response = await client.get(url, allow_redirects=False)197 with pytest.raises(RedirectLoop):198 while response.is_redirect:199 response = await response.next()200
2 unmodified lines
203async def test_cross_domain_redirect():204 client = AsyncClient(dispatch=MockDispatch())205 url = "https://example.com/cross_domain"206 headers = {"Authorization": "abc"}209 response = await client.request("GET", url, headers=headers)207 response = await client.get(url, headers=headers)208 data = json.loads(response.content.decode())209 assert response.url == URL("https://example.org/cross_domain_target")210 assert "authorization" not in data["headers"]211
2 unmodified lines
214async def test_same_domain_redirect():215 client = AsyncClient(dispatch=MockDispatch())216 url = "https://example.org/cross_domain"217 headers = {"Authorization": "abc"}220 response = await client.request("GET", url, headers=headers)218 response = await client.get(url, headers=headers)219 data = json.loads(response.content.decode())220 assert response.url == URL("https://example.org/cross_domain_target")221 assert data["headers"]["authorization"] == "abc"222
2 unmodified lines
225async def test_body_redirect():226 client = AsyncClient(dispatch=MockDispatch())227 url = "https://example.org/redirect_body"228 data = b"Example request body"231 response = await client.request("POST", url, data=data)229 response = await client.post(url, data=data)230 data = json.loads(response.content.decode())231 assert response.url == URL("https://example.org/redirect_body_target")232 assert data == {"body": "Example request body"}233
6 unmodified lines
240 async def streaming_body():241 yield b"Example request body"242243 with pytest.raises(RedirectBodyUnavailable):246 await client.request("POST", url, data=streaming_body())244 await client.post(url, data=streaming_body())