def test_join_functions_on_suggests_columns_and_join_conditions(self, completer): text = '''SELECT * FROM set_returning_func() f1 INNER JOIN set_returning_func() f2 ON f1.''' result = result_set(completer, text) self.assertSetEqual(result, set( [name_join('y = f2.y'), name_join('x = f2.x')] + testdata.columns('set_returning_func', typ='functions') ))
def test_suggested_aliases_after_on(self, completer, text): position = len('SELECT u.name, o.id FROM users u JOIN orders o ON ') result = result_set(completer, text, position) self.assertSetEqual(result, set([ alias('u'), name_join('o.id = u.id'), name_join('o.email = u.email'), alias('o')]))
def test_suggested_tables_after_on(self, completer, text): position = len( 'SELECT users.name, orders.id FROM users JOIN orders ON ') result = result_set(completer, text, position) self.assertSetEqual(result, set([ name_join('orders.id = users.id'), name_join('orders.email = users.email'), alias('users'), alias('orders') ]))
def test_suggested_join_conditions_with_same_table_twice(self, completer, text): result = get_result(completer, text) self.assertListEqual(result, [ fk_join('u2.userid = u.id'), fk_join('u2.userid = users.id'), name_join('u2.userid = "Users".userid'), name_join('u2.username = "******".username'), alias('u'), alias('u2'), alias('users'), alias('"Users"') ])
def test_suggestions_after_on(self, completer, text): position = len( 'SELECT x.id, y.product_name FROM custom.products x JOIN custom.products y ON ' ) result = result_set(completer, text, position) self.assertSetEqual( result, set([ alias('x'), alias('y'), name_join('y.price = x.price'), name_join('y.product_name = x.product_name'), name_join('y.id = x.id') ]))
def test_suggested_join_conditions(self, completer, text): result = result_set(completer, text) self.assertSetEqual( result, set([ alias('users'), alias('shipments'), name_join('shipments.id = users.id'), fk_join('shipments.user_id = users.id') ]))