Fixed change_user and change_product unit tests.
This commit is contained in:
parent
bead299ccd
commit
ce0a01cb7c
1 changed files with 19 additions and 8 deletions
|
@ -145,11 +145,18 @@ class DatabaseTest(unittest.TestCase):
|
||||||
with self.db as db:
|
with self.db as db:
|
||||||
agent = db.create_user('admin', 'supersecurepassword', 'admin@example.com', True, True)
|
agent = db.create_user('admin', 'supersecurepassword', 'admin@example.com', True, True)
|
||||||
user = db.create_user('testuser', 'supersecurepassword', 'testuser@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)
|
db.change_user(user, agent, email='newaddress@example.com', is_admin=False, is_member=False, balance=4200)
|
||||||
checkuser = db.login('testuser', 'supersecurepassword')
|
# Changes must be reflected in the passed user object
|
||||||
self.assertEqual('newaddress@example.com', checkuser.email)
|
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_admin)
|
||||||
self.assertFalse(checkuser.is_member)
|
self.assertFalse(checkuser.is_member)
|
||||||
|
self.assertEqual(4200, checkuser.balance)
|
||||||
user._user_id = -1
|
user._user_id = -1
|
||||||
with self.assertRaises(DatabaseConsistencyError):
|
with self.assertRaises(DatabaseConsistencyError):
|
||||||
db.change_user(user, agent, is_member='True')
|
db.change_user(user, agent, is_member='True')
|
||||||
|
@ -219,14 +226,18 @@ class DatabaseTest(unittest.TestCase):
|
||||||
def test_change_product(self) -> None:
|
def test_change_product(self) -> None:
|
||||||
with self.db as db:
|
with self.db as db:
|
||||||
product = db.create_product('Club Mate', 200, 200)
|
product = db.create_product('Club Mate', 200, 200)
|
||||||
product.name = 'Flora Power Mate'
|
db.change_product(product, name='Flora Power Mate', price_member=150, price_non_member=250, stock=42)
|
||||||
product.price_member = 150
|
# Changes must be reflected in the passed object
|
||||||
product.price_non_member = 250
|
self.assertEqual('Flora Power Mate', product.name)
|
||||||
db.change_product(product)
|
self.assertEqual(150, product.price_member)
|
||||||
checkproduct = db.list_products()[0]
|
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('Flora Power Mate', checkproduct.name)
|
||||||
self.assertEqual(150, checkproduct.price_member)
|
self.assertEqual(150, checkproduct.price_member)
|
||||||
self.assertEqual(250, checkproduct.price_non_member)
|
self.assertEqual(250, checkproduct.price_non_member)
|
||||||
|
self.assertEqual(42, checkproduct.stock)
|
||||||
product._product_id = -1
|
product._product_id = -1
|
||||||
with self.assertRaises(DatabaseConsistencyError):
|
with self.assertRaises(DatabaseConsistencyError):
|
||||||
db.change_product(product)
|
db.change_product(product)
|
||||||
|
|
Loading…
Reference in a new issue