def test_create_connection_http(self, http_conn): conn = mock.Mock() http_conn.return_value = conn handle = rw_handles.FileHandle(None) ret = handle._create_connection('http://localhost/foo?q=bar', 'GET') self.assertEqual(conn, ret) conn.putrequest.assert_called_once_with('GET', '/foo?q=bar')
def test_create_connection_https(self, https_conn): conn = mock.Mock() https_conn.return_value = conn handle = rw_handles.FileHandle(None) ret = handle._create_connection('https://localhost/foo?q=bar', 'GET') self.assertEqual(conn, ret) conn.set_cert.assert_called_once_with(ca_certs=None, cert_reqs=ssl.CERT_NONE, assert_fingerprint=None) conn.putrequest.assert_called_once_with('GET', '/foo?q=bar')
def test_create_connection_https_with_cacerts(self, https_conn): conn = mock.Mock() https_conn.return_value = conn handle = rw_handles.FileHandle(None) ret = handle._create_connection('https://localhost/foo?q=bar', 'GET', cacerts=True) self.assertEqual(conn, ret) ca_store = requests.certs.where() conn.set_cert.assert_called_once_with(ca_certs=ca_store, cert_reqs=ssl.CERT_REQUIRED, assert_fingerprint=None)
def test_find_vmdk_url(self): device_url_0 = mock.Mock() device_url_0.disk = False device_url_1 = mock.Mock() device_url_1.disk = True device_url_1.url = 'https://*/ds1/vm1.vmdk' lease_info = mock.Mock() lease_info.deviceUrl = [device_url_0, device_url_1] host = '10.1.2.3' port = 443 exp_url = 'https://%s:%d/ds1/vm1.vmdk' % (host, port) vmw_http_file = rw_handles.FileHandle(None) self.assertEqual(exp_url, vmw_http_file._find_vmdk_url(lease_info, host, port))
def test_create_connection_https_with_ssl_thumbprint(self, https_conn): conn = mock.Mock() https_conn.return_value = conn handle = rw_handles.FileHandle(None) cacerts = mock.sentinel.cacerts thumbprint = mock.sentinel.thumbprint ret = handle._create_connection('https://localhost/foo?q=bar', 'GET', cacerts=cacerts, ssl_thumbprint=thumbprint) self.assertEqual(conn, ret) conn.set_cert.assert_called_once_with(ca_certs=cacerts, cert_reqs=None, assert_fingerprint=thumbprint)
def test_close(self): file_handle = mock.Mock() vmw_http_file = rw_handles.FileHandle(file_handle) vmw_http_file.close() file_handle.close.assert_called_once_with()