Added unit tests for admin user test and touchkey-only userlist.
This commit is contained in:
parent
707883b1c4
commit
0b34f5ec7f
1 changed files with 17 additions and 2 deletions
|
@ -4,6 +4,7 @@ import unittest
|
|||
import crypt
|
||||
|
||||
from matemat.db import MatematDatabase
|
||||
from matemat.db.primitives import User
|
||||
from matemat.exceptions import AuthenticationError, DatabaseConsistencyError
|
||||
|
||||
|
||||
|
@ -43,11 +44,15 @@ class DatabaseTest(unittest.TestCase):
|
|||
with self.db as db:
|
||||
users = db.list_users()
|
||||
self.assertEqual(0, len(users))
|
||||
db.create_user('testuser', 'supersecurepassword', 'testuser@example.com', True, True)
|
||||
users = db.list_users(with_touchkey=True)
|
||||
self.assertEqual(0, len(users))
|
||||
testuser: User = db.create_user('testuser', 'supersecurepassword', 'testuser@example.com', True, True)
|
||||
db.change_touchkey(testuser, '', 'touchkey', verify_password=False)
|
||||
db.create_user('anothertestuser', 'otherpassword', 'anothertestuser@example.com', False, True)
|
||||
db.create_user('yatu', 'igotapasswordtoo', 'yatu@example.com', False, False)
|
||||
users = db.list_users()
|
||||
self.assertEqual(3, len(users))
|
||||
users_with_touchkey = db.list_users(with_touchkey=True)
|
||||
self.assertEqual(3, len(users))
|
||||
usercheck = {}
|
||||
for user in users:
|
||||
if user.name == 'testuser':
|
||||
|
@ -64,6 +69,16 @@ class DatabaseTest(unittest.TestCase):
|
|||
self.assertFalse(user.is_admin)
|
||||
usercheck[user.id] = 1
|
||||
self.assertEqual(3, len(usercheck))
|
||||
self.assertEqual(1, len(users_with_touchkey))
|
||||
self.assertEqual('testuser', users_with_touchkey[0].name)
|
||||
|
||||
def test_has_admin_users(self):
|
||||
with self.db as db:
|
||||
self.assertFalse(db.has_admin_users())
|
||||
testuser: User = db.create_user('testuser', 'supersecurepassword', 'testuser@example.com', True, True)
|
||||
self.assertTrue(db.has_admin_users())
|
||||
db.change_user(testuser, agent=testuser, is_admin=False)
|
||||
self.assertFalse(db.has_admin_users())
|
||||
|
||||
def test_login(self) -> None:
|
||||
with self.db as db:
|
||||
|
|
Loading…
Reference in a new issue