Skip to content

Commit 80e4f44

Browse files
committed
test_upstream: Create
Tests purely of requests HTTPAdapter, which can be used to prepare offline tests, and base all other tests on to show where other adapters differ from pure requests. Related to #14 Related to #25
1 parent 94fea04 commit 80e4f44

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

tests/test_upstream.py

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
from __future__ import unicode_literals
2+
3+
import unittest
4+
5+
import requests
6+
7+
8+
class TestUpstreamAdapter(unittest.TestCase):
9+
10+
cls = requests.adapters.HTTPAdapter
11+
12+
def test_freerangekitten_com(self):
13+
url = "http://freerangekitten.com/"
14+
s = requests.Session()
15+
s.mount("http://", self.cls())
16+
r = s.get(url)
17+
r.raise_for_status()
18+
self.assertEqual(r.url, url)
19+
self.assertEqual(r.history, [])
20+
21+
def test_example_com(self):
22+
url = "http://example.com/"
23+
s = requests.Session()
24+
s.mount("http://", self.cls())
25+
r = s.get(url)
26+
r.raise_for_status()
27+
self.assertEqual(r.url, url)
28+
self.assertEqual(r.history, [])
29+
30+
def test_webhostinggeeks_com_science(self):
31+
# https://github.com/EFForg/https-everywhere/issues/18867
32+
# https has wrong cert for a quick failure
33+
url = "http://science.webhostinggeeks.com/"
34+
s = requests.Session()
35+
s.mount("http://", self.cls())
36+
r = s.get(url)
37+
r.raise_for_status()
38+
self.assertEqual(r.url, url)
39+
self.assertEqual(r.history, [])
40+
41+
def test_fedmsg_com(self):
42+
# https://github.com/EFForg/https-everywhere/issues/18867
43+
# https redirects to http, so a manual exclusion is needed
44+
url = "http://fedmsg.com/"
45+
s = requests.Session()
46+
s.mount("http://", self.cls())
47+
r = s.get(url)
48+
r.raise_for_status()
49+
self.assertEqual(r.url, url)
50+
self.assertEqual(r.history, [])
51+
52+
def test_shopzilla(self):
53+
url = "http://www.shopzilla.com/"
54+
s = requests.Session()
55+
s.mount("http://", self.cls())
56+
r = s.get(url)
57+
r.raise_for_status()
58+
self.assertEqual(r.url, url)
59+
self.assertEqual(r.history, [])
60+
61+
def test_whisper_sh(self):
62+
url = "http://whisper.sh/"
63+
s = requests.Session()
64+
s.mount("http://", self.cls())
65+
r = s.get(url)
66+
r.raise_for_status()
67+
self.assertEqual(r.url, url)
68+
self.assertEqual(r.history, [])
69+
70+
def test_thesyriacampaign(self):
71+
url = "http://www.thesyriacampaign.org/"
72+
s = requests.Session()
73+
s.mount("http://", self.cls())
74+
r = s.get(url)
75+
self.assertEqual(r.status_code, 403)
76+
77+
def test_esncz_org(self):
78+
url = "http://www.isc.vutbr.cz/"
79+
s = requests.Session()
80+
s.mount("http://", self.cls())
81+
r = s.get(url)
82+
r.raise_for_status()
83+
self.assertEqual(r.url, "https://www.esncz.org")
84+
target = "https://www.esncz.org"
85+
self.assertEqual(r.url, target)
86+
self.assertEqual(len(r.history), 1)
87+
original = r.history[0]
88+
self.assertEqual(original.url, url)
89+
self.assertEqual(original.status_code, 302)
90+
self.assertEqual(original.reason, "Found")
91+
92+
def test_01_org(self):
93+
url = "http://01.org/"
94+
s = requests.Session()
95+
s.mount("http://", self.cls())
96+
r = s.get(url)
97+
r.raise_for_status()
98+
self.assertEqual(r.url, url.replace("http://", "https://"))
99+
self.assertEqual(len(r.history), 1)
100+
original = r.history[0]
101+
self.assertEqual(original.url, url)
102+
self.assertEqual(original.status_code, 301)
103+
self.assertEqual(original.reason, "Moved Permanently")
104+
105+
def test_01_org_www(self):
106+
url = "http://www.01.org/"
107+
s = requests.Session()
108+
s.mount("http://", self.cls())
109+
r = s.get(url)
110+
r.raise_for_status()
111+
self.assertEqual(r.url, "https://01.org/")
112+
self.assertEqual(len(r.history), 1)
113+
original = r.history[0]
114+
self.assertEqual(original.url, url)
115+
self.assertEqual(original.status_code, 301)
116+
self.assertEqual(original.reason, "Moved Permanently")
117+
118+
def test_medbank_mt(self):
119+
url = "http://business.medbank.com.mt/"
120+
s = requests.Session()
121+
s.mount("http://", self.cls())
122+
r = s.get(url)
123+
r.raise_for_status()
124+
self.assertEqual(r.url, "https://www.medirect.com.mt")
125+
self.assertEqual(len(r.history), 1)
126+
original = r.history[0]
127+
self.assertEqual(original.url, url)
128+
self.assertEqual(original.status_code, 301)
129+
self.assertEqual(original.reason, "Moved Permanently")
130+
131+
def test_my_vpnglobe(self):
132+
url = "http://my.vpnglobe.com/"
133+
s = requests.Session()
134+
s.mount("http://", self.cls())
135+
with self.assertRaises(requests.exceptions.SSLError):
136+
s.get(url)
137+
138+
def _test_modwsgi_org(self):
139+
# https://github.com/EFForg/https-everywhere/issues/18867
140+
# http has a redirect to readthedocs; https fails
141+
url = "http://www.modwsgi.org/"
142+
s = requests.Session()
143+
s.mount("http://", self.cls())
144+
with self.assertRaises(requests.exceptions.Timeout):
145+
s.get(url, timeout=5)
146+
147+
def test_python_org_packages(self):
148+
url = "http://packages.python.org/"
149+
s = requests.Session()
150+
s.mount("http://", self.cls())
151+
r = s.get(url)
152+
r.raise_for_status()
153+
self.assertEqual(r.url, "https://pythonhosted.org/")
154+
self.assertEqual(len(r.history), 2)
155+
original = r.history[0]
156+
self.assertEqual(original.url, url)
157+
self.assertEqual(original.status_code, 301)
158+
self.assertEqual(original.reason, "Moved Permanently")
159+
self.assertEqual(r.history[1].url, url.replace("http://", "https://"))
160+
self.assertEqual(r.history[1].status_code, 301)
161+
self.assertEqual(r.history[1].reason, "Moved Permanently")
162+
163+
def test_ros_wiki(self):
164+
# https://github.com/jayvdb/pypidb/issues/115
165+
# Short-lived problem
166+
url = "http://wiki.ros.org/"
167+
s = requests.Session()
168+
s.mount("http://", self.cls())
169+
r = s.get(url)
170+
r.raise_for_status()
171+
self.assertEqual(r.url, url)
172+
self.assertEqual(r.history, [])

0 commit comments

Comments
 (0)