def test_two_expr_columns(self): col_a = sql_builder.GreaterThanValue(1) col_b = sql_builder.LessThanValue(2) sql, bind_vars = sql_builder.build_where_clause( column_value_pairs=[('col_a', col_a), ('col_b', col_b)]) self.assertEqual(sql, 'col_a > %(col_a_1)s AND col_b < %(col_b_2)s') self.assertEqual(bind_vars, dict(col_a_1=1, col_b_2=2))
def test_three_iterable_columns(self): sql, bind_vars = sql_builder.build_where_clause( column_value_pairs=[("col_a", [1]), ("col_b", (2, 3)), ("col_c", set([4, 5]))] ) self.assertEqual( sql, "col_a IN (%(col_a_1)s) AND col_b IN (%(col_b_2)s, %(col_b_3)s) AND " "col_c IN (%(col_c_4)s, %(col_c_5)s)", ) self.assertEqual(bind_vars, dict(col_a_1=1, col_b_2=2, col_b_3=3, col_c_4=4, col_c_5=5))
def test_three_iterable_columns(self): sql, bind_vars = sql_builder.build_where_clause( column_value_pairs=[ ('col_a', [1]), ('col_b', (2, 3)), ('col_c', set([4, 5]))]) self.assertEqual( sql, 'col_a IN (%(col_a_1)s) AND col_b IN (%(col_b_2)s, %(col_b_3)s) AND ' 'col_c IN (%(col_c_4)s, %(col_c_5)s)') self.assertEqual( bind_vars, dict(col_a_1=1, col_b_2=2, col_b_3=3, col_c_4=4, col_c_5=5))
def test_empty_iterable(self): sql, bind_vars = sql_builder.build_where_clause( column_value_pairs=[('col_a', [])]) self.assertEqual(sql, '1 = 0') self.assertEqual(bind_vars, dict(col_a=[]))
def test_two_simple_columns(self): sql, bind_vars = sql_builder.build_where_clause( column_value_pairs=[('col_a', 1), ('col_b', 'two')]) self.assertEqual(sql, 'col_a = %(col_a_1)s AND col_b = %(col_b_2)s') self.assertEqual(bind_vars, dict(col_a_1=1, col_b_2='two'))
def test_two_expr_columns(self): col_a = sql_builder.Greater(1) col_b = sql_builder.Less(2) sql, bind_vars = sql_builder.build_where_clause(column_value_pairs=[("col_a", col_a), ("col_b", col_b)]) self.assertEqual(sql, "col_a > %(col_a_1)s AND col_b < %(col_b_2)s") self.assertEqual(bind_vars, dict(col_a_1=1, col_b_2=2))
def test_two_simple_columns(self): sql, bind_vars = sql_builder.build_where_clause(column_value_pairs=[("col_a", 1), ("col_b", "two")]) self.assertEqual(sql, "col_a = %(col_a_1)s AND col_b = %(col_b_2)s") self.assertEqual(bind_vars, dict(col_a_1=1, col_b_2="two"))