test_requests_ext.py
This file
Path
tests/test_requests_ext.py
124 lines · 4.2 KiB · Python
Last changed by
Merge pull request #898 from rvoicilas/developKenneth Reitzbefore adoption4477d0a
History of this fileTake it
The walk stopped after 200 commits: lines older than 511b139 point at it.
Merge pull request #676 from apotheos/developKenneth Reitzbefore adoption511b139
lines 1–4why, one step back1#!/usr/bin/env python2# -*- coding: utf-8 -*-34# Path hack.Merge remote-tracking branch 'origin/develop' into developKenneth Reitzbefore adoptiona74c6c6
lines 5–6why, one step back5import os6import sysMerge pull request #676 from apotheos/developKenneth Reitzbefore adoption511b139
lines 7–26why, one step back7sys.path.insert(0, os.path.abspath('..'))89import unittest1011import requests12from requests.compat import is_py2, is_py31314try:15 import omnijson as json16except ImportError:17 import json181920class RequestsTestSuite(unittest.TestCase):21 """Requests test cases."""2223 # It goes to eleven.24 _multiprocess_can_split_ = True2526 def test_addition(self):Merge pull request #898 from rvoicilas/developKenneth Reitzbefore adoption4477d0a
line 27why, one step back27 self.assertEqual(2, 1 + 1)Merge pull request #676 from apotheos/developKenneth Reitzbefore adoption511b139
lines 28–81why, one step back2829 def test_ssl_hostname_ok(self):30 requests.get('https://github.com', verify=True)3132 def test_ssl_hostname_not_ok(self):33 requests.get('https://kennethreitz.com', verify=False)3435 self.assertRaises(requests.exceptions.SSLError, requests.get, 'https://kennethreitz.com')3637 def test_ssl_hostname_session_not_ok(self):3839 s = requests.session()4041 self.assertRaises(requests.exceptions.SSLError, s.get, 'https://kennethreitz.com')4243 s.get('https://kennethreitz.com', verify=False)4445 def test_binary_post(self):46 '''We need to be careful how we build the utf-8 string since47 unicode literals are a syntax error in python348 '''4950 if is_py2:51 # Blasphemy!52 utf8_string = eval("u'Smörgås'.encode('utf-8')")53 elif is_py3:54 utf8_string = 'Smörgås'.encode('utf-8')55 else:56 raise EnvironmentError('Flesh out this test for your environment.')57 requests.post('http://www.google.com/', data=utf8_string)5859 def test_unicode_error(self):60 url = 'http://blip.fm/~1abvfu'61 requests.get(url)6263 def test_chunked_head_redirect(self):64 url = "http://t.co/NFrx0zLG"65 r = requests.head(url, allow_redirects=True)66 self.assertEqual(r.status_code, 200)6768 def test_unicode_redirect(self):69 '''This url redirects to a location that has a nonstandard70 character in it, that breaks requests in python2.77172 After some research, the cause was identified as an unintended73 sideeffect of overriding of str with unicode.7475 In the case that the redirected url is actually a malformed76 "bytes" object, i.e. a string with character c where77 ord(c) > 127,78 then unicode(url) breaks.79 '''80 r = requests.get('http://www.marketwire.com/mw/release.' +81 'do?id=1628202&sourceType=3')Merge pull request #898 from rvoicilas/developKenneth Reitzbefore adoption4477d0a
line 82why, one step back82 self.assertTrue(r.ok)Merge pull request #676 from apotheos/developKenneth Reitzbefore adoption511b139
lines 83–89why, one step back8384 def test_unicode_url_outright(self):85 '''This url visits in my browser'''86 r = requests.get('http://www.marketwire.com/press-release/' +87 'jp-morgan-behauptet-sich-der-spitze-euro' +88 'p%C3%A4ischer-anleihe-analysten-laut-umf' +89 'rageergebnissen-1628202.htm')Merge pull request #898 from rvoicilas/developKenneth Reitzbefore adoption4477d0a
line 90why, one step back90 self.assertTrue(r.ok)Merge pull request #676 from apotheos/developKenneth Reitzbefore adoption511b139
lines 91–98why, one step back9192 def test_redirect_encoding(self):93 '''This url redirects to94 http://www.dealipedia.com/deal_view_investment.php?r=20012'''9596 r = requests.get('http://feedproxy.google.com/~r/Dealipedia' +97 'News/~3/BQtUJRJeZlo/deal_view_investment.' +98 'php')Merge pull request #898 from rvoicilas/developKenneth Reitzbefore adoption4477d0a
line 99why, one step back99 self.assertTrue(r.ok)Merge pull request #676 from apotheos/developKenneth Reitzbefore adoption511b139
lines 100–106why, one step back100101 def test_cookies_on_redirects(self):102 """Test interaction between cookie handling and redirection."""103 # get a cookie for tinyurl.com ONLY104 s = requests.session()105 s.get(url='http://tinyurl.com/preview.php?disable=1')106 # we should have set a cookie for tinyurl: preview=0Merge pull request #773 from randomir/developKenneth Reitzbefore adoption56b01bf
line 107why, one step back107 self.assertTrue('preview' in s.cookies)Merge pull request #676 from apotheos/developKenneth Reitzbefore adoption511b139
lines 108–114why, one step back108 self.assertEqual(s.cookies['preview'], '0')109 self.assertEqual(list(s.cookies)[0].name, 'preview')110 self.assertEqual(list(s.cookies)[0].domain, 'tinyurl.com')111112 # get cookies on another domain113 r2 = s.get(url='http://httpbin.org/cookies')114 # the cookie is not thereMerge pull request #773 from randomir/developKenneth Reitzbefore adoption56b01bf
line 115why, one step back115 self.assertTrue('preview' not in json.loads(r2.text)['cookies'])Merge pull request #676 from apotheos/developKenneth Reitzbefore adoption511b139
lines 116–119why, one step back116117 # this redirects to another domain, httpbin.org118 # cookies of the first domain should NOT be sent to the next one119 r3 = s.get(url='http://tinyurl.com/7zp3jnr')Merge pull request #898 from rvoicilas/developKenneth Reitzbefore adoption4477d0a
line 120why, one step back120 self.assertEqual(r3.url, 'http://httpbin.org/cookies')Merge pull request #793 from Lukasa/typoKenneth Reitzbefore adoption0052306
line 121why, one step back121 self.assertTrue('preview' not in json.loads(r3.text)['cookies'])Merge pull request #676 from apotheos/developKenneth Reitzbefore adoption511b139
lines 122–124why, one step back122123if __name__ == '__main__':124 unittest.main()