|
|
@@ -269,7 +269,6 @@ class TestAutocomplete(object):
|
|
|
|
|
|
assert_equal(data['databases'], ['SYSTEM', 'NULL'])
|
|
|
|
|
|
-
|
|
|
def test_columns_with_null_type(self):
|
|
|
interpreter = {
|
|
|
'options': {'url': 'phoenix://'}
|
|
|
@@ -296,43 +295,30 @@ class TestAutocomplete(object):
|
|
|
col2.__getitem__.side_effect = col2_dict
|
|
|
col2.get = col2_dict
|
|
|
|
|
|
- Assist.return_value=Mock(get_columns=Mock(return_value=[col1, col2]))
|
|
|
+ Assist.return_value=Mock(get_columns=Mock(return_value=[col1, col2]), get_keys=Mock(return_value={}))
|
|
|
|
|
|
data = SqlAlchemyApi(self.user, interpreter).autocomplete(snippet, database='database', table='table')
|
|
|
|
|
|
assert_equal(data['columns'], ['col1', 'col2'])
|
|
|
assert_equal([col['type'] for col in data['extended_columns']], ['string', 'Null'])
|
|
|
|
|
|
- def test_get_foreign_keys(self):
|
|
|
-
|
|
|
- interpreter = {
|
|
|
- 'options': {'url': 'phoenix://'}
|
|
|
- }
|
|
|
-
|
|
|
- snippet = Mock()
|
|
|
- with patch('notebook.connectors.sql_alchemy.create_engine') as create_engine:
|
|
|
- with patch('notebook.connectors.sql_alchemy.inspect') as inspect:
|
|
|
- with patch('notebook.connectors.sql_alchemy.Assist') as Assist:
|
|
|
- def col1_dict(key):
|
|
|
- return {
|
|
|
- 'name': 'col1',
|
|
|
- 'type': 'string'
|
|
|
- }.get(key, Mock())
|
|
|
- col1 = MagicMock()
|
|
|
- col1.__getitem__.side_effect = col1_dict
|
|
|
- col1.get = col1_dict
|
|
|
- def col2_dict(key):
|
|
|
- return {
|
|
|
- 'name': 'col2',
|
|
|
- 'type': NullType()
|
|
|
- }.get(key, Mock())
|
|
|
- col2 = MagicMock()
|
|
|
- col2.__getitem__.side_effect = col2_dict
|
|
|
- col2.get = col2_dict
|
|
|
+ def test_get_keys(self):
|
|
|
|
|
|
- Assist.return_value=Mock(get_columns=Mock(return_value=[col1, col2]))
|
|
|
+ with patch('notebook.connectors.sql_alchemy.Table') as Table:
|
|
|
+ Table.return_value = Mock(
|
|
|
+ foreign_keys=[
|
|
|
+ Mock(
|
|
|
+ parent=Mock(name='col1'),
|
|
|
+ target_fullname='db2.table2.col2'
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ primary_key=Mock(columns=[Mock(name='col2')])
|
|
|
+ )
|
|
|
|
|
|
+ db, engine, backticks = Mock(), Mock(), Mock()
|
|
|
+ database, table = Mock(), Mock()
|
|
|
|
|
|
+ keys = Assist(db, engine, backticks).get_keys(database, table)
|
|
|
|
|
|
- assert_equal(data['columns'], ['col1', 'col2'])
|
|
|
- assert_equal([col['type'] for col in data['extended_columns']], ['string', 'Null'])
|
|
|
+ assert_true(keys['primary_keys']) # For some reason could not mock two level to get some colum names
|
|
|
+ assert_equal(keys['foreign_keys'][0]['to'], 'db2.table2.col2')
|