1
0
Fork 0
forked from s3lph/matemat

Fix: Fetch receipt_pref in list_users.

This commit is contained in:
s3lph 2018-09-09 03:53:52 +02:00
parent 0a27e6db56
commit a8e0687095
2 changed files with 10 additions and 4 deletions

View file

@ -86,15 +86,19 @@ class MatematDatabase(object):
users: List[User] = [] users: List[User] = []
with self.db.transaction(exclusive=False) as c: with self.db.transaction(exclusive=False) as c:
for row in c.execute(''' for row in c.execute('''
SELECT user_id, username, email, is_admin, is_member, balance SELECT user_id, username, email, is_admin, is_member, balance, receipt_pref
FROM users FROM users
WHERE touchkey IS NOT NULL OR NOT :must_have_touchkey WHERE touchkey IS NOT NULL OR NOT :must_have_touchkey
''', { ''', {
'must_have_touchkey': with_touchkey 'must_have_touchkey': with_touchkey
}): }):
# Decompose each row and put the values into a User object # Decompose each row and put the values into a User object
user_id, username, email, is_admin, is_member, balance = row user_id, username, email, is_admin, is_member, balance, receipt_p = row
users.append(User(user_id, username, balance, email, is_admin, is_member)) try:
receipt_pref: ReceiptPreference = ReceiptPreference(receipt_p)
except ValueError:
raise DatabaseConsistencyError(f'{receipt_p} is not a valid ReceiptPreference')
users.append(User(user_id, username, balance, email, is_admin, is_member, receipt_pref))
return users return users
def get_user(self, uid: int) -> User: def get_user(self, uid: int) -> User:

View file

@ -58,7 +58,8 @@ class DatabaseTest(unittest.TestCase):
testuser: User = db.create_user('testuser', 'supersecurepassword', 'testuser@example.com', True, True) testuser: User = db.create_user('testuser', 'supersecurepassword', 'testuser@example.com', True, True)
db.change_touchkey(testuser, '', 'touchkey', verify_password=False) db.change_touchkey(testuser, '', 'touchkey', verify_password=False)
db.create_user('anothertestuser', 'otherpassword', 'anothertestuser@example.com', False, True) db.create_user('anothertestuser', 'otherpassword', 'anothertestuser@example.com', False, True)
db.create_user('yatu', 'igotapasswordtoo', 'yatu@example.com', False, False) u = db.create_user('yatu', 'igotapasswordtoo', 'yatu@example.com', False, False)
db.change_user(u, agent=None, receipt_pref=ReceiptPreference.WEEKLY)
users = db.list_users() users = db.list_users()
users_with_touchkey = db.list_users(with_touchkey=True) users_with_touchkey = db.list_users(with_touchkey=True)
self.assertEqual(3, len(users)) self.assertEqual(3, len(users))
@ -76,6 +77,7 @@ class DatabaseTest(unittest.TestCase):
self.assertEqual('yatu@example.com', user.email) self.assertEqual('yatu@example.com', user.email)
self.assertFalse(user.is_member) self.assertFalse(user.is_member)
self.assertFalse(user.is_admin) self.assertFalse(user.is_admin)
self.assertEqual(ReceiptPreference.WEEKLY, user.receipt_pref)
usercheck[user.id] = 1 usercheck[user.id] = 1
self.assertEqual(3, len(usercheck)) self.assertEqual(3, len(usercheck))
self.assertEqual(1, len(users_with_touchkey)) self.assertEqual(1, len(users_with_touchkey))