diff --git a/tests/support/usersupp.py b/tests/support/usersupp.py index 65a02fa4a..7a8a8eb98 100644 --- a/tests/support/usersupp.py +++ b/tests/support/usersupp.py @@ -38,6 +38,8 @@ TEST_USER_DN = '/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=test@example.com' +OTHER_USER_DN = '/C=DK/ST=NA/L=NA/O=Other Org/OU=NA/CN=Other User/emailAddress=other@example.com' +NO_SUCH_USER_DN = '/C=DK/ST=NA/L=NA/O=No Such Org/OU=NA/CN=No Such User/emailAddress=nosuchuser@example.com' _FIXTURE_NAME_BY_USER_DN = { TEST_USER_DN: 'MiG-users.db--example' @@ -79,19 +81,21 @@ def _provision_test_user(testcase, distinguished_name): try: fixture_relpath = _FIXTURE_NAME_BY_USER_DN[distinguished_name] except KeyError: - raise AssertionError('supplied test user is not known as a fixture') + raise AssertionError( + 'supplied test user is not known as a fixture') # note: this is a non-standard direct use of fixture preparation due # to this being bootstrap code and should not be used elsewhere - prepared_fixture = _PreparedFixture.from_relpath( - testcase, - fixture_relpath, - fixture_format='json' - ) + prepared_fixture = _PreparedFixture.from_relpath(testcase, + fixture_relpath, + fixture_format='json' + ) # write out the user database fixture containing the user - prepared_fixture.write_to_dir(conf_user_db_home, output_format='pickle') + prepared_fixture.write_to_dir(conf_user_db_home, + output_format='pickle') - test_user_dir = UserAssertMixin._provision_test_user_dirs(testcase, distinguished_name) + test_user_dir = UserAssertMixin._provision_test_user_dirs( + testcase, distinguished_name) return test_user_dir @@ -103,6 +107,7 @@ def _provision_test_user_dirs(testcase, distinguished_name): self = testcase + # NOTE: we basically need all the dirs in _USERADM_PATH_KEYS list. conf_user_home = os.path.normpath(self.configuration.user_home) test_client_dir_name = client_id_dir(distinguished_name) @@ -112,14 +117,26 @@ def _provision_test_user_dirs(testcase, distinguished_name): # create the test user settings directory conf_user_settings = os.path.normpath(self.configuration.user_settings) - test_user_settings_dir = os.path.join(conf_user_settings, test_client_dir_name) + test_user_settings_dir = os.path.join(conf_user_settings, + test_client_dir_name) os.makedirs(test_user_settings_dir) # create an empty user settings file - test_user_settings_file = os.path.join(test_user_settings_dir, 'settings') + test_user_settings_file = os.path.join(test_user_settings_dir, + 'settings') with open(test_user_settings_file, 'wb') as outfile: pickle.dump({}, outfile) + # TODO: clean up old _ensure_dirs_exist calls in tests to create these. + # create the test user cache, resource pending and mrsl files sub dirs + for sub in (self.configuration.user_cache, + self.configuration.resource_pending, + self.configuration.mrsl_files_dir): + conf_user_sub = os.path.normpath(sub) + test_user_sub_dir = os.path.join(conf_user_sub, + test_client_dir_name) + os.makedirs(test_user_sub_dir) + return test_user_dir @staticmethod @@ -134,8 +151,8 @@ def _provision_test_users(testcase, *distinguished_names): that the user db will be populated from arbitrary data and thus the test dependent upon this is less strongly assured, but if (as is the expectation) the basic operations are validated with - "indenpdent" data i.e. conained within fixtures as opposed to - generated by logic that extended tests which need + "independent" data i.e. contained within fixtures as opposed to + generated by logic that extended tests will need. """ conf_user_db_home = UserAssertMixin._provision_user_db_dir(testcase) @@ -156,7 +173,9 @@ def _provision_test_users(testcase, *distinguished_names): # suitably hinted so a production format pickle file ends up on-disk prepared_fixture = _PreparedFixture(testcase, 'MiG-users.db--example') prepared_fixture.fixture_data = users_by_dn - prepared_fixture.write_to_dir(conf_user_db_home, output_format='pickle') + prepared_fixture.write_to_dir(conf_user_db_home, + output_format='pickle') for distinguished_name in distinguished_names: - UserAssertMixin._provision_test_user_dirs(testcase, distinguished_name) + UserAssertMixin._provision_test_user_dirs(testcase, + distinguished_name)