Skip to content

Commit 85adb30

Browse files
committed
Use assertIn helper to test for key or entry in list or dicts. More strict
checking that created vgrids are really always in vgrid map after initial force_update_vgrid_map calls to rule out issues there in relation to remaining inconsistent CI errors.
1 parent a664e9d commit 85adb30

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

tests/test_mig_shared_vgridaccess.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def test_vgrid_inherit_map_single(self):
446446
}
447447
inherited_map = vgrid_inherit_map(self.configuration, test_map)
448448
vgrid_data = inherited_map.get(VGRIDS, {})
449-
self.assertTrue(self.TEST_VGRID_NAME in vgrid_data)
449+
self.assertIn(self.TEST_VGRID_NAME, vgrid_data)
450450
settings_dict = dict(vgrid_data[self.TEST_VGRID_NAME][SETTINGS])
451451
self.assertIs(type(settings_dict), dict)
452452
self.assertEqual(settings_dict.get('hidden'), True)
@@ -478,7 +478,7 @@ def test_user_vgrid_access(self):
478478
# Start with global access to default vgrid
479479
allowed_vgrids = user_vgrid_access(self.configuration,
480480
self.TEST_USER_DN)
481-
self.assertTrue('Generic' in allowed_vgrids)
481+
self.assertIn('Generic', allowed_vgrids)
482482
self.assertTrue(len(allowed_vgrids), 1)
483483
# Create private vgrid
484484
self._provision_test_user(self, self.TEST_OWNER_DN)
@@ -514,7 +514,7 @@ def test_vgrid_map_refresh(self):
514514
# Force refresh map
515515
updated_map = force_update_vgrid_map(self.configuration)
516516
vgrids = updated_map.get(VGRIDS, {})
517-
self.assertTrue(self.TEST_VGRID_NAME in vgrids)
517+
self.assertIn(self.TEST_VGRID_NAME, vgrids)
518518
self.assertEqual(vgrids[self.TEST_VGRID_NAME]
519519
[OWNERS], [self.TEST_OWNER_DN])
520520

@@ -545,12 +545,12 @@ def test_resource_map_update(self):
545545
vgrid_data = updated_vgrid_map.get(VGRIDS, {})
546546
top_vgrid_data = vgrid_data.get(self.TEST_VGRID_NAME, {})
547547
top_vgrid_res = top_vgrid_data.get(RESOURCES, {})
548-
self.assertTrue(self.TEST_RESOURCE_ID in top_vgrid_res)
548+
self.assertIn(self.TEST_RESOURCE_ID, top_vgrid_res)
549549

550550
# Check resource map contains resource entry
551551
updated_res_map = force_update_resource_map(self.configuration)
552552
# Check resource map contains entry
553-
self.assertTrue(self.TEST_RESOURCE_ID in updated_res_map)
553+
self.assertIn(self.TEST_RESOURCE_ID, updated_res_map)
554554

555555
def test_settings_inheritance(self):
556556
"""Test inherited settings propagation through cached maps"""
@@ -638,11 +638,12 @@ def test_resource_revoked_access(self):
638638
resources=[self.TEST_RESOURCE_ID])
639639

640640
initial_vgrid_map = force_update_vgrid_map(self.configuration)
641+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
641642
# Check vgrid map contains resource entry
642643
vgrid_data = initial_vgrid_map.get(VGRIDS, {})
643644
top_vgrid_data = vgrid_data.get(self.TEST_VGRID_NAME, {})
644645
top_vgrid_res = top_vgrid_data.get(RESOURCES, {})
645-
self.assertTrue(self.TEST_RESOURCE_ID in top_vgrid_res)
646+
self.assertIn(self.TEST_RESOURCE_ID, top_vgrid_res)
646647

647648
# Check resource map contains resource entry
648649
initial_map = force_update_resource_map(self.configuration)
@@ -658,7 +659,7 @@ def test_resource_revoked_access(self):
658659
vgrid_data = updated_vgrid_map.get(VGRIDS, {})
659660
top_vgrid_data = vgrid_data.get(self.TEST_VGRID_NAME, {})
660661
top_vgrid_res = top_vgrid_data.get(RESOURCES, {})
661-
self.assertFalse(self.TEST_RESOURCE_ID in top_vgrid_res)
662+
self.assertNotIn(self.TEST_RESOURCE_ID, top_vgrid_res)
662663

663664
# Verify resource still in resource map
664665
updated_map = force_update_resource_map(self.configuration)
@@ -668,12 +669,14 @@ def test_non_recursive_inheritance(self):
668669
"""Verify non-recursive map excludes nested vgrids"""
669670
# Create parent+child vgrids
670671
parent_vgrid = 'parent'
671-
self._create_vgrid(parent_vgrid, [self.TEST_OWNER_DN])
672+
self._create_vgrid(parent_vgrid, owners=[self.TEST_OWNER_DN])
672673
child_vgrid = os.path.join(parent_vgrid, 'child')
673-
self._create_vgrid(child_vgrid, None, [self.TEST_MEMBER_DN])
674+
self._create_vgrid(child_vgrid, members=[self.TEST_MEMBER_DN])
674675

675676
# Force update to avoid auto caching and get non-recursive map
676-
vgrid_map = force_update_vgrid_map(self.configuration)
677+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
678+
self.assertIn(parent_vgrid, initial_vgrid_map.get(VGRIDS, {}))
679+
self.assertIn(child_vgrid, initial_vgrid_map.get(VGRIDS, {}))
677680
vgrid_map = get_vgrid_map(self.configuration, recursive=False)
678681
# Parent should appear
679682
self.assertIn(parent_vgrid, vgrid_map.get(VGRIDS, {}))
@@ -698,6 +701,8 @@ def test_hidden_setting_propagation(self):
698701

