Skip to content

Commit bc931aa

Browse files
authored
Add a few more user state dirs made by actual user creation in provision user helper (#563)
* Add a few more user state dirs made by actual user creation and importantly expected e.g. during useradm operations like edit_user, delete_user, etc. and therefore difficult to do without when adding test coverage a.o. in #561. Introduce two more common DNs used across tests: Other User and No Such User. Polish a long comment with some typos and incomplete ending. * Add a couple of good points from review feedback (thanks @albu-diku) as comments to get the PR wrapped up. Minor format-only changes from automatic long-line wrap in editor.
1 parent 359827f commit bc931aa

1 file changed

Lines changed: 33 additions & 14 deletions

File tree

tests/support/usersupp.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939

4040
TEST_USER_DN = '/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=test@example.com'
41+
OTHER_USER_DN = '/C=DK/ST=NA/L=NA/O=Other Org/OU=NA/CN=Other User/emailAddress=other@example.com'
42+
NO_SUCH_USER_DN = '/C=DK/ST=NA/L=NA/O=No Such Org/OU=NA/CN=No Such User/emailAddress=nosuchuser@example.com'
4143

4244
_FIXTURE_NAME_BY_USER_DN = {
4345
TEST_USER_DN: 'MiG-users.db--example'
@@ -79,19 +81,21 @@ def _provision_test_user(testcase, distinguished_name):
7981
try:
8082
fixture_relpath = _FIXTURE_NAME_BY_USER_DN[distinguished_name]
8183
except KeyError:
82-
raise AssertionError('supplied test user is not known as a fixture')
84+
raise AssertionError(
85+
'supplied test user is not known as a fixture')
8386

8487
# note: this is a non-standard direct use of fixture preparation due
8588
# to this being bootstrap code and should not be used elsewhere
86-
prepared_fixture = _PreparedFixture.from_relpath(
87-
testcase,
88-
fixture_relpath,
89-
fixture_format='json'
90-
)
89+
prepared_fixture = _PreparedFixture.from_relpath(testcase,
90+
fixture_relpath,
91+
fixture_format='json'
92+
)
9193
# write out the user database fixture containing the user
92-
prepared_fixture.write_to_dir(conf_user_db_home, output_format='pickle')
94+
prepared_fixture.write_to_dir(conf_user_db_home,
95+
output_format='pickle')
9396

94-
test_user_dir = UserAssertMixin._provision_test_user_dirs(testcase, distinguished_name)
97+
test_user_dir = UserAssertMixin._provision_test_user_dirs(
98+
testcase, distinguished_name)
9599

96100
return test_user_dir
97101

@@ -103,6 +107,7 @@ def _provision_test_user_dirs(testcase, distinguished_name):
103107

104108
self = testcase
105109

110+
# NOTE: we basically need all the dirs in _USERADM_PATH_KEYS list.
106111
conf_user_home = os.path.normpath(self.configuration.user_home)
107112
test_client_dir_name = client_id_dir(distinguished_name)
108113

@@ -112,14 +117,26 @@ def _provision_test_user_dirs(testcase, distinguished_name):
112117

113118
# create the test user settings directory
114119
conf_user_settings = os.path.normpath(self.configuration.user_settings)
115-
test_user_settings_dir = os.path.join(conf_user_settings, test_client_dir_name)
120+
test_user_settings_dir = os.path.join(conf_user_settings,
121+
test_client_dir_name)
116122
os.makedirs(test_user_settings_dir)
117123

118124
# create an empty user settings file
119-
test_user_settings_file = os.path.join(test_user_settings_dir, 'settings')
125+
test_user_settings_file = os.path.join(test_user_settings_dir,
126+
'settings')
120127
with open(test_user_settings_file, 'wb') as outfile:
121128
pickle.dump({}, outfile)
122129

130+
# TODO: clean up old _ensure_dirs_exist calls in tests to create these.
131+
# create the test user cache, resource pending and mrsl files sub dirs
132+
for sub in (self.configuration.user_cache,
133+
self.configuration.resource_pending,
134+
self.configuration.mrsl_files_dir):
135+
conf_user_sub = os.path.normpath(sub)
136+
test_user_sub_dir = os.path.join(conf_user_sub,
137+
test_client_dir_name)
138+
os.makedirs(test_user_sub_dir)
139+
123140
return test_user_dir
124141

125142
@staticmethod
@@ -134,8 +151,8 @@ def _provision_test_users(testcase, *distinguished_names):
134151
that the user db will be populated from arbitrary data and thus
135152
the test dependent upon this is less strongly assured, but if
136153
(as is the expectation) the basic operations are validated with
137-
"indenpdent" data i.e. conained within fixtures as opposed to
138-
generated by logic that extended tests which need
154+
"independent" data i.e. contained within fixtures as opposed to
155+
generated by logic that extended tests will need.
139156
"""
140157

141158
conf_user_db_home = UserAssertMixin._provision_user_db_dir(testcase)
@@ -156,7 +173,9 @@ def _provision_test_users(testcase, *distinguished_names):
156173
# suitably hinted so a production format pickle file ends up on-disk
157174
prepared_fixture = _PreparedFixture(testcase, 'MiG-users.db--example')
158175
prepared_fixture.fixture_data = users_by_dn
159-
prepared_fixture.write_to_dir(conf_user_db_home, output_format='pickle')
176+
prepared_fixture.write_to_dir(conf_user_db_home,
177+
output_format='pickle')
160178

161179
for distinguished_name in distinguished_names:
162-
UserAssertMixin._provision_test_user_dirs(testcase, distinguished_name)
180+
UserAssertMixin._provision_test_user_dirs(testcase,
181+
distinguished_name)

0 commit comments

Comments
 (0)