Skip to content
Myr

Use httpbin to assert the final redirection URL

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

authored by Ryan Munro · committed by Ryan Munro · parent 1f05867 · Browse files · 1 file+9 added−7 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+9 added−7 removed

  • other:+9 added−7 removed

1 file+9 added−7 removed

modified:test_requests.py+9 added-7 removed
188 unmodified lines
189 assert r.history[0].is_redirect190191 def test_HTTP_302_TOO_MANY_REDIRECTS(self, httpbin):192 try:193 requests.get(httpbin('redirect', '50'))193 requests.get(httpbin('relative-redirect', '50'))194 except TooManyRedirects as e:195 assert '/relative-redirect/20' in e.request.url196 assert e.request.url == e.response.url195 url = httpbin('relative-redirect', '20')196 assert e.request.url == url197 assert e.response.url == url198 assert len(e.response.history) == 30199 else:200 pytest.fail('Expected redirect to raise TooManyRedirects but it did not')201202 def test_HTTP_302_TOO_MANY_REDIRECTS_WITH_PARAMS(self, httpbin):203 s = requests.session()204 s.max_redirects = 5205 try:205 s.get(httpbin('redirect', '50'))206 s.get(httpbin('relative-redirect', '50'))207 except TooManyRedirects as e:207 assert '/relative-redirect/45' in e.request.url208 assert e.request.url == e.response.url208 url = httpbin('relative-redirect', '45')209 assert e.request.url == url210 assert e.response.url == url211 assert len(e.response.history) == 5212 else:211 pytest.fail('Expected redirect to raise TooManyRedirects but it did not')213 pytest.fail('Expected custom max number of redirects to be respected but was not')214215 # def test_HTTP_302_ALLOW_REDIRECT_POST(self):216 # r = requests.post(httpbin('status', '302'), data={'some': 'data'})217 # self.assertEqual(r.status_code, 200)
1553 unmodified lines