699702
# Verify parent remains visible in cache
700703
updated_map = force_update_vgrid_map(self.configuration)
704+
self.assertIn(parent_vgrid, updated_map.get(VGRIDS, {}))
705+
self.assertIn(child_vgrid, updated_map.get(VGRIDS, {}))
701706
parent_data = updated_map.get(VGRIDS, {}).get(parent_vgrid, {})
702707
parent_settings = dict(parent_data.get(SETTINGS, []))
703708
self.assertNotEqual(parent_settings.get('hidden'), True)
@@ -708,6 +713,7 @@ def test_default_vgrid_access(self):
708713
members=[self.TEST_MEMBER_DN])
709714

710715
initial_vgrid_map = force_update_vgrid_map(self.configuration)
716+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
711717

712718
# Even non-member should have access to default vgrid
713719
participant = check_vgrid_access(self.configuration,
@@ -716,45 +722,46 @@ def test_default_vgrid_access(self):
716722
self.assertFalse(participant)
717723
allowed_vgrids = user_vgrid_access(self.configuration,
718724
self.TEST_OUTSIDER_DN)
719-
self.assertTrue('Generic' in allowed_vgrids)
725+
self.assertIn('Generic', allowed_vgrids)
720726

721727
# Invalid vgrid should not allow any participation or access
722728
participant = check_vgrid_access(self.configuration, self.TEST_MEMBER_DN,
723729
'invalid-vgrid-name')
724730
self.assertFalse(participant)
725731
allowed_vgrids = user_vgrid_access(self.configuration,
726732
self.TEST_MEMBER_DN)
727-
self.assertFalse('invalid-vgrid-name' in allowed_vgrids)
733+
self.assertNotIn('invalid-vgrid-name', allowed_vgrids)
728734

729735
def test_general_vgrid_access(self):
730736
"""Verify general access rules for vgrids"""
731737
self._create_vgrid(self.TEST_VGRID_NAME, owners=[self.TEST_OWNER_DN],
732738
members=[self.TEST_MEMBER_DN])
733739

734740
initial_vgrid_map = force_update_vgrid_map(self.configuration)
741+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
735742

736743
# Test vgrid must allow owner and members access
737744
allowed = check_vgrid_access(self.configuration, self.TEST_OWNER_DN,
738745
self.TEST_VGRID_NAME)
739746
self.assertTrue(allowed)
740747
allowed_vgrids = user_vgrid_access(self.configuration,
741748
self.TEST_OWNER_DN)
742-
self.assertTrue(self.TEST_VGRID_NAME in allowed_vgrids)
749+
self.assertIn(self.TEST_VGRID_NAME, allowed_vgrids)
743750

744751
allowed = check_vgrid_access(self.configuration, self.TEST_MEMBER_DN,
745752
self.TEST_VGRID_NAME)
746753
self.assertTrue(allowed)
747754
allowed_vgrids = user_vgrid_access(self.configuration,
748755
self.TEST_MEMBER_DN)
749-
self.assertTrue(self.TEST_VGRID_NAME in allowed_vgrids)
756+
self.assertIn(self.TEST_VGRID_NAME, allowed_vgrids)
750757

751758
# Test vgrid must reject allow outsider access
752759
allowed = check_vgrid_access(self.configuration, self.TEST_OUTSIDER_DN,
753760
self.TEST_VGRID_NAME)
754761
self.assertFalse(allowed)
755762
allowed_vgrids = user_vgrid_access(self.configuration,
756763
self.TEST_OUTSIDER_DN)
757-
self.assertFalse(self.TEST_VGRID_NAME in allowed_vgrids)
764+
self.assertNotIn(self.TEST_VGRID_NAME, allowed_vgrids)
758765

759766
def test_user_allowed_res_confs(self):
760767
"""Minimal test for user_allowed_res_confs"""
@@ -763,7 +770,8 @@ def test_user_allowed_res_confs(self):
763770
self._create_resource(self.TEST_RESOURCE_ID, [self.TEST_OWNER_DN])
764771
self._create_vgrid(self.TEST_VGRID_NAME, owners=[self.TEST_OWNER_DN],
765772
resources=[self.TEST_RESOURCE_ID])
766-
force_update_vgrid_map(self.configuration)
773+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
774+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
767775
force_update_resource_map(self.configuration)
768776
# Owner should be allowed access
769777
allowed = user_allowed_res_confs(self.configuration,
@@ -851,12 +859,13 @@ def test_access_nonexistent_vgrid(self):
851859
# Should not appear in allowed vgrids
852860
allowed_vgrids = user_vgrid_access(
853861
self.configuration, self.TEST_MEMBER_DN)
854-
self.assertFalse('no-such-vgrid' in allowed_vgrids)
862+
self.assertNotIn('no-such-vgrid', allowed_vgrids)
855863

856864
def test_empty_member_access(self):
857865
"""Verify members-only vgrid rejects outsiders"""
858866
self._create_vgrid(self.TEST_VGRID_NAME, [], [self.TEST_MEMBER_DN])
859-
force_update_vgrid_map(self.configuration)
867+
initial_vgrid_map = force_update_vgrid_map(self.configuration)
868+
self.assertIn(self.TEST_VGRID_NAME, initial_vgrid_map.get(VGRIDS, {}))
860869

861870
# Outsider should be blocked despite no owners
862871
allowed = check_vgrid_access(self.configuration, self.TEST_OUTSIDER_DN,

0 commit comments

Comments
 (0)