From ce0a01cb7c44a50457d39a6f3c86a6117e9236c7 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 21 Jul 2018 21:45:05 +0200 Subject: [PATCH] Fixed change_user and change_product unit tests. --- matemat/db/test/test_facade.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/matemat/db/test/test_facade.py b/matemat/db/test/test_facade.py index 6913d68..04c0eb4 100644 --- a/matemat/db/test/test_facade.py +++ b/matemat/db/test/test_facade.py @@ -145,11 +145,18 @@ class DatabaseTest(unittest.TestCase): with self.db as db: agent = db.create_user('admin', 'supersecurepassword', 'admin@example.com', True, True) user = db.create_user('testuser', 'supersecurepassword', 'testuser@example.com', True, True) - db.change_user(user, agent, email='newaddress@example.com', is_admin=False, is_member=False) - checkuser = db.login('testuser', 'supersecurepassword') - self.assertEqual('newaddress@example.com', checkuser.email) + db.change_user(user, agent, email='newaddress@example.com', is_admin=False, is_member=False, balance=4200) + # Changes must be reflected in the passed user object + self.assertEqual('newaddress@example.com', user.email) + self.assertFalse(user.is_admin) + self.assertFalse(user.is_member) + self.assertEqual(4200, user.balance) + # Changes must be reflected in the database + checkuser = db.get_user(user.id) + self.assertEqual('newaddress@example.com', user.email) self.assertFalse(checkuser.is_admin) self.assertFalse(checkuser.is_member) + self.assertEqual(4200, checkuser.balance) user._user_id = -1 with self.assertRaises(DatabaseConsistencyError): db.change_user(user, agent, is_member='True') @@ -219,14 +226,18 @@ class DatabaseTest(unittest.TestCase): def test_change_product(self) -> None: with self.db as db: product = db.create_product('Club Mate', 200, 200) - product.name = 'Flora Power Mate' - product.price_member = 150 - product.price_non_member = 250 - db.change_product(product) - checkproduct = db.list_products()[0] + db.change_product(product, name='Flora Power Mate', price_member=150, price_non_member=250, stock=42) + # Changes must be reflected in the passed object + 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) + # Changes must be reflected in the database + checkproduct = db.get_product(product.id) self.assertEqual('Flora Power Mate', checkproduct.name) self.assertEqual(150, checkproduct.price_member) self.assertEqual(250, checkproduct.price_non_member) + self.assertEqual(42, checkproduct.stock) product._product_id = -1 with self.assertRaises(DatabaseConsistencyError): db.change_product(product)