async def test_share_flow_full(
    app, full_spawn, user, share_user, create_user_with_scopes
):
    """Exercise the full process of sharing and then accessing a shared server"""
    user = create_user_with_scopes(
        "shares!user", "self", f"read:users:name!user={share_user.name}"
    )
    # start server
    await user.spawn("")
    await app.proxy.add_user(user)
    spawner = user.spawner

    # grant access
    share_url = f"shares/{user.name}/{spawner.name}"
    r = await api_request(
        app,
        share_url,
        method="post",
        name=user.name,
        data=json.dumps({"user": share_user.name}),
    )
    r.raise_for_status()
    share_model = r.json()

    # attempt to _use_ access
    user_url = public_url(app, user) + "api/contents/"
    token = share_user.new_api_token()
    r = await async_requests.get(user_url, headers={"Authorization": f"Bearer {token}"})
    r.raise_for_status()

    # revoke access
    r = await api_request(
        app,
        share_url,
        method="patch",
        name=user.name,
        data=json.dumps(
            {
                "scopes": share_model["scopes"],
                "user": share_user.name,
            }
        ),
    )
    r.raise_for_status()
    # new request with new token to avoid cache
    token = share_user.new_api_token()
    r = await async_requests.get(user_url, headers={"Authorization": f"Bearer {token}"})
    assert r.status_code == 403
Exercise the full process of sharing and then accessing a shared server
jupyterhub/tests/test_shares.py