def test_users(self, testdir_function, test_utils): testdir_function.activate() users = Users.users() assert len(users) == 1 username = test_utils.random_string(10) Users.create_user(username, '123') users = Users.users() assert len(users) == 2 assert Users.user_exists(username)
def test_refresh_users(self, testdir_function): testdir_function.activate() user1 = Users.generate_user_dictionary('01', 'username01', '123', None, True, []) user2 = Users.generate_user_dictionary('02', 'username02', '123', None, True, []) assert len(Users.users()) == 1 with open(Users.file_path(), 'w') as f: json.dump([user1, user2], f) Users.refresh_users() assert len(Users.users()) == 2
def test_edit_user_remove_all_superuser_permissions( self, testdir_function): """Cannot edit a user and remove superuser permissions if it's the only superuser available """ testdir_function.activate() assert len(Users.users()) == 1 Users.create_user('standard', '123456') assert len(Users.users()) == 2 errors = Users.edit_user('admin', new_is_superuser=False) assert errors == ['Cannot remove Superuser permission for this user']
def test_create_users_file(self, testdir_function): testdir_function.activate() os.remove(Users.file_path()) Users.create_users_file() assert os.path.isfile(Users.file_path()) with open(Users.file_path()) as f: assert f.read() == '[]' assert Users.users() == []
def users_get(): _verify_permissions(Permissions.SUPER_USER) users = deepcopy(Users.users()) for user in users: del user['password'] return jsonify(users)