Skip to content

Commit 752fab6

Browse files
committed
Add better coverage of fundamental function use and clean up some unnecessary
clean function arguments.
1 parent 8f1f1de commit 752fab6

File tree

1 file changed

+136
-23
lines changed

1 file changed

+136
-23
lines changed

tests/test_mig_shared_vgridaccess.py

Lines changed: 136 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
USERID, VGRIDS, check_vgrid_access, check_vgrids_modified, \
3737
force_update_resource_map, force_update_user_map, force_update_vgrid_map, \
3838
get_re_provider_map, get_resource_map, get_user_map, get_vgrid_map, \
39-
load_resource_map, refresh_vgrid_map, resources_using_re, unmap_vgrid, \
40-
user_vgrid_access, vgrid_inherit_map
39+
load_resource_map, mark_vgrid_modified, refresh_resource_map, \
40+
refresh_user_map, refresh_vgrid_map, res_vgrid_access, \
41+
reset_vgrids_modified, resources_using_re, unmap_vgrid, user_vgrid_access, \
42+
vgrid_inherit_map
4143
from tests.support import MigTestCase, ensure_dirs_exist, testmain
4244

4345

@@ -111,7 +113,6 @@ def _create_resource(self, res_name, owners, config=None):
111113

112114
def before_each(self):
113115
"""Create test environment for vgridaccess tests"""
114-
self._provision_test_user(self, self.TEST_OWNER_DN)
115116
ensure_dirs_exist(self.configuration.mig_system_files)
116117
ensure_dirs_exist(self.configuration.mig_system_run)
117118
ensure_dirs_exist(self.configuration.user_home)
@@ -125,6 +126,128 @@ def before_each(self):
125126

126127
self.test_vgrid = 'testvgrid'
127128

