def test_http_call_failed(self, mock_conn): client = PrestoClient('any_host', 'any_user', 8080) mock_conn.side_effect = HTTPException('Error') self.assertFalse(client.execute_query('any_sql')) mock_conn.side_effect = socket.error('Error') self.assertFalse(client.execute_query('any_sql'))
def test_default_request_called(self, mock_conn): client = PrestoClient('any_host', 'any_user', 8080) headers = {'X-Presto-Catalog': 'tpch', 'X-Presto-Schema': 'sf1', 'X-Presto-User': '******'} client.execute_query('any_sql') mock_conn.assert_called_with('any_host', 8080, False, URL_TIMEOUT_MS) mock_conn().request.assert_called_with('POST', '/v1/statement', 'any_sql', headers) self.assertTrue(mock_conn().getresponse.called)
def test_default_request_called(self, mock_conn): client = PrestoClient('any_host', 'any_user', 8080) headers = { 'X-Presto-Catalog': 'tpch', 'X-Presto-Schema': 'sf1', 'X-Presto-User': '******' } client.execute_query('any_sql') mock_conn.assert_called_with('any_host', 8080, False, URL_TIMEOUT_MS) mock_conn().request.assert_called_with('POST', '/v1/statement', 'any_sql', headers) self.assertTrue(mock_conn().getresponse.called)
def test_http_answer_valid(self, mock_response, mock_request): client = PrestoClient('any_host', 'any_user', 8080) mock_response.return_value.read.return_value = '{}' type(mock_response.return_value).status = \ PropertyMock(return_value=200) self.assertTrue(client.execute_query('any_sql'))
def test_connection_failed(self, mock_conn): client = PrestoClient('any_host', 'any_user', 8080) client.execute_query('any_sql') self.assertTrue(mock_conn().close.called) self.assertFalse(client.execute_query('any_sql'))