本文整理汇总了Python中prestoadmin.prestoclient.PrestoClient类的典型用法代码示例。如果您正苦于以下问题:Python PrestoClient类的具体用法?Python PrestoClient怎么用?Python PrestoClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PrestoClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_http_call_failed
def test_http_call_failed(self, mock_conn, mock_presto_config):
client = PrestoClient('any_host', 'any_user')
mock_conn.side_effect = HTTPException("Error")
self.assertFalse(client.run_sql("any_sql"))
mock_conn.side_effect = socket.error("Error")
self.assertFalse(client.run_sql("any_sql"))
示例2: test_http_call_failed
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"))
示例3: test_retrieve_rows
def test_retrieve_rows(self, mock_uri, mock_get_from_uri, mock_port):
mock_port.return_value = 8080
client = PrestoClient('any_host', 'any_user')
dir = os.path.abspath(os.path.dirname(__file__))
with open(dir + '/resources/valid_rest_response_level1.txt') \
as json_file:
client.response_from_server = json.load(json_file)
mock_get_from_uri.return_value = True
mock_uri.side_effect = [
"http://localhost:8080/v1/statement/2015_harih/2", ""
]
self.assertEqual(client.get_rows(), [])
self.assertEqual(client.next_uri,
"http://localhost:8080/v1/statement/2015_harih/2")
with open(dir + '/resources/valid_rest_response_level2.txt') \
as json_file:
client.response_from_server = json.load(json_file)
mock_uri.side_effect = [
"http://localhost:8080/v1/statement/2015_harih/2", ""
]
expected_row = [["uuid1", "http://localhost:8080", "presto-main:0.97",
True],
["uuid2", "http://worker:8080", "presto-main:0.97",
False]]
self.assertEqual(client.get_rows(), expected_row)
self.assertEqual(client.next_uri, "")
示例4: test_get_response
def test_get_response(self, mock_resp, mock_urlopen):
client = PrestoClient('any_host', 'any_user')
mock_urlopen.return_value = mock_resp
mock_resp.read.return_value = '{"message": "ok!"}'
client.get_response_from('any_uri')
self.assertEqual(client.response_from_server, {"message": "ok!"})
示例5: test_connection_failed
def test_connection_failed(self, mock_conn, mock_port):
mock_port.return_value = 8080
client = PrestoClient('any_host', 'any_user')
client.execute_query("any_sql")
self.assertTrue(mock_conn().close.called)
self.assertFalse(client.execute_query("any_sql"))
示例6: test_http_answer_valid
def test_http_answer_valid(self, mock_response, mock_request, mock_port):
mock_port.return_value = 8080
client = PrestoClient('any_host', 'any_user')
mock_response.return_value.read.return_value = '{}'
type(mock_response.return_value).status = \
PropertyMock(return_value=200)
self.assertTrue(client.execute_query('any_sql'))
示例7: test_limit_rows
def test_limit_rows(self, mock_uri, mock_get_from_uri):
client = PrestoClient('any_host', 'any_user', 8080)
dir = os.path.abspath(os.path.dirname(__file__))
with open(dir + '/files/valid_rest_response_level2.txt') as json_file:
client.response_from_server = json.load(json_file)
mock_get_from_uri.return_value = True
mock_uri.side_effect = ["any_next_uri", ""]
self.assertEqual(client.get_rows(0), [])
示例8: test_default_request_called
def test_default_request_called(self, mock_conn, mock_presto_config):
client = PrestoClient('any_host', 'any_user')
headers = {"X-Presto-Catalog": "hive", "X-Presto-Schema": "default",
"X-Presto-User": 'any_user', "X-Presto-Source": "presto-admin"}
client.run_sql("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)
示例9: test_default_request_called
def test_default_request_called(self, mock_conn):
client = PrestoClient('any_host', 'any_user', 8080)
headers = {"X-Presto-Catalog": "hive", "X-Presto-Schema": "default",
"X-Presto-User": 'any_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)
示例10: test_append_rows
def test_append_rows(self, mock_uri, mock_get_from_uri):
client = PrestoClient('any_host', 'any_user', 8080)
dir = os.path.abspath(os.path.dirname(__file__))
with open(dir + '/files/valid_rest_response_level2.txt') as json_file:
client.response_from_server = json.load(json_file)
mock_get_from_uri.return_value = True
mock_uri.side_effect = ["any_next_uri", "any_next_next_uri", "", ""]
expected_row = [["uuid1", "http://localhost:8080", "presto-main:0.97",
True],
["uuid2", "http://worker:8080", "presto-main:0.97",
False],
["uuid1", "http://localhost:8080", "presto-main:0.97",
True],
["uuid2", "http://worker:8080", "presto-main:0.97",
False]]
self.assertEqual(client.get_rows(), expected_row)
示例11: test_execute_query_get_port
def test_execute_query_get_port(self, run_mock, conn_mock):
client = PrestoClient('any_host', 'any_user')
client.rows = ['hello']
client.next_uri = 'hello'
client.response_from_server = {'hello': 'hello'}
run_mock.return_value = _AttributeString('http-server.http.port=8080')
run_mock.return_value.failed = False
client.execute_query('select * from nation')
self.assertEqual(client.port, 8080)
self.assertEqual(client.rows, [])
self.assertEqual(client.next_uri, '')
self.assertEqual(client.response_from_server, {})
示例12: testrun_sql_get_port
def testrun_sql_get_port(self, sudo_mock, conn_mock, mock_presto_config):
client = PrestoClient('any_host', 'any_user')
client.rows = ['hello']
client.next_uri = 'hello'
client.response_from_server = {'hello': 'hello'}
sudo_mock.return_value = _AttributeString('http-server.http.port=8080')
sudo_mock.return_value.failed = False
sudo_mock.return_value.return_code = 0
client.run_sql('select * from nation')
self.assertEqual(client.port, 8080)
self.assertEqual(client.rows, [])
self.assertEqual(client.next_uri, '')
self.assertEqual(client.response_from_server, {})
示例13: test_create_authorization_headers_fails_with_colon_in_user
def test_create_authorization_headers_fails_with_colon_in_user(self, mock_error, mock_presto_config):
PrestoClient._create_auth_headers("Aladdin:1", "open sesame")
error_message = "LDAP user cannot contain ':': Aladdin:1"
mock_error.assert_called_once_with(error_message)
示例14: test_connection_failed
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"))
示例15: test_create_authorization_headers
def test_create_authorization_headers(self, mock_presto_config):
auth_headers = PrestoClient._create_auth_headers("Aladdin", "open sesame")
expected_auth_headers = {"Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="}
self.assertEqual(auth_headers, expected_auth_headers)