129+
def test_force_update_user_map(self):
130+
"""Simple test that user map refresh completes"""
131+
user_map_before = get_user_map(self.configuration)
132+
self.assertFalse(user_map_before)
133+
self._provision_test_user(self, self.TEST_USER_DN)
134+
updated_users = force_update_user_map(self.configuration)
135+
self.assertTrue(updated_users)
136+
self.assertNotEqual(user_map_before, updated_users)
137+
138+
def test_force_update_resource_map(self):
139+
"""Simple test that resource map refresh completes"""
140+
res_map_before = get_resource_map(self.configuration)
141+
self.assertFalse(res_map_before)
142+
self._create_resource(self.TEST_RESOURCE_ID, [self.TEST_OWNER_DN])
143+
updated_res = force_update_resource_map(self.configuration)
144+
self.assertTrue(updated_res)
145+
self.assertNotEqual(len(res_map_before), len(updated_res))
146+
147+
def test_force_update_vgrid_map(self):
148+
"""Simple test that vgrid map refresh completes"""
149+
# Only (implicit) default vgrid in vgrid map before init
150+
vgrid_map_before = get_vgrid_map(self.configuration)
151+
self.assertEqual(len(vgrid_map_before.get(VGRIDS, [])), 1)
152+
self._create_vgrid(self.test_vgrid, [self.TEST_OWNER_DN])
153+
updated_vgrid = force_update_vgrid_map(self.configuration)
154+
self.assertTrue(updated_vgrid)
155+
self.assertNotEqual(len(vgrid_map_before.get(VGRIDS, [])),
156+
len(updated_vgrid.get(VGRIDS, [])))
157+
158+
def test_refresh_user_map(self):
159+
"""Minimal test for user map refresh functionality"""
160+
self._provision_test_user(self, self.TEST_USER_DN)
161+
user_map = refresh_user_map(self.configuration)
162+
self.assertTrue(user_map)
163+
self.assertIn(self.TEST_USER_DN, user_map)
164+
165+
def test_refresh_resource_map(self):
166+
"""Minimal test for resource map refresh functionality"""
167+
self._create_resource(self.TEST_RESOURCE_ID, [self.TEST_OWNER_DN])
168+
res_map = refresh_resource_map(self.configuration)
169+
self.assertTrue(res_map)
170+
self.assertIn(self.TEST_RESOURCE_ID, res_map)
171+
172+
def test_refresh_vgrid_map(self):
173+
"""Minimal test for vgrid map refresh functionality"""
174+
self._create_vgrid(self.test_vgrid, [self.TEST_OWNER_DN])
175+
vgrid_map = refresh_vgrid_map(self.configuration)
176+
self.assertTrue(vgrid_map)
177+
self.assertIn(self.test_vgrid, vgrid_map.get(VGRIDS, []))
178+
179+
def test_get_user_map(self):
180+
"""Minimal test for user map refresh functionality"""
181+
self._provision_test_user(self, self.TEST_USER_DN)
182+
force_update_user_map(self.configuration)
183+
user_map = get_user_map(self.configuration)
184+
self.assertTrue(user_map)
185+
self.assertIn(self.TEST_USER_DN, user_map)
186+
187+
def test_get_resource_map(self):
188+
"""Minimal test for user map refresh functionality"""
189+
self._create_resource(self.TEST_RESOURCE_ID, [self.TEST_OWNER_DN])
190+
force_update_resource_map(self.configuration)
191+
resource_map = get_resource_map(self.configuration)
192+
self.assertTrue(resource_map)
193+
self.assertIn(self.TEST_RESOURCE_ID, resource_map)
194+
195+
def test_get_vgrid_map(self):
196+
"""Minimal test for user map refresh functionality"""
197+
self._create_vgrid(self.test_vgrid, [self.TEST_OWNER_DN])
198+
force_update_vgrid_map(self.configuration)
199+
vgrid_map = get_vgrid_map(self.configuration)
200+
self.assertTrue(vgrid_map)
201+
self.assertIn(self.test_vgrid, vgrid_map.get(VGRIDS, []))
202+
203+
def test_check_vgrids_modified(self):
204+
"""Minimal test for vgrid modified tracking"""
205+
# Initially ALL marked modified until cache init
206+
modified, stamp = check_vgrids_modified(self.configuration)
207+
self.assertEqual(modified, ['ALL'])
208+
# Reset and check ALL gone
209+
reset_vgrids_modified(self.configuration)
210+
modified, stamp = check_vgrids_modified(self.configuration)
211+
self.assertEqual(modified, [])
212+
# Mark modified
213+
mark_vgrid_modified(self.configuration, self.test_vgrid)
214+
modified, stamp = check_vgrids_modified(self.configuration)
215+
self.assertIn(self.test_vgrid, modified)
216+
# Reset and check gone again
217+
reset_vgrids_modified(self.configuration)
218+
modified, stamp = check_vgrids_modified(self.configuration)
219+
self.assertNotIn(self.test_vgrid, modified)
220+
221+
def test_user_vgrid_access(self):
222+
"""Minimal test for user vgrid participation"""
223+
# Start with global access to default vgrid
224+
allowed_vgrids = user_vgrid_access(self.configuration,
225+
self.TEST_USER_DN)
226+
self.assertTrue('Generic' in allowed_vgrids)
227+
self.assertTrue(len(allowed_vgrids), 1)
228+
# Create private vgrid
229+
self._provision_test_user(self, self.TEST_OWNER_DN)
230+
self._create_vgrid(self.test_vgrid, [self.TEST_OWNER_DN])
231+
# Refresh maps to reflect new content
232+
force_update_vgrid_map(self.configuration)
233+
allowed_vgrids = user_vgrid_access(self.configuration,
234+
self.TEST_OWNER_DN)
235+
self.assertIn(self.test_vgrid, allowed_vgrids)
236+
237+
def test_res_vgrid_access(self):
238+
"""Minimal test for resource vgrid participation"""
239+
# Only Generic access initially
240+
allowed_vgrids = res_vgrid_access(
241+
self.configuration, self.TEST_RESOURCE_ID)
242+
self.assertEqual(allowed_vgrids, ['Generic'])
243+
# Add to vgrid
244+
self._create_resource(self.TEST_RESOURCE_ID, [self.TEST_OWNER_DN])
245+
self._create_vgrid(self.test_vgrid, resources=[self.TEST_RESOURCE_ID])
246+
# Refresh maps to reflect new content
247+
force_update_vgrid_map(self.configuration)
248+
allowed = res_vgrid_access(self.configuration, self.TEST_RESOURCE_ID)
249+
self.assertIn(self.test_vgrid, allowed)
250+
128251
def test_vgrid_map_refresh(self):
129252
"""Verify vgrid map refresh captures changes"""
130253
# We always init empty maps
@@ -162,17 +285,15 @@ def test_resource_map_update(self):
162285
self._create_resource(self.TEST_RESOURCE_ID, [self.TEST_OWNER_DN])
163286
self._create_vgrid(self.test_vgrid, owners=[self.TEST_OWNER_DN],
164287
resources=[self.TEST_RESOURCE_ID])
165-
updated_vgrid_map = force_update_vgrid_map(self.configuration,
166-
clean=True)
288+
updated_vgrid_map = force_update_vgrid_map(self.configuration)
167289
# Check vgrid map contains resource entry
168290
vgrid_data = updated_vgrid_map.get(VGRIDS, {})
169291
top_vgrid_data = vgrid_data.get(self.test_vgrid, {})
170292
top_vgrid_res = top_vgrid_data.get(RESOURCES, [])
171293
self.assertTrue(self.TEST_RESOURCE_ID in top_vgrid_res)
172294

