Implemented unit tests for get_user and get_product.
This commit is contained in:
parent
105a10e91b
commit
fcc64d1662
1 changed files with 24 additions and 0 deletions
|
@ -26,6 +26,19 @@ class DatabaseTest(unittest.TestCase):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
db.create_user('testuser', 'supersecurepassword2', 'testuser2@example.com')
|
db.create_user('testuser', 'supersecurepassword2', 'testuser2@example.com')
|
||||||
|
|
||||||
|
def test_get_user(self) -> None:
|
||||||
|
with self.db as db:
|
||||||
|
with db.transaction(exclusive=False):
|
||||||
|
created = db.create_user('testuser', 'supersecurepassword', 'testuser@example.com',
|
||||||
|
admin=True, member=False)
|
||||||
|
user = db.get_user(created.id)
|
||||||
|
self.assertEqual('testuser', user.name)
|
||||||
|
self.assertEqual('testuser@example.com', user.email)
|
||||||
|
self.assertEqual(False, user.is_member)
|
||||||
|
self.assertEqual(True, user.is_admin)
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
db.get_user(-1)
|
||||||
|
|
||||||
def test_list_users(self) -> None:
|
def test_list_users(self) -> None:
|
||||||
with self.db as db:
|
with self.db as db:
|
||||||
users = db.list_users()
|
users = db.list_users()
|
||||||
|
@ -170,6 +183,17 @@ class DatabaseTest(unittest.TestCase):
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
db.create_product('Club Mate', 250, 250)
|
db.create_product('Club Mate', 250, 250)
|
||||||
|
|
||||||
|
def test_get_product(self) -> None:
|
||||||
|
with self.db as db:
|
||||||
|
with db.transaction(exclusive=False):
|
||||||
|
created = db.create_product('Club Mate', 150, 250)
|
||||||
|
product = db.get_product(created.id)
|
||||||
|
self.assertEqual('Club Mate', product.name)
|
||||||
|
self.assertEqual(150, product.price_member)
|
||||||
|
self.assertEqual(250, product.price_non_member)
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
db.get_product(-1)
|
||||||
|
|
||||||
def test_list_products(self) -> None:
|
def test_list_products(self) -> None:
|
||||||
with self.db as db:
|
with self.db as db:
|
||||||
# Test empty list
|
# Test empty list
|
||||||
|
|
Loading…
Reference in a new issue