From 0a27e6db5631aa35d6406bc3db023509a49c4de2 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 9 Sep 2018 03:44:49 +0200 Subject: [PATCH] Hopefully fixed now! --- matemat/db/facade.py | 6 +++++- matemat/db/test/test_facade.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/matemat/db/facade.py b/matemat/db/facade.py index c7a7be7..039961f 100644 --- a/matemat/db/facade.py +++ b/matemat/db/facade.py @@ -183,7 +183,7 @@ class MatematDatabase(object): row = c.fetchone() if row is None: raise AuthenticationError('User does not exist') - user_id, username, email, pwhash, tkhash, admin, member, balance, receipt_pref = row + user_id, username, email, pwhash, tkhash, admin, member, balance, receipt_p = row if password is not None and not compare_digest(crypt.crypt(password, pwhash), pwhash): raise AuthenticationError('Password mismatch') elif touchkey is not None \ @@ -192,6 +192,10 @@ class MatematDatabase(object): raise AuthenticationError('Touchkey mismatch') elif touchkey is not None and tkhash is None: raise AuthenticationError('Touchkey not set') + try: + receipt_pref: ReceiptPreference = ReceiptPreference(receipt_p) + except ValueError: + raise DatabaseConsistencyError(f'{receipt_p} is not a valid ReceiptPreference') return User(user_id, username, balance, email, admin, member, receipt_pref) def change_password(self, user: User, oldpass: str, newpass: str, verify_password: bool = True) -> None: diff --git a/matemat/db/test/test_facade.py b/matemat/db/test/test_facade.py index 974056e..19e19c3 100644 --- a/matemat/db/test/test_facade.py +++ b/matemat/db/test/test_facade.py @@ -108,7 +108,7 @@ class DatabaseTest(unittest.TestCase): self.assertEqual(u.id, user.id) user = db.login('testuser', touchkey='0123') self.assertEqual(u.id, user.id) - self.assertEqual(2, user.receipt_pref) + self.assertEqual(ReceiptPreference.MONTHLY, user.receipt_pref) with self.assertRaises(AuthenticationError): # Inexistent user should fail db.login('nooone', 'supersecurepassword')