Ejemplo n.º 1
0
def _test_permissions(
    mocker,
    client,
    usr,
    permissions,
    will_succeed,
    kwargs={},
):
    mocker.patch('app.service_api_client.get_live_services_data', return_value={'data': service})

    request.view_args.update({'service_id': 'foo'})
    if usr:
        client.login(usr)

    decorator = user_has_permissions(*permissions, **kwargs)
    decorated_index = decorator(index)

    if will_succeed:
        decorated_index()
    else:
        try:
            if (
                decorated_index().location != '/sign-in?next=%2F' or
                decorated_index().status_code != 302
            ):
                pytest.fail("Failed to throw a forbidden or unauthorised exception")
        except (Forbidden, Unauthorized):
            pass
Ejemplo n.º 2
0
def _test_permissions(
    client,
    usr,
    permissions,
    will_succeed,
    kwargs=None,
):
    request.view_args.update({'service_id': 'foo'})
    if usr:
        client.login(usr)

    decorator = user_has_permissions(*permissions, **(kwargs or {}))
    decorated_index = decorator(index)

    if will_succeed:
        decorated_index()
    else:
        try:
            if (
                decorated_index().location != '/sign-in?next=%2F' or
                decorated_index().status_code != 302
            ):
                pytest.fail("Failed to throw a forbidden or unauthorised exception")
        except (Forbidden, Unauthorized):
            pass
def _test_permissions(app_, usr, permissions, service_id, will_succeed, any_=False, admin_override=False):
    with app_.test_request_context() as ctx:
        request.view_args.update({'service_id': service_id})
        with app_.test_client() as client:
            client.login(usr)
            decorator = user_has_permissions(*permissions, any_=any_, admin_override=admin_override)
            decorated_index = decorator(index)
            if will_succeed:
                response = decorated_index()
            else:
                try:
                    response = decorated_index()
                    pytest.fail("Failed to throw a forbidden exception")
                except Forbidden:
                    pass
Ejemplo n.º 4
0
def _test_permissions(client, usr, permissions, will_succeed, kwargs={}):
    request.view_args.update({'service_id': 'foo'})
    if usr:
        client.login(usr)

    decorator = user_has_permissions(*permissions, **kwargs)
    decorated_index = decorator(index)

    if will_succeed:
        decorated_index()
    else:
        try:
            decorated_index()
            pytest.fail(
                "Failed to throw a forbidden or unauthorised exception")
        except (Forbidden, Unauthorized):
            pass
def _test_permissions(
    client,
    usr,
    permissions,
    service_id,
    will_succeed,
    any_=False,
    admin_override=False,
):
    request.view_args.update({'service_id': service_id})
    if usr:
        client.login(usr)
    decorator = user_has_permissions(*permissions, any_=any_, admin_override=admin_override)
    decorated_index = decorator(index)
    if will_succeed:
        decorated_index()
    else:
        try:
            decorated_index()
            pytest.fail("Failed to throw a forbidden or unauthorised exception")
        except (Forbidden, Unauthorized):
            pass
def _test_permissions(app_,
                      usr,
                      permissions,
                      service_id,
                      will_succeed,
                      any_=False,
                      admin_override=False):
    with app_.test_request_context() as ctx:
        request.view_args.update({'service_id': service_id})
        with app_.test_client() as client:
            client.login(usr)
            decorator = user_has_permissions(*permissions,
                                             any_=any_,
                                             admin_override=admin_override)
            decorated_index = decorator(index)
            if will_succeed:
                response = decorated_index()
            else:
                try:
                    response = decorated_index()
                    pytest.fail("Failed to throw a forbidden exception")
                except Forbidden:
                    pass