Ejemplo n.º 1
0
 def test_multi_search_conditions(self, test_fields):
     table = test_fields['table']
     condition = test_fields['multi_search']
     query = qs.select(table, ('*', ), condition, operator=(
         '=',
         '>',
     ))
     assert query == 'SELECT * FROM test WHERE age = ? AND name > ?;'
Ejemplo n.º 2
0
 def test_in(self, test_fields):
     table = test_fields['table']
     condition = test_fields['tri_search']
     query = qs.select(table, ('*', ),
                       condition,
                       operator=('<', 'LIKE', '='),
                       logic_operator=('AND', 'OR'))
     assert query == 'SELECT * FROM test WHERE age < ? AND first LIKE ? OR last = ?;'
Ejemplo n.º 3
0
 def test_multi_order(self, test_fields):
     order_by = test_fields['multi_search']
     query = qs.select(
         test_fields['table'],
         ('*', ),
         order_by=order_by,
     )
     assert query == 'SELECT * FROM test ORDER BY age, name;'
Ejemplo n.º 4
0
 def test_after_order(self, test_fields):
     order_by = test_fields['sing_search']
     limit = {'limit': 5}
     query = qs.select(test_fields['table'], ('*', ),
                       order_by=order_by,
                       order=('DESC', ),
                       limit=limit)
     assert query == 'SELECT * FROM test ORDER BY age DESC LIMIT 5;'
Ejemplo n.º 5
0
 def test_order_with_Where(self, test_fields):
     order_by = test_fields['sing_search']
     condition = test_fields['multi_search']
     query = qs.select(test_fields['table'], ('*', ),
                       search_condition=condition,
                       operator=('=', 'LIKE'),
                       order_by=order_by,
                       order=('DESC', ))
     assert query == 'SELECT * FROM test WHERE age = ? AND name LIKE ? ORDER BY age DESC;'
Ejemplo n.º 6
0
 def test_in(self, test_fields):
     table = test_fields['table']
     condition = test_fields['sing_search']
     query = qs.select(
         table,
         ('*', ),
         condition,
         operator=('BETWEEN', ),
     )
     assert query == 'SELECT * FROM test WHERE age BETWEEN ? AND ?;'
Ejemplo n.º 7
0
 def test_like(self, test_fields):
     table = test_fields['table']
     condition = test_fields['sing_search']
     query = qs.select(
         table,
         ('*', ),
         condition,
         operator=('LIKE', ),
     )
     assert query == 'SELECT * FROM test WHERE age LIKE ?;'
Ejemplo n.º 8
0
 def test_greater_than(self, test_fields):
     table = test_fields['table']
     condition = test_fields['sing_search']
     query = qs.select(
         table,
         ('*', ),
         condition,
         operator=('>', ),
     )
     assert query == 'SELECT * FROM test WHERE age > ?;'
Ejemplo n.º 9
0
 def test_less_than_or_equal(self, test_fields):
     table = test_fields['table']
     condition = test_fields['sing_search']
     query = qs.select(
         table,
         ('*', ),
         condition,
         operator=('<=', ),
     )
     assert query == 'SELECT * FROM test WHERE age <= ?;'
Ejemplo n.º 10
0
 def test_not_equal_2(self, test_fields):
     table = test_fields['table']
     condition = test_fields['sing_search']
     query = qs.select(
         table,
         ('*', ),
         condition,
         operator=('<>', ),
     )
     assert query == 'SELECT * FROM test WHERE age <> ?;'
Ejemplo n.º 11
0
 def test_multi_search_conditions_new_placeholder(self, test_fields):
     table = test_fields['table']
     condition = test_fields['multi_search']
     query = qs.select(table, ('*', ),
                       condition,
                       operator=(
                           '=',
                           '=',
                       ),
                       logic_operator=('OR', ),
                       place_holder='%s')
     assert query == 'SELECT * FROM test WHERE age = %s OR name = %s;'
Ejemplo n.º 12
0
 def test_default(self, test_fields):
     table = test_fields['table']
     order_by = test_fields['sing_search']
     query = qs.select(table, ('*', ), order_by=order_by)
     assert query == 'SELECT * FROM test ORDER BY age;'
Ejemplo n.º 13
0
 def test_single_search_conditions(self, test_fields):
     table = test_fields['table']
     condition = test_fields['sing_search']
     query = qs.select(table, ('*', ), condition)
     assert query == 'SELECT * FROM test WHERE age = ?;'
Ejemplo n.º 14
0
 def test_wildcard(self):
     query = qs.select('test', ('*', ))
     assert query == 'SELECT * FROM test;'
Ejemplo n.º 15
0
 def test_multiple_fields(self, test_fields):
     query = qs.select(test_fields['table'], test_fields['fields'])
     assert query == 'SELECT id, age, name FROM test;'
Ejemplo n.º 16
0
 def test_single_field(self):
     assert qs.select('test', ('name', )) == 'SELECT name FROM test;'
Ejemplo n.º 17
0
 def test_average(self, test_fields, agregate):
     sum_ = agregate['sum']('age')
     test_fields['sing_search']
     query = qs.select(test_fields['table'], (sum_, ))
     assert query == f'SELECT sum(age) FROM test;'
Ejemplo n.º 18
0
 def test_min(self, test_fields, agregate):
     min_ = agregate['min']('age')
     test_fields['sing_search']
     query = qs.select(test_fields['table'], (min_, ))
     assert query == f'SELECT min(age) FROM test;'
Ejemplo n.º 19
0
 def test_count(self, test_fields, agregate):
     count = agregate['count']('age')
     test_fields['sing_search']
     query = qs.select(test_fields['table'], (count, ))
     assert query == f'SELECT count(age) FROM test;'
Ejemplo n.º 20
0
 def test_average(self, test_fields, agregate):
     avg = agregate['avg']('age')
     test_fields['sing_search']
     query = qs.select(test_fields['table'], (avg, ))
     assert query == f'SELECT avg(age) FROM test;'
Ejemplo n.º 21
0
 def test_with_offset(self, test_fields):
     limit = {'limit': 5, 'offset': 7}
     query = qs.select(test_fields['table'], ('*', ), limit=limit)
     assert query == 'SELECT * FROM test LIMIT 5 OFFSET 7;'
Ejemplo n.º 22
0
 def test_no_offset(self, test_fields):
     limit = {'limit': 5}
     query = qs.select(test_fields['table'], ('*', ), limit=limit)
     assert query == 'SELECT * FROM test LIMIT 5;'
Ejemplo n.º 23
0
 def test_explicit_DESC(self, test_fields):
     table = test_fields['table']
     order_by = test_fields['sing_search']
     query = qs.select(table, ('*', ), order_by=order_by, order=('DESC', ))
     assert query == 'SELECT * FROM test ORDER BY age DESC;'
Ejemplo n.º 24
0
 def test_multi_mixed_order(self, test_fields):
     order_by = test_fields['multi_search']
     query = qs.select(test_fields['table'], ('*', ),
                       order_by=order_by,
                       order=('ASC', 'DESC'))
     assert query == 'SELECT * FROM test ORDER BY age ASC, name DESC;'