def test_delete_publications(self, publ_type):
        def check_delete(headers, after_delete_publications,
                         remaining_publications):
            delete_json = process_client.delete_workspace_publications(
                publ_type, owner, headers=headers)
            publication_set = {
                publication['name']
                for publication in delete_json
            }
            assert after_delete_publications == publication_set

            get_json = process_client.get_workspace_publications(
                publ_type, workspace=owner, headers=authn_headers_owner)
            publication_set = {publication['name'] for publication in get_json}
            assert remaining_publications == publication_set

        owner = self.owner
        authn_headers_owner = self.authn_headers_owner
        authn_headers_deleter = self.authn_headers_deleter

        publication_a = 'test_delete_publications_publication_a'
        publication_b = 'test_delete_publications_publication_b'
        publications = [
            (publication_a, {
                'read': 'EVERYONE',
                'write': owner
            }),
            (publication_b, {
                'read': 'EVERYONE',
                'write': 'EVERYONE'
            }),
        ]

        for (name, access_rights) in publications:
            process_client.publish_workspace_publication(
                publ_type,
                owner,
                name,
                access_rights=access_rights,
                headers=authn_headers_owner)

        response = process_client.get_workspace_publications(
            publ_type, workspace=owner, headers=authn_headers_owner)
        assert len(response) == len(publications)

        # Delete by other user with rights only for one layer
        check_delete(authn_headers_deleter, {
            publication_b,
        }, {
            publication_a,
        })

        # Delete by owner, everything is deleted
        check_delete(authn_headers_owner, {
            publication_a,
        }, set())
Example #2
0
def same_title_in_source_and_rest_multi(workspace, publ_type, name, headers):
    with app.app_context():
        publ_info = layman_util.get_publication_info(
            workspace, publ_type, name, context={'keys': ['title']})
    title = publ_info['title']
    infos = process_client.get_workspace_publications(publ_type,
                                                      workspace,
                                                      headers=headers)

    publication_infos = [info for info in infos if info['name'] == name]
    info = next(iter(publication_infos))
    assert info['title'] == title, f'publication_infos={publication_infos}'
        def check_delete(headers, after_delete_publications,
                         remaining_publications):
            delete_json = process_client.delete_workspace_publications(
                publ_type, owner, headers=headers)
            publication_set = {
                publication['name']
                for publication in delete_json
            }
            assert after_delete_publications == publication_set

            get_json = process_client.get_workspace_publications(
                publ_type, workspace=owner, headers=authn_headers_owner)
            publication_set = {publication['name'] for publication in get_json}
            assert remaining_publications == publication_set
Example #4
0
def test_get_publication_infos():
    ensure_all_publications()

    users = data.USERS | {settings.ANONYM_USER, settings.NONAME_USER}
    # prepare expected data
    expected = dict()
    for actor in users:
        expected[actor] = dict()
        for workspace in data.WORKSPACES:
            expected[actor][workspace] = dict()
            for publ_type in process_client.PUBLICATION_TYPES:
                expected[actor][workspace][publ_type] = dict()
                for access_type in ['read', 'write']:
                    expected[actor][workspace][publ_type][access_type] = set()
    for (workspace, publ_type,
         publication), value in data.PUBLICATIONS.items():
        for access_type in ['read', 'write']:
            users_with_right = value[data.TEST_DATA].get('users_can_' +
                                                         access_type)
            users_with_right = users_with_right or users
            for actor in users_with_right:
                expected[actor][workspace][publ_type][access_type].add(
                    publication)

    for actor in users:
        headers = data.HEADERS.get(actor)

        # test internal get_publication_infos only with actor and access type
        for access_type in ['read', 'write']:
            with app.app_context():
                publications = layman_util.get_publication_infos(
                    context={
                        'actor_name': actor,
                        'access_type': access_type
                    })
                assert {publ_type
                        for _, publ_type, _ in publications.keys()
                        } == set(process_client.PUBLICATION_TYPES)
                for publ_type in process_client.PUBLICATION_TYPES:
                    for workspace in data.WORKSPACES:
                        publications_set = {
                            name
                            for ws, p_type, name in publications.keys()
                            if ws == workspace and p_type == publ_type
                        }
                        assert publications_set == expected[actor][workspace][
                            publ_type][access_type]

        for publ_type in process_client.PUBLICATION_TYPES:
            for workspace in data.WORKSPACES:
                # test internal get_publication_infos with workspace, publication type. actor and access type
                for access_type in ['read', 'write']:
                    with app.app_context():
                        publications = layman_util.get_publication_infos(
                            workspace, publ_type, {
                                'actor_name': actor,
                                'access_type': access_type
                            })
                    assert all(
                        p_workspace == workspace and p_type == publ_type
                        for p_workspace, p_type, _ in publications.keys())
                    publications_set = {
                        name
                        for _, _, name in publications.keys()
                    }
                    assert publications_set == expected[actor][workspace][
                        publ_type][access_type]

                # test authenticated GET Workspace Layers/Maps
                publications = process_client.get_workspace_publications(
                    publ_type, workspace, headers=headers)
                publication_set = {
                    publication['name']
                    for publication in publications
                }
                assert publication_set == expected[actor][workspace][
                    publ_type]['read']

            # test authenticated GET Layers/Maps
            publications = process_client.get_publications(publ_type,
                                                           headers=headers)
            for workspace in data.WORKSPACES:
                publication_set = {
                    publication['name']
                    for publication in publications
                    if publication['workspace'] == workspace
                }
                assert publication_set == expected[actor][workspace][
                    publ_type]['read']