From e2db21fc1b1f7fa28936fc91c59c0ba8411b3642 Mon Sep 17 00:00:00 2001 From: s3lph Date: Mon, 28 Dec 2020 09:54:04 +0100 Subject: [PATCH] Fix database unit tests --- matemat/db/facade.py | 3 +-- matemat/db/test/test_facade.py | 11 ++++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/matemat/db/facade.py b/matemat/db/facade.py index 957c744..43a150f 100644 --- a/matemat/db/facade.py +++ b/matemat/db/facade.py @@ -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. diff --git a/matemat/db/test/test_facade.py b/matemat/db/test/test_facade.py index d232352..d3e34fb 100644 --- a/matemat/db/test/test_facade.py +++ b/matemat/db/test/test_facade.py @@ -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)