aboutsummaryrefslogtreecommitdiff
path: root/test/appengine/test_urlfetch.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/appengine/test_urlfetch.py')
-rw-r--r--test/appengine/test_urlfetch.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/appengine/test_urlfetch.py b/test/appengine/test_urlfetch.py
new file mode 100644
index 0000000..3f72023
--- /dev/null
+++ b/test/appengine/test_urlfetch.py
@@ -0,0 +1,49 @@
+from . import AppEngineSandboxTest, MockResponse
+
+from mock import patch
+from nose.plugins.skip import SkipTest
+from ..test_no_ssl import TestWithoutSSL
+
+
+class TestHTTP(AppEngineSandboxTest, TestWithoutSSL):
+ nosegae_urlfetch = True
+
+ def test_urlfetch_called_with_http(self):
+ """
+ Check that URLFetch is used to fetch non-https resources
+ """
+ resp = MockResponse(
+ 'OK',
+ 200,
+ False,
+ 'http://www.google.com',
+ {'content-type': 'text/plain'})
+ with patch('google.appengine.api.urlfetch.fetch', return_value=resp) as fetchmock:
+ import urllib3
+ pool = urllib3.HTTPConnectionPool('www.google.com', '80')
+ r = pool.request('GET', '/')
+ self.assertEqual(r.status, 200, r.data)
+ self.assertEqual(fetchmock.call_count, 1)
+
+
+class TestHTTPS(AppEngineSandboxTest):
+ nosegae_urlfetch = True
+
+ def test_urlfetch_called_with_https(self):
+ """
+ Check that URLFetch is used when fetching https resources
+ """
+ raise SkipTest() # Skipped for now because it fails.
+ resp = MockResponse(
+ 'OK',
+ 200,
+ False,
+ 'https://www.google.com',
+ {'content-type': 'text/plain'})
+ with patch('google.appengine.api.urlfetch.fetch', return_value=resp) as fetchmock:
+ import urllib3
+ pool = urllib3.HTTPSConnectionPool('www.google.com', '443')
+ pool.ConnectionCls = urllib3.connection.UnverifiedHTTPSConnection
+ r = pool.request('GET', '/')
+ self.assertEqual(r.status, 200, r.data)
+ self.assertEqual(fetchmock.call_count, 1)