Fixed a small bug in the SQL queries and the unit tests
This commit is contained in:
parent
9a41d33ef7
commit
07a4d3131e
2 changed files with 5 additions and 5 deletions
|
@ -606,7 +606,7 @@ class MatematDatabase(object):
|
|||
transactions: List[Transaction] = []
|
||||
with self.db.transaction() as cursor:
|
||||
cursor.execute('''
|
||||
SELECT COALESCE(MAX(r.date), u.created), MAX(r.last_ta_id)
|
||||
SELECT COALESCE(MAX(r.date), u.created), COALESCE(MAX(r.last_ta_id), 0)
|
||||
FROM users AS u
|
||||
LEFT JOIN receipts AS r
|
||||
ON r.user_id = u.user_id
|
||||
|
|
|
@ -506,14 +506,14 @@ class DatabaseTest(unittest.TestCase):
|
|||
db.increment_consumption(user, product)
|
||||
db.deposit(user, 1337)
|
||||
receipt1: Receipt = db.create_receipt(user, write=True)
|
||||
# Attempt to create a receipt with zero transactions. Won't be written to DB.
|
||||
# Attempt to create a receipt with zero transactions. Will carry NULL transaction IDs
|
||||
receipt2: Receipt = db.create_receipt(user, write=True)
|
||||
self.assertEqual(-1, receipt2.id)
|
||||
self.assertNotEqual(-1, receipt2.id)
|
||||
self.assertEqual(0, len(receipt2.transactions))
|
||||
|
||||
with db.transaction() as c:
|
||||
c.execute('SELECT COUNT(receipt_id) FROM receipts')
|
||||
self.assertEqual(1, c.fetchone()[0])
|
||||
self.assertEqual(2, c.fetchone()[0])
|
||||
|
||||
db.increment_consumption(user, product)
|
||||
db.change_user(user, agent=admin, balance=4200)
|
||||
|
@ -529,7 +529,7 @@ class DatabaseTest(unittest.TestCase):
|
|||
|
||||
with db.transaction() as c:
|
||||
c.execute('SELECT COUNT(receipt_id) FROM receipts')
|
||||
self.assertEqual(1, c.fetchone()[0])
|
||||
self.assertEqual(2, c.fetchone()[0])
|
||||
|
||||
self.assertEqual(user, receipt1.user)
|
||||
self.assertEqual(3, len(receipt1.transactions))
|
||||
|
|
Loading…
Reference in a new issue