aboutsummaryrefslogtreecommitdiff
path: root/test/appengine/test_urlfetch.py
blob: 3f720238c01e44869d9bd399672afedb3957033b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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)