173295
# Check resource map contains resource entry
174-
updated_res_map = force_update_resource_map(self.configuration,
175-
clean=True)
296+
updated_res_map = force_update_resource_map(self.configuration)
176297
# Check resource map contains entry
177298
self.assertTrue(self.TEST_RESOURCE_ID in updated_res_map)
178299

@@ -229,8 +350,7 @@ def test_user_map_fields(self):
229350
self._provision_test_user(self, self.TEST_OWNER_DN)
230351
self._provision_test_user(self, self.TEST_USER_DN)
231352
# Force fresh user map
232-
initial_vgrid_map = force_update_vgrid_map(self.configuration,
233-
clean=True)
353+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
234354
user_map = force_update_user_map(self.configuration)
235355
test_owner = user_map.get(self.TEST_OWNER_DN, {})
236356
self.assertEqual(test_owner.get(USERID), self.TEST_OWNER_UUID)
@@ -246,35 +366,31 @@ def test_resource_revoked_access(self):
246366
self._create_vgrid(self.test_vgrid, owners=[self.TEST_OWNER_DN],
247367
resources=[self.TEST_RESOURCE_ID])
248368

249-
initial_vgrid_map = force_update_vgrid_map(self.configuration,
250-
clean=True)
369+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
251370
# Check vgrid map contains resource entry
252371
vgrid_data = initial_vgrid_map.get(VGRIDS, {})
253372
top_vgrid_data = vgrid_data.get(self.test_vgrid, {})
254373
top_vgrid_res = top_vgrid_data.get(RESOURCES, [])
255374
self.assertTrue(self.TEST_RESOURCE_ID in top_vgrid_res)
256375

257376
# Check resource map contains resource entry
258-
initial_map = force_update_resource_map(self.configuration,
259-
clean=True)
377+
initial_map = force_update_resource_map(self.configuration)
260378
self.assertIn(self.TEST_RESOURCE_ID, initial_map)
261379

262380
# Remove resource assignment from vgrid
263381
status, msg = vgrid_set_entities(self.configuration, self.test_vgrid,
264382
'resources', [], allow_empty=True)
265383
self.assertTrue(status, msg)
266384

267-
updated_vgrid_map = force_update_vgrid_map(self.configuration,
268-
clean=True)
385+
updated_vgrid_map = force_update_vgrid_map(self.configuration)
269386
# Check vgrid map no longer contains resource entry
270387
vgrid_data = updated_vgrid_map.get(VGRIDS, {})
271388
top_vgrid_data = vgrid_data.get(self.test_vgrid, {})
272389
top_vgrid_res = top_vgrid_data.get(RESOURCES, [])
273390
self.assertFalse(self.TEST_RESOURCE_ID in top_vgrid_res)
274391

275392
# Verify resource still in resource map
276-
updated_map = force_update_resource_map(self.configuration,
277-
clean=True)
393+
updated_map = force_update_resource_map(self.configuration)
278394
self.assertIn(self.TEST_RESOURCE_ID, updated_map)
279395

280396
def test_non_recursive_inheritance(self):
@@ -286,8 +402,7 @@ def test_non_recursive_inheritance(self):
286402
self._create_vgrid(child_vgrid, None, [self.TEST_MEMBER_DN])
287403

288404
# Force update to avoid auto caching and get non-recursive map
289-
vgrid_map = force_update_vgrid_map(self.configuration,
290-
clean=True)
405+
vgrid_map = force_update_vgrid_map(self.configuration)
291406
vgrid_map = get_vgrid_map(self.configuration, recursive=False)
292407
# Parent should appear
293408
self.assertIn(parent_vgrid, vgrid_map.get(VGRIDS, {}))
@@ -321,8 +436,7 @@ def test_default_vgrid_access(self):
321436
self._create_vgrid(self.test_vgrid, owners=[self.TEST_OWNER_DN],
322437
members=[self.TEST_MEMBER_DN])
323438

324-
initial_vgrid_map = force_update_vgrid_map(self.configuration,
325-
clean=True)
439+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
326440

327441
# Even non-member should have access to default vgrid
328442
participant = check_vgrid_access(self.configuration,
@@ -346,8 +460,7 @@ def test_general_vgrid_access(self):
346460
self._create_vgrid(self.test_vgrid, owners=[self.TEST_OWNER_DN],
347461
members=[self.TEST_MEMBER_DN])
348462

349-
initial_vgrid_map = force_update_vgrid_map(self.configuration,
350-
clean=True)
463+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
351464

352465
# Test vgrid must allow owner and members access
353466
allowed = check_vgrid_access(self.configuration, self.TEST_OWNER_DN,

0 commit comments

Comments
 (0)