async def test_login_strip(app, form_user, auth_user, form_password):
    """Test that login form strips space form usernames, but not passwords"""
    form_data = {"username": form_user, "password": form_password}
    expected_auth = {"username": auth_user, "password": form_password}
    called_with = []

    async def mock_authenticate(handler, data):
        called_with.append(data)

    with mock.patch.object(app.authenticator, 'authenticate', mock_authenticate):
        r = await get_page('login', app)
        r.raise_for_status()
        cookies = r.cookies
        xsrf = cookies['_xsrf']
        page = BeautifulSoup(r.text, "html.parser")
        action_url = public_host(app) + page.find("form")["action"]
        xsrf_input = page.find("form").find("input", attrs={"name": "_xsrf"})
        form_data["_xsrf"] = xsrf_input["value"]
        await async_requests.post(
            action_url, data=form_data, allow_redirects=False, cookies=cookies
        )

    assert called_with == [expected_auth]
Test that login form strips space form usernames, but not passwords
jupyterhub/tests/test_pages.py