def test_search_all_alias_raise_duplicate_error(self): with self.assertRaises(RuntimeError): ctx = StatementBinderContext() ctx._check_table_alias_map = MagicMock() ctx._check_derived_table_alias_map = MagicMock() # duplicate ctx._table_alias_map['alias'] = 'col_name' ctx._derived_table_alias_map['alias'] = 'col_name' ctx._search_all_alias_maps('col_name')
def test_search_all_alias_maps(self): ctx = StatementBinderContext() check_table_map = ctx._check_table_alias_map = MagicMock() check_derived_map = ctx._check_derived_table_alias_map = MagicMock() # only _table_alias_map has entry check_table_map.return_value = 'col_obj' ctx._table_alias_map['alias'] = 'col_name' ctx._derived_table_alias_map = {} result = ctx._search_all_alias_maps('col_name') check_table_map.assert_called_once_with('alias', 'col_name') check_derived_map.assert_not_called() self.assertEqual(result, ('alias', 'col_obj')) # only _derived_table_alias_map check_derived_map.return_value = 'derived_col_obj' ctx._table_alias_map = {} ctx._derived_table_alias_map['alias'] = 'col_name' result = ctx._search_all_alias_maps('col_name') check_table_map.assert_called_once_with('alias', 'col_name') check_table_map.assert_called_once_with('alias', 'col_name') self.assertEqual(result, ('alias', 'derived_col_obj'))