Ejemplo n.º 1
0
    def test_uses_https_if_verify_certs_is_off(self):
        with warnings.catch_warnings(record=True) as w:
            con = Urllib3HttpConnection(use_ssl=True, verify_certs=False)
            self.assertEquals(1, len(w))
            self.assertEquals('Connecting to localhost using SSL with verify_certs=False is insecure.', str(w[0].message))

        self.assertIsInstance(con.pool, urllib3.HTTPSConnectionPool)
Ejemplo n.º 2
0
 def test_http_auth(self):
     con = Urllib3HttpConnection(http_auth='username:secret')
     self.assertEquals({
         'authorization': 'Basic dXNlcm5hbWU6c2VjcmV0',
         'connection': 'keep-alive',
         'content-type': 'application/json'
     }, con.headers)
Ejemplo n.º 3
0
    def test_ssl_context(self):
        try:
            context = ssl.create_default_context()
        except AttributeError:
            # if create_default_context raises an AttributeError Exception
            # it means SSLContext is not available for that version of python
            # and we should skip this test.
            raise SkipTest(
                "Test test_ssl_context is skipped cause SSLContext is not available for this version of ptyhon")

        con = Urllib3HttpConnection(use_ssl=True, ssl_context=context)
        self.assertEqual(len(con.pool.conn_kw.keys()), 1)
        self.assertIsInstance(
            con.pool.conn_kw['ssl_context'],
            ssl.SSLContext
        )
        self.assertTrue(con.use_ssl)
Ejemplo n.º 4
0
 def test_doesnt_use_https_if_not_specified(self):
     con = Urllib3HttpConnection()
     self.assertIsInstance(con.pool, urllib3.HTTPConnectionPool)
Ejemplo n.º 5
0
 def test_keep_alive_is_on_by_default(self):
     con = Urllib3HttpConnection()
     self.assertEquals({'connection': 'keep-alive',
         'content-type': 'application/json'}, con.headers)
Ejemplo n.º 6
0
 def test_timeout_set(self):
     con = Urllib3HttpConnection(timeout=42)
     self.assertEquals(42, con.timeout)
Ejemplo n.º 7
0
 def test_http_compression(self):
     con = Urllib3HttpConnection(http_compress=True)
     self.assertTrue(con.http_compress)
     self.assertEquals(con.headers['content-encoding'], 'gzip')