Skip to content
Myr

add laurentb's test case for cookie handling on redirects

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

authored by Shivaram Lingamneni · committed by Shivaram Lingamneni · parent 6eb349f · Browse files · 1 file+19 added−0 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+19 added−0 removed

  • tests:+19 added−0 removed

1 file+19 added−0 removed

modified:tests/test_requests_ext.py+19 added
102 unmodified lines
103 'News/~3/BQtUJRJeZlo/deal_view_investment.' +104 'php')105 assert r.ok106107 def test_cookies_on_redirects(self):108 """Test interaction between cookie handling and redirection."""109 # get a cookie for tinyurl.com ONLY110 s = requests.session()111 s.get(url='http://tinyurl.com/preview.php?disable=1')112 # we should have set a cookie for tinyurl: preview=0113 self.assertIn('preview', s.cookies)114 self.assertEqual(s.cookies['preview'], '0')115 self.assertEqual(list(s.cookies)[0].name, 'preview')116 self.assertEqual(list(s.cookies)[0].domain, 'tinyurl.com')117118 # get cookies on another domain119 r2 = s.get(url='http://httpbin.org/cookies')120 # the cookie is not there121 self.assertNotIn('preview', json.loads(r2.text)['cookies'])122123 # this redirects to another domain, httpbin.org124 # cookies of the first domain should NOT be sent to the next one125 r3 = s.get(url='http://tinyurl.com/7zp3jnr')126 assert r3.url == 'http://httpbin.org/cookies'127 self.assertNotIn('preview', json.loads(r2.text)['cookies'])128129if __name__ == '__main__':130 unittest.main()131