예제 #1
0
파일: run.py 프로젝트: giang816/peregrine
def run_with_fake_auth():
    from datamodelutils import models as md

    def get_project_ids(role='_member_', project_ids=None):
        if project_ids is None:
            project_ids = []
        if not project_ids:
            with current_app.db.session_scope():
                project_ids += [
                    '{}-{}'.format(p.programs[0].name, p.code)
                    for p in current_app.db.nodes(md.Project).all()
                ]
        return project_ids

    with patch(
            'peregrine.auth.CurrentUser.roles',
            new_callable=PropertyMock,
            return_value=roles,
    ), patch(
            'peregrine.auth.CurrentUser.logged_in',
            new_callable=PropertyMock,
            return_value=lambda: True,
    ), patch(
            'peregrine.auth.CurrentUser.get_project_ids',
            new_callable=PropertyMock,
            return_value=get_project_ids,
    ), patch(
            'peregrine.auth.verify_hmac',
            new=set_user,
    ):
        run_for_development(debug=debug, threaded=True)
예제 #2
0
파일: run.py 프로젝트: giang816/peregrine
def run_with_fake_download():
    with patch("peregrine.download.get_nodes", fake_get_nodes):
        with patch.multiple("peregrine.download",
                            key_for=fake_key_for,
                            key_for_node=fake_key_for_node,
                            urls_from_signpost=fake_urls_from_signpost):
            if os.environ.get("GDC_FAKE_AUTH"):
                run_with_fake_auth()
            else:
                run_for_development(debug=debug, threaded=True)
예제 #3
0
파일: run.py 프로젝트: jacquayj/peregrine
def run_with_fake_authz():
    """
    Mocks arborist calls.
    """
    auth_mapping = {}  # modify this to mock specific access
    with patch(
            'gen3authz.client.arborist.client.ArboristClient.auth_mapping',
            new_callable=PropertyMock,
            return_value=lambda x: auth_mapping,
    ):
        run_for_development(debug=debug, threaded=True)
예제 #4
0
def run_with_fake_auth():
    with patch(
            "peregrine.auth.CurrentUser.roles",
            new_callable=PropertyMock,
            return_value=roles,
    ), patch(
            "peregrine.auth.CurrentUser.logged_in",
            new_callable=PropertyMock,
            return_value=lambda: True,
    ), patch("peregrine.auth.verify_hmac", new=set_user):
        run_for_development(debug=debug, threaded=True)
예제 #5
0
def run_with_fake_authz():
    """
    By mocking `get_read_access_projects`, we avoid checking the
    Authorization header and access token, and avoid making arborist
    calls to fetch a list of authorized resources.
    """
    # `user_projects` contains a list of `project_id`s (in format
    # "<program.name>-<project.code>") the user has access to.
    # Update it to mock specific access:
    user_projects = []
    with patch(
            "peregrine.resources.submission.get_read_access_projects",
            return_value=user_projects,
    ):
        run_for_development(debug=debug, threaded=True)
예제 #6
0
파일: run.py 프로젝트: giang816/peregrine
    ), patch(
            'peregrine.auth.verify_hmac',
            new=set_user,
    ):
        run_for_development(debug=debug, threaded=True)


def run_with_fake_download():
    with patch("peregrine.download.get_nodes", fake_get_nodes):
        with patch.multiple("peregrine.download",
                            key_for=fake_key_for,
                            key_for_node=fake_key_for_node,
                            urls_from_signpost=fake_urls_from_signpost):
            if os.environ.get("GDC_FAKE_AUTH"):
                run_with_fake_auth()
            else:
                run_for_development(debug=debug, threaded=True)


if __name__ == '__main__':
    import pdb
    pdb.set_trace()
    debug = bool(os.environ.get('PEREGRINE_DEBUG', True))
    if os.environ.get("GDC_FAKE_DOWNLOAD") == 'True':
        run_with_fake_download()
    else:
        if os.environ.get("GDC_FAKE_AUTH") == 'True':
            run_with_fake_auth()
        else:
            run_for_development(debug=debug, threaded=True)