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
Provenance
- Commit
e40b0bf- Tree
b216eab- Author
Tom Christie <tom@tomchristie.com>- Committer
Tom Christie <tom@tomchristie.com>- Parent
3d997af
1 file changed+17 added−19 removed
modified:tests/client/test_redirects.py+17 added-19 removed
87 unmodified lines88 89 @pytest.mark.asyncio90 async 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) == 196 97 98 @pytest.mark.asyncio99 async 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) == 1105 106 107 @pytest.mark.asyncio108 async 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) == 1114 115 116 @pytest.mark.asyncio117 async 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) == 06 unmodified lines131 132 @pytest.mark.asyncio133 async 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) == 1139 140 141 @pytest.mark.asyncio142 async 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) == 1148 149 150 @pytest.mark.asyncio151 async 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) == 1157 158 159 @pytest.mark.asyncio160 async 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 line168 @pytest.mark.asyncio169 async 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")173 174 175 @pytest.mark.asyncio176 async 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 line185 @pytest.mark.asyncio186 async 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")190 191 192 @pytest.mark.asyncio193 async 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 lines203 async 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 lines214 async 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 lines225 async 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 lines240 async def streaming_body():241 yield b"Example request body"242 243 with pytest.raises(RedirectBodyUnavailable):246- await client.request("POST", url, data=streaming_body())244+ await client.post(url, data=streaming_body())