Fix database unit tests
This commit is contained in:
parent
a5b52e24b5
commit
e2db21fc1b
2 changed files with 5 additions and 9 deletions
|
@ -471,8 +471,7 @@ class MatematDatabase(object):
|
|||
|
||||
def increment_consumption(self, user: User, product: Product) -> None:
|
||||
"""
|
||||
Decrement the user's balance by the price of the product, decrement the products stock, and create an entry in
|
||||
the statistics table.
|
||||
Decrement the user's balance by the price of the product and create an entry in the statistics table.
|
||||
|
||||
:param user: The user buying a product.
|
||||
:param product: The product the user is buying.
|
||||
|
|
|
@ -279,7 +279,7 @@ class DatabaseTest(unittest.TestCase):
|
|||
self.assertEqual('Flora Power Mate', product.name)
|
||||
self.assertEqual(150, product.price_member)
|
||||
self.assertEqual(250, product.price_non_member)
|
||||
self.assertEqual(42, product.stock)
|
||||
self.assertEqual(None, product.stock)
|
||||
self.assertEqual(False, product.stockable)
|
||||
# Changes must be reflected in the database
|
||||
checkproduct = db.get_product(product.id)
|
||||
|
@ -367,11 +367,8 @@ class DatabaseTest(unittest.TestCase):
|
|||
self.assertEqual(1234, c.fetchone()[0])
|
||||
|
||||
user1.id = -1
|
||||
clubmate.id = -1
|
||||
with self.assertRaises(DatabaseConsistencyError):
|
||||
db.increment_consumption(user1, florapowermate)
|
||||
with self.assertRaises(DatabaseConsistencyError):
|
||||
db.increment_consumption(user2, clubmate)
|
||||
|
||||
def test_check_receipt_due(self):
|
||||
with self.db as db:
|
||||
|
@ -475,7 +472,7 @@ class DatabaseTest(unittest.TestCase):
|
|||
|
||||
admin: User = db.create_user('admin', 'supersecurepassword', 'admin@example.com', True, True)
|
||||
user: User = db.create_user('user', 'supersecurepassword', 'user@example.com', True, True)
|
||||
product: Product = db.create_product('Flora Power Mate', 200, 200)
|
||||
product: Product = db.create_product('Flora Power Mate', 200, 200, True)
|
||||
|
||||
# Create some transactions
|
||||
db.change_user(user, agent=admin,
|
||||
|
@ -564,8 +561,8 @@ class DatabaseTest(unittest.TestCase):
|
|||
user2: User = db.create_user('user2', 'supersecurepassword', 'user2@example.com', True, False)
|
||||
user3: User = db.create_user('user3', 'supersecurepassword', 'user3@example.com', True, False)
|
||||
user4: User = db.create_user('user4', 'supersecurepassword', 'user4@example.com', True, False)
|
||||
flora: Product = db.create_product('Flora Power Mate', 200, 200)
|
||||
club: Product = db.create_product('Club Mate', 200, 200)
|
||||
flora: Product = db.create_product('Flora Power Mate', 200, 200, True)
|
||||
club: Product = db.create_product('Club Mate', 200, 200, False)
|
||||
|
||||
# Create some transactions
|
||||
db.deposit(user1, 1337)
|
||||
|
|
Loading…
Reference in a new issue