|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# --- BEGIN_HEADER --- |
| 4 | +# |
| 5 | +# test_mig_server-createuser - unit tests for the migrid createuser CLI |
| 6 | +# Copyright (C) 2003-2024 The MiG Project by the Science HPC Center at UCPH |
| 7 | +# |
| 8 | +# This file is part of MiG. |
| 9 | +# |
| 10 | +# MiG is free software: you can redistribute it and/or modify |
| 11 | +# it under the terms of the GNU General Public License as published by |
| 12 | +# the Free Software Foundation; either version 2 of the License, or |
| 13 | +# (at your option) any later version. |
| 14 | +# |
| 15 | +# MiG is distributed in the hope that it will be useful, |
| 16 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | +# GNU General Public License for more details. |
| 19 | +# |
| 20 | +# You should have received a copy of the GNU General Public License |
| 21 | +# along with this program; if not, write to the Free Software |
| 22 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 23 | +# USA. |
| 24 | +# |
| 25 | +# --- END_HEADER --- |
| 26 | +# |
| 27 | + |
| 28 | +"""Unit tests for the migrid createuser CLI""" |
| 29 | + |
| 30 | +from __future__ import print_function |
| 31 | +import os |
| 32 | +import sys |
| 33 | + |
| 34 | +from tests.support import MIG_BASE, TEST_OUTPUT_DIR, MigTestCase, testmain |
| 35 | + |
| 36 | +from mig.server.createuser import main as createuser |
| 37 | + |
| 38 | +class TestBooleans(MigTestCase): |
| 39 | + def before_each(self): |
| 40 | + configuration = self.configuration |
| 41 | + test_user_db_home = os.path.join(configuration.state_path, 'user_db_home') |
| 42 | + try: |
| 43 | + os.rmdir(test_user_db_home) |
| 44 | + except: |
| 45 | + pass |
| 46 | + self.expected_user_db_home = test_user_db_home |
| 47 | + |
| 48 | + def _provide_configuration(self): |
| 49 | + return 'testconfig' |
| 50 | + |
| 51 | + def test_user_db_is_created_and_user_is_added(self): |
| 52 | + args = [ |
| 53 | + "-r", |
| 54 | + "Test User", |
| 55 | + "Test Org", |
| 56 | + "NA", |
| 57 | + "DK", |
| 58 | + "dummy-user", |
| 59 | + "This is the create comment", |
| 60 | + "password" |
| 61 | + ] |
| 62 | + createuser(args, TEST_OUTPUT_DIR, configuration=self.configuration) |
| 63 | + |
| 64 | + # presence of user home |
| 65 | + path_kind = MigTestCase._absolute_path_kind(self.expected_user_db_home) |
| 66 | + self.assertEqual(path_kind, 'dir') |
| 67 | + |
| 68 | + # presence of user db |
| 69 | + expected_user_db_file = os.path.join(self.expected_user_db_home, 'MiG-users.db') |
| 70 | + path_kind = MigTestCase._absolute_path_kind(expected_user_db_file) |
| 71 | + self.assertEqual(path_kind, 'file') |
| 72 | + |
| 73 | + |
| 74 | +if __name__ == '__main__': |
| 75 | + testmain() |
0 commit comments