async def test_spawn_other_user(
    app, user, username, group, create_temp_role, has_access
):
    """GET /user/:name as another user with access to spawns user's server"""
    cookies = await app.login_user(username)
    requester = app.users[username]
    name = user.name
    assert username != user.name

    if has_access:
        if has_access == "group":
            group.users.append(user.orm_user)
            app.db.commit()
            scopes = [
                f"access:servers!group={group.name}",
                f"servers!group={group.name}",
            ]
            assert group in user.orm_user.groups
        elif has_access == "all":
            scopes = ["access:servers", "servers"]
        elif has_access == "user":
            scopes = [f"access:servers!user={user.name}", f"servers!user={user.name}"]
        role = create_temp_role(scopes)
        roles.grant_role(app.db, requester, role)

    r = await get_page('spawn/' + name, app, cookies=cookies)
    if not has_access:
        assert r.status_code == 404
        return
    r.raise_for_status()

    while '/spawn-pending/' in r.url:
        await asyncio.sleep(0.1)
        r = await async_requests.get(r.url, cookies=cookies)
        r.raise_for_status()

    assert (r.url.split('?')[0] + '/').startswith(public_url(app, user))
    r = await get_page(f'user/{name}/env', app, hub=False, cookies=cookies)

    r.raise_for_status()
    env = r.json()
    assert env['JUPYTERHUB_USER'] == name
GET /user/:name as another user with access to spawns user's server
jupyterhub/tests/test_pages.py