Skip to content

Commit

Permalink
Use one less test publications
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Jan 2, 2024
1 parent 6b70356 commit bbc3a88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
3 changes: 2 additions & 1 deletion test_tools/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def oauth2_provider_mock():
'test_adjust_db_for_roles_ws2': None,
'test_access_rights_role_user1': None,
'test_access_rights_application_owner': None,
'test_access_rights_application_reader': None,
'test_access_rights_application_reader_user': None,
'test_access_rights_application_reader_role': None,
'test_access_rights_application_other_user': None,
'test_patch_after_feature_change_role_user': None,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,32 +168,27 @@ def generate_geoserver_negative_test_cases(publications_user_can_read, publicati
@pytest.mark.usefixtures('ensure_layman_module', 'oauth2_provider_mock')
class TestAccessRights:
OWNER = 'test_access_rights_application_owner'
READER = 'test_access_rights_application_reader'
READER_USER = 'test_access_rights_application_reader_user'
READER_ROLE = 'test_access_rights_application_reader_role'
OTHER_USER = 'test_access_rights_application_other_user'
ROLE = 'TEST_ACCESS_RIGHTS_APPLICATION_ROLE'
OTHER_ROLE = 'TEST_ACCESS_RIGHTS_APPLICATION_OTHER_ROLE'
NON_EXISTING_ROLE = 'TEST_ACCESS_RIGHTS_NON_EXISTING_ROLE'

LAYER_NO_ACCESS = Publication(OWNER, process_client.LAYER_TYPE, 'test_no_access_layer')
LAYER_USER_ACCESS = Publication(OWNER, process_client.LAYER_TYPE, 'test_user_access_layer')
LAYER_ROLE_ACCESS = Publication(OWNER, process_client.LAYER_TYPE, 'test_role_access_layer')
LAYER_ACCESS_RIGHTS = Publication(OWNER, process_client.LAYER_TYPE, 'test_access_rights_layer')
LAYER_EVERYONE_ACCESS = Publication(OWNER, process_client.LAYER_TYPE, 'test_everyone_access_layer')
MAP_NO_ACCESS = Publication(OWNER, process_client.MAP_TYPE, 'test_no_access_map')
MAP_USER_ACCESS = Publication(OWNER, process_client.MAP_TYPE, 'test_user_access_map')
MAP_ROLE_ACCESS = Publication(OWNER, process_client.MAP_TYPE, 'test_role_access_map')
MAP_ACCESS_RIGHTS = Publication(OWNER, process_client.MAP_TYPE, 'test_access_rights_map')
MAP_EVERYONE_ACCESS = Publication(OWNER, process_client.MAP_TYPE, 'test_everyone_access_map')

ACCESS_RIGHT_NO_ACCESS = {
'read': OWNER,
'write': OWNER,
}
ACCESS_RIGHTS_USER_ACCESS = {
'read': f'{OWNER}, {READER}',
'write': f'{OWNER}, {READER}',
}
ACCESS_RIGHTS_ROLE_ACCESS = {
'read': f'{OWNER}, {ROLE}, {NON_EXISTING_ROLE}',
'write': f'{OWNER}, {ROLE}, {NON_EXISTING_ROLE}',
ACCESS_RIGHTS_ACCESS = {
'read': f'{OWNER}, {READER_USER}, {ROLE}, {NON_EXISTING_ROLE}',
'write': f'{OWNER}, {READER_USER}, {ROLE}, {NON_EXISTING_ROLE}',
}
ACCESS_RIGHTS_EVERYONE_ACCESS = {
'read': settings.RIGHTS_EVERYONE_ROLE,
Expand All @@ -203,20 +198,19 @@ class TestAccessRights:
PUBLICATIONS_DEFS = [
# Publication, posted access rights, deleter
(LAYER_NO_ACCESS, ACCESS_RIGHT_NO_ACCESS, OWNER),
(LAYER_USER_ACCESS, ACCESS_RIGHTS_USER_ACCESS, READER),
(LAYER_ROLE_ACCESS, ACCESS_RIGHTS_ROLE_ACCESS, READER),
(LAYER_ACCESS_RIGHTS, ACCESS_RIGHTS_ACCESS, READER_USER),
(LAYER_EVERYONE_ACCESS, ACCESS_RIGHTS_EVERYONE_ACCESS, OTHER_USER),
(MAP_NO_ACCESS, ACCESS_RIGHT_NO_ACCESS, OWNER),
(MAP_USER_ACCESS, ACCESS_RIGHTS_USER_ACCESS, READER),
(MAP_ROLE_ACCESS, ACCESS_RIGHTS_ROLE_ACCESS, READER),
(MAP_ACCESS_RIGHTS, ACCESS_RIGHTS_ACCESS, READER_USER),
(MAP_EVERYONE_ACCESS, ACCESS_RIGHTS_EVERYONE_ACCESS, OTHER_USER),
]

PUBLICATIONS = [publication for publication, _, _ in PUBLICATIONS_DEFS]

PUBLICATIONS_BY_USER = {
OWNER: [publication for publication, _, _ in PUBLICATIONS_DEFS],
READER: [LAYER_USER_ACCESS, LAYER_ROLE_ACCESS, LAYER_EVERYONE_ACCESS, MAP_USER_ACCESS, MAP_ROLE_ACCESS, MAP_EVERYONE_ACCESS, ],
READER_USER: [LAYER_ACCESS_RIGHTS, LAYER_EVERYONE_ACCESS, MAP_ACCESS_RIGHTS, MAP_EVERYONE_ACCESS, ],
READER_ROLE: [LAYER_ACCESS_RIGHTS, LAYER_EVERYONE_ACCESS, MAP_ACCESS_RIGHTS, MAP_EVERYONE_ACCESS, ],
OTHER_USER: [LAYER_EVERYONE_ACCESS, MAP_EVERYONE_ACCESS, ],
settings.ANONYM_USER: [LAYER_EVERYONE_ACCESS, MAP_EVERYONE_ACCESS, ],
}
Expand All @@ -231,22 +225,23 @@ class TestAccessRights:
@pytest.fixture(scope='class', autouse=True)
def class_fixture(self, request):
process_client.ensure_reserved_username(self.OWNER)
process_client.ensure_reserved_username(self.READER)
process_client.ensure_reserved_username(self.READER_USER)
process_client.ensure_reserved_username(self.READER_ROLE)
process_client.ensure_reserved_username(self.OTHER_USER)
role_service_util.ensure_user_role(self.READER, self.ROLE)
role_service_util.ensure_user_role(self.READER_ROLE, self.ROLE)
role_service_util.ensure_user_role(self.OTHER_USER, self.OTHER_ROLE)
role_service_util.ensure_user_role(self.READER, self.NON_EXISTING_ROLE)
role_service_util.ensure_user_role(self.READER_ROLE, self.NON_EXISTING_ROLE)
for publication, access_rights, _ in self.PUBLICATIONS_DEFS:
process_client.publish_workspace_publication(publication.type, publication.workspace, publication.name,
actor_name=self.OWNER, access_rights=access_rights, )
role_service_util.delete_user_role(self.READER, self.NON_EXISTING_ROLE)
role_service_util.delete_user_role(self.READER_ROLE, self.NON_EXISTING_ROLE)
role_service_util.delete_role(self.NON_EXISTING_ROLE)
yield
if request.node.session.testsfailed == 0 and not request.config.option.nocleanup:
for publication, _, deleter in self.PUBLICATIONS_DEFS:
process_client.delete_workspace_publication(publication.type, publication.workspace, publication.name,
actor_name=deleter, )
role_service_util.delete_user_role(self.READER, self.ROLE)
role_service_util.delete_user_role(self.READER_ROLE, self.ROLE)
role_service_util.delete_role(self.ROLE)
role_service_util.delete_user_role(self.OTHER_USER, self.OTHER_ROLE)
role_service_util.delete_role(self.OTHER_ROLE)
Expand Down

0 comments on commit bbc3a88

Please sign in to comment.