def test_where_functions(self): s = SQLGenerator() params = { 'nom': 'dupont', 'prenom': 'jean', 'age': SQLExpression('YEARS(%(date)s)', date='2013/01/01') } self.assertEqual( s.where(params), 'age = YEARS(%(date)s) AND nom = %(nom)s AND prenom = %(prenom)s') self.assertEqual(params, { 'nom': 'dupont', 'prenom': 'jean', 'date': '2013/01/01' }) params = { 'nom': 'dupont', 'prenom': 'jean', 'age': SQLExpression('YEARS(%(date)s)', date='2013/01/01') } self.assertEqual( s.where(params, 'x.id = y.id'), 'x.id = y.id AND age = YEARS(%(date)s) AND nom = %(nom)s AND prenom = %(prenom)s' ) self.assertEqual(params, { 'nom': 'dupont', 'prenom': 'jean', 'date': '2013/01/01' })
def test_set_functions(self): s = SQLGenerator() params = { 'nom': 'dupont', 'prenom': 'jean', 'age': SQLExpression('YEARS(%(date)s)', date='2013/01/01') } self.assertEqual( s.set(params), 'age = YEARS(%(date)s), nom = %(nom)s, prenom = %(prenom)s') self.assertEqual(params, { 'nom': 'dupont', 'prenom': 'jean', 'date': '2013/01/01' })
def test_delete_functions(self): s = SQLGenerator() params = { 'nom': 'dupont', 'prenom': 'jean', 'age': SQLExpression('YEARS(%(date)s)', date='2013/01/01') } self.assertEqual( s.delete('test', params), 'DELETE 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' })
def test_adv_select_functions(self): s = SQLGenerator() params = { 'nom': 'dupont', 'prenom': 'jean', 'age': SQLExpression('YEARS(%(date)s)', date='2013/01/01') } self.assertEqual( s.adv_select(['column'], [('test', 't')], params), 'SELECT column FROM test AS t WHERE age = YEARS(%(date)s) ' 'AND nom = %(nom)s AND prenom = %(prenom)s') self.assertEqual(params, { 'nom': 'dupont', 'prenom': 'jean', 'date': '2013/01/01' })
def test_insert_functions(self): s = SQLGenerator() params = { 'nom': 'dupont', 'prenom': 'jean', 'age': SQLExpression('YEARS(%(date)s)', date='2013/01/01') } sqlstr = s.insert('test', params) self.assertEqual( sqlstr, 'INSERT INTO test ( age, nom, prenom ) VALUES ' '( YEARS(%(date)s), %(nom)s, %(prenom)s )') self.assertEqual(params, { 'nom': 'dupont', 'prenom': 'jean', 'date': '2013/01/01' })
def test_update_functions(self): s = SQLGenerator() params = { 'id': '001', 'nom': 'dupont', 'prenom': 'jean', 'age': SQLExpression('YEARS(%(date)s)', date='2013/01/01') } self.assertEqual( s.update('test', params, ['id']), 'UPDATE test SET age = YEARS(%(date)s), nom = %(nom)s, ' 'prenom = %(prenom)s WHERE id = %(id)s') self.assertEqual(params, { 'nom': 'dupont', 'prenom': 'jean', 'date': '2013/01/01', 'id': '001' })