Пример #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 > ?;'
Пример #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 = ?;'
Пример #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;'
Пример #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;'
Пример #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;'
Пример #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 ?;'
Пример #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 ?;'
Пример #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 > ?;'
Пример #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 <= ?;'
Пример #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 <> ?;'
Пример #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;'
Пример #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;'
Пример #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 = ?;'
Пример #14
0
 def test_wildcard(self):
     query = qs.select('test', ('*', ))
     assert query == 'SELECT * FROM test;'
Пример #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;'
Пример #16
0
 def test_single_field(self):
     assert qs.select('test', ('name', )) == 'SELECT name FROM test;'
Пример #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;'
Пример #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;'
Пример #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;'
Пример #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;'
Пример #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;'
Пример #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;'
Пример #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;'
Пример #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;'