-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make createuser work for new installations and add basic test.
Allow user creation to provision the directries necessary for user creation to succeed in addition to the database file itself given the state that exists after config generation is run to completion for a new installation. Cover the very basic operation of createuser ensuring that a user db and lock file are correctly create upon a call to create a test user.
- Loading branch information
Showing
6 changed files
with
210 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# --- BEGIN_HEADER --- | ||
# | ||
# test_mig_server-createuser - unit tests for the migrid createuser CLI | ||
# Copyright (C) 2003-2024 The MiG Project by the Science HPC Center at UCPH | ||
# | ||
# This file is part of MiG. | ||
# | ||
# MiG is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# MiG is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
# USA. | ||
# | ||
# --- END_HEADER --- | ||
# | ||
|
||
"""Unit tests for the migrid createuser CLI""" | ||
|
||
from __future__ import print_function | ||
import os | ||
import shutil | ||
import sys | ||
|
||
from tests.support import MIG_BASE, TEST_OUTPUT_DIR, MigTestCase, testmain | ||
|
||
from mig.server.createuser import _main as createuser | ||
from mig.shared.useradm import _USERADM_CONFIG_DIR_KEYS | ||
|
||
|
||
class TestBooleans(MigTestCase): | ||
def before_each(self): | ||
configuration = self.configuration | ||
test_state_path = configuration.state_path | ||
|
||
for config_key in _USERADM_CONFIG_DIR_KEYS: | ||
dir_path = getattr(configuration, config_key)[0:-1] | ||
try: | ||
shutil.rmtree(dir_path) | ||
except: | ||
pass | ||
|
||
self.expected_user_db_home = configuration.user_db_home[0:-1] | ||
|
||
def _provide_configuration(self): | ||
return 'testconfig' | ||
|
||
def test_user_db_is_created_and_user_is_added(self): | ||
args = [ | ||
"Test User", | ||
"Test Org", | ||
"NA", | ||
"DK", | ||
"dummy-user", | ||
"This is the create comment", | ||
"password" | ||
] | ||
print("") # acount for output generated by the logic | ||
createuser(self.configuration, args, default_renew=True) | ||
|
||
# presence of user home | ||
path_kind = MigTestCase._absolute_path_kind(self.expected_user_db_home) | ||
self.assertEqual(path_kind, 'dir') | ||
|
||
# presence of user db | ||
expected_user_db_file = os.path.join( | ||
self.expected_user_db_home, 'MiG-users.db') | ||
path_kind = MigTestCase._absolute_path_kind(expected_user_db_file) | ||
self.assertEqual(path_kind, 'file') | ||
|
||
|
||
if __name__ == '__main__': | ||
testmain() |