Add a test for "with totals"

This commit is contained in:
Itai Shirav 2017-04-04 14:41:23 +03:00
parent b27756d44b
commit e1ef96f05b
2 changed files with 10 additions and 8 deletions

View File

@ -38,14 +38,7 @@ def unescape(value):
def parse_tsv(line):
if PY3 and isinstance(line, binary_type):
line = line.decode()
# GROUP BY WITH TOTALS modifier contains a blank line (second last row)
# separating normal result from the totals (last row)
# Let's skip the blank line
try:
last_element = line[-1]
except IndexError:
return
if last_element == '\n':
if line and line[-1] == '\n':
line = line[:-1]
return [unescape(value) for value in line.split('\t')]

View File

@ -89,6 +89,15 @@ class DatabaseTestCase(unittest.TestCase):
self.assertEqual(results[0].get_database(), self.database)
self.assertEqual(results[1].get_database(), self.database)
def test_select_with_totals(self):
self._insert_and_check(self._sample_data(), len(data))
query = "SELECT last_name, sum(height) as height FROM `test-db`.person GROUP BY last_name WITH TOTALS"
results = list(self.database.select(query))
total = sum(r.height for r in results[:-1])
# Last line has an empty last name, and total of all heights
self.assertFalse(results[-1].last_name)
self.assertEquals(total, results[-1].height)
def test_pagination(self):
self._insert_and_check(self._sample_data(), len(data))
# Try different page sizes