Fix assert logic in test_list_security_groups_list_all_tenants_filter

In test_list_security_groups_list_all_tenants_filter, when testing
"Fetch all security groups for non-admin user", the following check
is not correct, it can't check "all created Security Groups are
present in fetched list", but can only check that "no other user's
Security Groups can be retrieved by non-admin user."
This is to fix the check statements.

Change-Id: I4781a3450385a66df53c437791ac6b107d8efe7e
This commit is contained in:
zhufl
2018-10-19 11:26:21 +08:00
parent e1b2e0d4d6
commit b9b4f4f8c7

View File

@@ -73,8 +73,17 @@ class SecurityGroupsTestAdminJSON(base.BaseV2ComputeAdminTest):
# search filter # search filter
fetched_list = (self.client.list_security_groups(all_tenants='true') fetched_list = (self.client.list_security_groups(all_tenants='true')
['security_groups']) ['security_groups'])
# Now check if all created Security Groups are present in fetched list sec_group_id_list = [sg['id'] for sg in fetched_list]
for sec_group in fetched_list: # Now check that 'all_tenants='true' filter for non-admin user only
self.assertEqual(sec_group['tenant_id'], client_tenant_id, # provide the requested non-admin user's created security groups,
"Failed to get all security groups for " # not all security groups which include security groups created by
"non admin user.") # other users.
for sec_group in security_group_list:
if sec_group['tenant_id'] == client_tenant_id:
self.assertIn(sec_group['id'], sec_group_id_list,
"Failed to get all security groups for "
"non admin user.")
else:
self.assertNotIn(sec_group['id'], sec_group_id_list,
"Non admin user shouldn't get other user's "
"security groups.")