Exemple #1
0
 def test_ssl_checks_if_enabled(self, mock_get_cert, mock_conn):
     config_dict = {
         'http': {
             'ca_certs_file': os.path.join(self.wd, 'ca.crt'),
             'verify_server_certificates': True,
         }
     }
     with mock.patch.dict(clay.config.CONFIG.config, config_dict):
         http.request('GET', 'https://www.google.com')
         mock_get_cert.assert_called_once_with(('www.google.com', 443), ca_certs=os.path.join(self.wd, 'ca.crt'))
Exemple #2
0
 def test_ssl_certs_disabled_if_no_file(self, mock_get_cert, mock_conn):
     config_dict = {
         'http': {
             'ca_certs_file': os.path.join(self.wd, 'does_not_exist.crt'),
             'verify_server_certificates': True,
         }
     }
     with mock.patch.dict(clay.config.CONFIG.config, config_dict):
         http.request('GET', 'https://www.google.com')
         self.assertEqual(mock_get_cert.call_count, 0)
Exemple #3
0
 def test_ssl_checks_not_enabled(self, mock_get_cert, mock_conn):
     config_dict = {
         'http': {
             'ca_certs_file': os.path.join(self.wd, 'ca.crt'),
             'verify_server_certificates': False,
         }
     }
     with mock.patch.dict(clay.config.CONFIG.config, config_dict):
         http.request('GET', 'https://www.google.com')
         self.assertEqual(mock_get_cert.call_count, 0)
Exemple #4
0
 def test_ssl_checks_if_enabled(self, mock_get_cert, mock_conn):
     config_dict = {
         'http': {
             'ca_certs_file': os.path.join(self.wd, 'ca.crt'),
             'verify_server_certificates': True,
         }
     }
     with mock.patch.dict(clay.config.CONFIG.config, config_dict):
         http.request('GET', 'https://www.google.com')
         mock_get_cert.assert_called_once_with(('www.google.com', 443), ca_certs=os.path.join(self.wd, 'ca.crt'))
Exemple #5
0
 def test_good(self, mock_urlopen, mock_get_cert):
     mock_response = mock.Mock(name='resp')
     mock_response.getcode.return_value = 200
     mock_response.read.return_value = s.body
     mock_response.headers = {}
     mock_urlopen.return_value = mock_response
     response = http.request('GET', 'http://www.google.com')
     self.assertEqual(response, http.Response(status=200, headers={}, data=s.body))
Exemple #6
0
 def test_good(self, mock_urlopen, mock_get_cert):
     mock_response = mock.Mock(name='resp')
     mock_response.getcode.return_value = 200
     mock_response.read.return_value = s.body
     mock_response.headers = {}
     mock_urlopen.return_value = mock_response
     response = http.request('GET', 'http://www.google.com')
     self.assertEqual(response, http.Response(status=200, headers={}, data=s.body))
Exemple #7
0
 def test_error_returns_response(self, mock_urlopen, mock_get_cert):
     e = urllib2.HTTPError('http://www.google.com', 404, 'Some message', {}, None)
     mock_urlopen.side_effect = e
     response = http.request('GET', 'http://www.google.com')
     self.assertEqual(response, http.Response(status=404, headers={}, data=None))
Exemple #8
0
 def test_timeout_passed(self, mock_urlopen, mock_get_cert):
     http.request('GET', 'http://www.google.com', timeout=10)
     mock_urlopen.assert_called_once_with(mock.ANY, timeout=10)
Exemple #9
0
 def test_error_returns_response(self, mock_urlopen, mock_get_cert):
     e = urllib2.HTTPError('http://www.google.com', 404, 'Some message', {}, None)
     mock_urlopen.side_effect = e
     response = http.request('GET', 'http://www.google.com')
     self.assertEqual(response, http.Response(status=404, headers={}, data=None))