From 0b34f5ec7f664a062ec3095b21828b21b0fc9145 Mon Sep 17 00:00:00 2001 From: s3lph Date: Tue, 14 Aug 2018 23:58:54 +0200 Subject: [PATCH] Added unit tests for admin user test and touchkey-only userlist. --- matemat/db/test/test_facade.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/matemat/db/test/test_facade.py b/matemat/db/test/test_facade.py index d82b62c..5843a29 100644 --- a/matemat/db/test/test_facade.py +++ b/matemat/db/test/test_facade.py @@ -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: