Example #1
0
 def test_ok_offset(self):
     query = {
         'limit': '10',
         'offset': '10',
     }
     sql = db.make_sql(query)
     assert sql == 'SELECT id, title, url, created FROM news LIMIT 10 OFFSET 10'
Example #2
0
 def test_ok_order_limit(self):
     query = {
         'order': 'title DESC',
         'limit': '10',
     }
     sql = db.make_sql(query)
     assert sql == 'SELECT id, title, url, created FROM news ORDER BY title DESC LIMIT 10'
Example #3
0
 def test_fail_order_direction(self):
     query = {'order': 'title some'}
     with pytest.raises(RuntimeError) as exinfo:
         db.make_sql(query)
     assert 'incorrect order direction' in str(exinfo.value)
Example #4
0
 def test_fail_order(self):
     query = {'order': 'hah'}
     with pytest.raises(RuntimeError) as exinfo:
         db.make_sql(query)
     assert 'incorrect order' in str(exinfo.value)
Example #5
0
 def test_ok_limit(self):
     query = {'limit': '10'}
     sql = db.make_sql(query)
     assert sql == 'SELECT id, title, url, created FROM news LIMIT 10'
Example #6
0
 def test_ok_order_asc(self):
     query = {'order': 'url asc'}
     sql = db.make_sql(query)
     assert sql == 'SELECT id, title, url, created FROM news ORDER BY url ASC LIMIT 5'
Example #7
0
 def test_ok_order(self):
     query = {'order': 'title'}
     sql = db.make_sql(query)
     assert sql == 'SELECT id, title, url, created FROM news ORDER BY title LIMIT 5'
Example #8
0
 def test_ok_no_args(self):
     query = {}
     sql = db.make_sql(query)
     assert sql == 'SELECT id, title, url, created FROM news LIMIT 5'
Example #9
0
 def test_fail_limit(self):
     query = {'limit': '-10'}
     with pytest.raises(RuntimeError) as exinfo:
         db.make_sql(query)
     assert 'incorrect limit' in str(exinfo.value)