def test_select_values(self): s = SQLGenerator() self.assertEqual(s.select('test', {}), 'SELECT * FROM test') self.assertEqual(s.select('test', {'nom': 'dupont'}), 'SELECT * FROM test WHERE nom = %(nom)s') self.assertEqual( s.select('test', { 'nom': 'dupont', 'prenom': 'jean' }), 'SELECT * FROM test WHERE nom = %(nom)s AND prenom = %(prenom)s')
def test_select_functions(self): s = SQLGenerator() params = { 'nom': 'dupont', 'prenom': 'jean', 'age': SQLExpression('YEARS(%(date)s)', date='2013/01/01') } self.assertEqual( s.select('test', params), 'SELECT * FROM test WHERE age = YEARS(%(date)s) ' 'AND nom = %(nom)s AND prenom = %(prenom)s') self.assertEqual(params, { 'nom': 'dupont', 'prenom': 'jean', 'date': '2013/01/01' })