예제 #1
0
 def testDoHttpsRequestResponseWithHttpsProxy(self):
     """Test a https request via a http proxy."""
     # default is https
     test_client = client.HttpsClient(self.hostname,
                                      proxy='https://proxyhost:126')
     req_url = 'https://' + self.hostname + '/url'
     self._TestDoRequestResponse(test_client, '/url', req_url)
예제 #2
0
    def testDoWithProxy(self):
        """Test Do() with a proxy specified."""
        method = 'GET'
        url = 'url'
        proxy = 'proxyhost:123'

        # Working case.
        mock_response = mock.create_autospec(httplib.HTTPConnection)
        mock_response.status = 200
        test_client = client.HttpsClient(self.hostname, proxy=proxy)

        with mock.patch.object(
                test_client, '_DoRequestResponse',
                return_value=mock_response) as mock_do_request_response:
            test_client.Do(method, url)
            mock_do_request_response.assert_called_once_with(method,
                                                             url,
                                                             body=None,
                                                             headers={},
                                                             output_file=None)

        # No port case.
        proxy = 'proxyhost'
        self.assertRaises(client.Error,
                          client.HttpsClient,
                          self.hostname,
                          proxy=proxy)
        # Bad port case.
        proxy = 'proxyhost:alpha'
        self.assertRaises(client.Error,
                          client.HttpsClient,
                          self.hostname,
                          proxy=proxy)
예제 #3
0
    def testInit(self, mock_lh):
        """Test __init__()."""
        i = client.HttpsClient(self.hostname)
        self.assertEqual(i._progress_callback, None)
        self.assertEqual(i._ca_cert_chain, None)

        mock_lh.assert_called_once_with(self.hostname, None, None)
예제 #4
0
  def testDoWithProxy(self):
    """Test Do() with a proxy specified."""
    method = 'GET'
    url = 'url'
    proxy = 'proxyhost:123'

    # Working case.
    mock_response = self.mox.CreateMockAnything()
    mock_response.status = 200
    test_client = client.HttpsClient(self.hostname, proxy=proxy)
    self.mox.StubOutWithMock(test_client, '_DoRequestResponse')
    test_client._DoRequestResponse(
        method, url, body=None, headers={}, output_file=None).AndReturn(
            mock_response)
    self.mox.ReplayAll()
    test_client.Do(method, url)
    self.mox.VerifyAll()
    # No port case.
    proxy = 'proxyhost'
    self.assertRaises(
        client.Error,
        client.HttpsClient, self.hostname, proxy=proxy)
    # Bad port case.
    proxy = 'proxyhost:alpha'
    self.assertRaises(
        client.Error,
        client.HttpsClient, self.hostname, proxy=proxy)
예제 #5
0
 def testInit(self):
   """Test __init__()."""
   mock_lh = self.mox.CreateMockAnything()
   self.mox.StubOutWithMock(self.client, '_LoadHost')
   self.stubs.Set(client.HttpsClient, '_LoadHost', mock_lh)
   mock_lh(self.hostname, None, None).AndReturn(None)
   self.mox.ReplayAll()
   i = client.HttpsClient(self.hostname)
   self.assertEqual(i._progress_callback, None)
   self.assertEqual(i._ca_cert_chain, None)
   self.mox.VerifyAll()
예제 #6
0
 def testDoHttpRequestResponseWithHttpProxy(self):
     """Test a https request via a http proxy."""
     test_client = client.HttpsClient('http://%s' % self.hostname,
                                      proxy='proxyhost:123')
     req_url = 'http://' + self.hostname + '/url'
     self._TestDoRequestResponse(test_client, '/url', req_url)
예제 #7
0
 def testConnectWithProxy(self):
     test_client = client.HttpsClient(self.hostname, proxy='proxyhost:123')
     self._TestConnect(test_client, 'proxyhost', 123)
예제 #8
0
 def setUp(self):
     super(HttpsClientTest, self).setUp()
     self.stubs = stubout.StubOutForTesting()
     self.hostname = 'hostname'
     self.port = None
     self.client = client.HttpsClient(self.hostname)
예제 #9
0
 def setUp(self):
   mox.MoxTestBase.setUp(self)
   self.stubs = stubout.StubOutForTesting()
   self.hostname = 'hostname'
   self.port = None
   self.client = client.HttpsClient(self.hostname)