def connect(*args, **kwargs): """Returns a DBAPI compatible connection object Params: type (str): query engine type. "hive" by default. db (str): the name of database on Treasure Data result_url (str): result output URL priority (str): job priority retry_limit (int): job retry limit wait_interval (int): job wait interval to check status wait_callback (callable): a callback to be called on every ticks of job wait Returns: `tdclient.connection.Connection` """ return connection.Connection(*args, **kwargs)
def test_connection_with_cursor_options(): td = connection.Connection(apikey="APIKEY", endpoint="http://api.example.com/", type="presto", db="sample_datasets", result_url="mysql://db.example.com", priority="HIGH", retry_limit=3, wait_interval=5, wait_callback=repr) with mock.patch("tdclient.connection.cursor.Cursor") as Cursor: td.cursor() assert Cursor.called args, kwargs = Cursor.call_args assert kwargs.get("type") == "presto" assert kwargs.get("db") == "sample_datasets" assert kwargs.get("result_url") == "mysql://db.example.com" assert kwargs.get("priority") == "HIGH" assert kwargs.get("retry_limit") == 3 assert kwargs.get("wait_interval") == 5 assert kwargs.get("wait_callback") == repr
def test_connection_rollback(): td = connection.Connection(apikey="APIKEY") with pytest.raises(errors.NotSupportedError) as error: td.rollback()
def test_connection_close(): td = connection.Connection(apikey="APIKEY") td._api = mock.MagicMock() td.close() assert td._api.close.called
def test_connection_with_options(): td = connection.Connection(apikey="APIKEY", endpoint="http://api.example.com/") assert td.api.apikey == "APIKEY" assert td.api._endpoint == "http://api.example.com/"
def test_connection(): td = connection.Connection(apikey="foo") assert td.api.apikey == "foo"