|
@@ -47,6 +47,7 @@ class TestApi(object):
|
|
|
|
|
|
|
|
self.user = rewrite_user(User.objects.get(username="test"))
|
|
self.user = rewrite_user(User.objects.get(username="test"))
|
|
|
self.interpreter = {
|
|
self.interpreter = {
|
|
|
|
|
+ 'name': 'hive',
|
|
|
'options': {
|
|
'options': {
|
|
|
'url': 'mysql://hue:localhost@hue:3306/hue'
|
|
'url': 'mysql://hue:localhost@hue:3306/hue'
|
|
|
},
|
|
},
|
|
@@ -55,6 +56,7 @@ class TestApi(object):
|
|
|
|
|
|
|
|
def test_column_backticks_escaping(self):
|
|
def test_column_backticks_escaping(self):
|
|
|
interpreter = {
|
|
interpreter = {
|
|
|
|
|
+ 'name': 'hive',
|
|
|
'options': {
|
|
'options': {
|
|
|
'url': 'mysql://'
|
|
'url': 'mysql://'
|
|
|
}
|
|
}
|
|
@@ -62,14 +64,17 @@ class TestApi(object):
|
|
|
assert_equal(SqlAlchemyApi(self.user, interpreter).backticks, '`')
|
|
assert_equal(SqlAlchemyApi(self.user, interpreter).backticks, '`')
|
|
|
|
|
|
|
|
interpreter = {
|
|
interpreter = {
|
|
|
|
|
+ 'name': 'hive',
|
|
|
'options': {
|
|
'options': {
|
|
|
'url': 'postgresql://'
|
|
'url': 'postgresql://'
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
assert_equal(SqlAlchemyApi(self.user, interpreter).backticks, '"')
|
|
assert_equal(SqlAlchemyApi(self.user, interpreter).backticks, '"')
|
|
|
|
|
|
|
|
|
|
+
|
|
|
def test_create_athena_engine(self):
|
|
def test_create_athena_engine(self):
|
|
|
interpreter = {
|
|
interpreter = {
|
|
|
|
|
+ 'name': 'hive',
|
|
|
'options': {
|
|
'options': {
|
|
|
'url': 'awsathena+rest://XXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXX@athena.us-west-2.amazonaws.com:443/default?s3_staging_dir=s3://gethue-athena/scratch'
|
|
'url': 'awsathena+rest://XXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXX@athena.us-west-2.amazonaws.com:443/default?s3_staging_dir=s3://gethue-athena/scratch'
|
|
|
}
|
|
}
|
|
@@ -85,8 +90,8 @@ class TestApi(object):
|
|
|
rows = 10
|
|
rows = 10
|
|
|
start_over = True
|
|
start_over = True
|
|
|
|
|
|
|
|
- with patch('notebook.connectors.sql_alchemy.CONNECTION_CACHE') as CONNECTION_CACHE:
|
|
|
|
|
- CONNECTION_CACHE.get = Mock(
|
|
|
|
|
|
|
+ with patch('notebook.connectors.sql_alchemy.CONNECTIONS') as CONNECTIONS:
|
|
|
|
|
+ CONNECTIONS.get = Mock(
|
|
|
return_value={
|
|
return_value={
|
|
|
'result': Mock(
|
|
'result': Mock(
|
|
|
fetchmany=Mock(return_value=[]) # We have 0 rows
|
|
fetchmany=Mock(return_value=[]) # We have 0 rows
|
|
@@ -114,8 +119,8 @@ class TestApi(object):
|
|
|
rows = 10
|
|
rows = 10
|
|
|
start_over = True
|
|
start_over = True
|
|
|
|
|
|
|
|
- with patch('notebook.connectors.sql_alchemy.CONNECTION_CACHE') as CONNECTION_CACHE:
|
|
|
|
|
- CONNECTION_CACHE.get = Mock(
|
|
|
|
|
|
|
+ with patch('notebook.connectors.sql_alchemy.CONNECTIONS') as CONNECTIONS:
|
|
|
|
|
+ CONNECTIONS.get = Mock(
|
|
|
return_value={
|
|
return_value={
|
|
|
'result': Mock(
|
|
'result': Mock(
|
|
|
fetchmany=Mock(return_value=[['row1'], ['row2']]) # We have 2 rows
|
|
fetchmany=Mock(return_value=[['row1'], ['row2']]) # We have 2 rows
|
|
@@ -136,12 +141,14 @@ class TestApi(object):
|
|
|
assert_equal(data['data'], [['row1'], ['row2']])
|
|
assert_equal(data['data'], [['row1'], ['row2']])
|
|
|
assert_equal(data['meta'](), [{'type': 'BIGINT_TYPE'}])
|
|
assert_equal(data['meta'](), [{'type': 'BIGINT_TYPE'}])
|
|
|
|
|
|
|
|
|
|
+
|
|
|
@raises(AuthenticationRequired)
|
|
@raises(AuthenticationRequired)
|
|
|
def test_create_engine_auth_error(self):
|
|
def test_create_engine_auth_error(self):
|
|
|
interpreter = {
|
|
interpreter = {
|
|
|
- 'options': {
|
|
|
|
|
- 'url': 'mysql://${USER}:${PASSWORD}@hue:3306/hue'
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ 'name': 'hive',
|
|
|
|
|
+ 'options': {
|
|
|
|
|
+ 'url': 'mysql://${USER}:${PASSWORD}@hue:3306/hue'
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
with patch('notebook.connectors.sql_alchemy.create_engine') as create_engine:
|
|
with patch('notebook.connectors.sql_alchemy.create_engine') as create_engine:
|
|
@@ -150,6 +157,7 @@ class TestApi(object):
|
|
|
|
|
|
|
|
def test_create_engine_auth(self):
|
|
def test_create_engine_auth(self):
|
|
|
interpreter = {
|
|
interpreter = {
|
|
|
|
|
+ 'name': 'hive',
|
|
|
'options': {
|
|
'options': {
|
|
|
'url': 'mysql://${USER}:${PASSWORD}@hue:3306/hue',
|
|
'url': 'mysql://${USER}:${PASSWORD}@hue:3306/hue',
|
|
|
'session': {
|
|
'session': {
|
|
@@ -174,7 +182,7 @@ class TestApi(object):
|
|
|
def test_check_status(self):
|
|
def test_check_status(self):
|
|
|
notebook = Mock()
|
|
notebook = Mock()
|
|
|
|
|
|
|
|
- with patch('notebook.connectors.sql_alchemy.CONNECTION_CACHE') as CONNECTION_CACHE:
|
|
|
|
|
|
|
+ with patch('notebook.connectors.sql_alchemy.CONNECTIONS') as CONNECTIONS:
|
|
|
|
|
|
|
|
snippet = {'result': {'handle': {'guid': 'guid-1', 'has_result_set': False}}}
|
|
snippet = {'result': {'handle': {'guid': 'guid-1', 'has_result_set': False}}}
|
|
|
response = SqlAlchemyApi(self.user, self.interpreter).check_status(notebook, snippet)
|
|
response = SqlAlchemyApi(self.user, self.interpreter).check_status(notebook, snippet)
|
|
@@ -222,7 +230,7 @@ class TestDialects(object):
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_backticks_with_connectors(self):
|
|
def test_backticks_with_connectors(self):
|
|
|
- interpreter = {'options': {'url': 'dialect://'}, 'dialect_properties': {'sql_identifier_quote': '`'}}
|
|
|
|
|
|
|
+ interpreter = {'name': 'hive', 'options': {'url': 'dialect://'}, 'dialect_properties': {'sql_identifier_quote': '`'}}
|
|
|
data = SqlAlchemyApi(self.user, interpreter).get_browse_query(snippet=Mock(), database='db1', table='table1')
|
|
data = SqlAlchemyApi(self.user, interpreter).get_browse_query(snippet=Mock(), database='db1', table='table1')
|
|
|
|
|
|
|
|
assert_equal(data, 'SELECT *\nFROM `db1`.`table1`\nLIMIT 1000\n')
|
|
assert_equal(data, 'SELECT *\nFROM `db1`.`table1`\nLIMIT 1000\n')
|
|
@@ -235,13 +243,13 @@ class TestDialects(object):
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_backticks_without_connectors(self):
|
|
def test_backticks_without_connectors(self):
|
|
|
- interpreter = {'options': {'url': 'phoenix://'}}
|
|
|
|
|
|
|
+ interpreter = {'name': 'hive', 'options': {'url': 'phoenix://'}}
|
|
|
data = SqlAlchemyApi(self.user, interpreter).get_browse_query(snippet=Mock(), database='db1', table='table1')
|
|
data = SqlAlchemyApi(self.user, interpreter).get_browse_query(snippet=Mock(), database='db1', table='table1')
|
|
|
|
|
|
|
|
assert_equal(data, 'SELECT *\nFROM `db1`.`table1`\nLIMIT 1000\n')
|
|
assert_equal(data, 'SELECT *\nFROM `db1`.`table1`\nLIMIT 1000\n')
|
|
|
|
|
|
|
|
|
|
|
|
|
- interpreter = {'options': {'url': 'postgresql://'}}
|
|
|
|
|
|
|
+ interpreter = {'name': 'hive', 'options': {'url': 'postgresql://'}}
|
|
|
data = SqlAlchemyApi(self.user, interpreter).get_browse_query(snippet=Mock(), database='db1', table='table1')
|
|
data = SqlAlchemyApi(self.user, interpreter).get_browse_query(snippet=Mock(), database='db1', table='table1')
|
|
|
|
|
|
|
|
assert_equal(data, 'SELECT *\nFROM "db1"."table1"\nLIMIT 1000\n')
|
|
assert_equal(data, 'SELECT *\nFROM "db1"."table1"\nLIMIT 1000\n')
|
|
@@ -256,6 +264,7 @@ class TestAutocomplete(object):
|
|
|
|
|
|
|
|
def test_empty_database_names(self):
|
|
def test_empty_database_names(self):
|
|
|
interpreter = {
|
|
interpreter = {
|
|
|
|
|
+ 'name': 'hive',
|
|
|
'options': {'url': 'phoenix://'}
|
|
'options': {'url': 'phoenix://'}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -271,6 +280,7 @@ class TestAutocomplete(object):
|
|
|
|
|
|
|
|
def test_columns_with_null_type(self):
|
|
def test_columns_with_null_type(self):
|
|
|
interpreter = {
|
|
interpreter = {
|
|
|
|
|
+ 'name': 'hive',
|
|
|
'options': {'url': 'phoenix://'}
|
|
'options': {'url': 'phoenix://'}
|
|
|
}
|
|
}
|
|
|
|
|
|