def test_invalid_kwargs(self): """some kwargs are reserved""" self.assertRaisesRegexp( ValueError, 'Cannot override', lambda: presto.connect( host=_HOST, username='******', requests_kwargs={ 'url': 'test' }).cursor())
def test_set_session_in_constructor(self): conn = presto.connect(host=_HOST, source=self.id(), session_props={'query_max_run_time': '1234m'}) with contextlib.closing(conn): with contextlib.closing(conn.cursor()) as cursor: cursor.execute('SHOW SESSION') rows = [ r for r in cursor.fetchall() if r[0] == 'query_max_run_time' ] assert len(rows) == 1 session_prop = rows[0] assert session_prop[1] == '1234m' cursor.execute('RESET SESSION query_max_run_time') cursor.fetchall() cursor.execute('SHOW SESSION') rows = [ r for r in cursor.fetchall() if r[0] == 'query_max_run_time' ] assert len(rows) == 1 session_prop = rows[0] assert session_prop[1] != '1234m'
def test_invalid_protocol_config(self): """protocol should be https when passing password""" self.assertRaisesRegexp( ValueError, 'Protocol.*https.*password', lambda: presto.connect(host=_HOST, username='******', password='******', protocol='http').cursor())
def test_requests_session(self): with requests.Session() as session: connection = presto.connect(host=_HOST, port=_PORT, source=self.id(), requests_session=session) cursor = connection.cursor() cursor.execute('SELECT * FROM one_row') self.assertEqual(cursor.fetchall(), [(1, )])
def test_invalid_password_and_kwargs(self): """password and requests_kwargs are incompatible""" self.assertRaisesRegexp( ValueError, 'Cannot use both', lambda: presto.connect(host=_HOST, username='******', password='******', protocol='https', requests_kwargs={}).cursor())
def test_requests_kwargs(self): connection = presto.connect( host=_HOST, port=_PORT, source=self.id(), requests_kwargs={'proxies': { 'http': 'localhost:99999' }}, ) cursor = connection.cursor() self.assertRaises(requests.exceptions.ProxyError, lambda: cursor.execute('SELECT * FROM one_row'))
def test_bad_protocol(self): self.assertRaisesRegexp( ValueError, 'Protocol must be', lambda: presto.connect('localhost', protocol='nonsense').cursor())
def connect(self): return presto.connect(host=_HOST, port=_PORT, source=self.id())