Fixed change_user and change_product unit tests.

This commit is contained in:
s3lph 2018-07-21 21:45:05 +02:00
parent bead299ccd
commit ce0a01cb7c

View file

@ -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)