コード例 #1
0
async def test_banned_user(client, capsys, cfg):
    reset_url = client.app.router["auth_reset_password"].url_for()

    async with NewUser({"status": UserStatus.BANNED.name}) as user:
        rp = await client.post(reset_url, json={
            "email": user["email"],
        })

    assert rp.url_obj.path == reset_url.path
    await assert_status(rp, web.HTTPOk, cfg.MSG_EMAIL_SENT.format(**user))

    out, err = capsys.readouterr()
    assert parse_test_marks(out)["reason"] == cfg.MSG_USER_BANNED
コード例 #2
0
async def test_unknown_email(client, capsys, cfg):
    reset_url = client.app.router["auth_reset_password"].url_for()

    rp = await client.post(reset_url, json={
        "email": EMAIL,
    })
    payload = await rp.text()

    assert rp.url_obj.path == reset_url.path
    await assert_status(rp, web.HTTPOk, cfg.MSG_EMAIL_SENT.format(email=EMAIL))

    out, err = capsys.readouterr()
    assert parse_test_marks(out)["reason"] == cfg.MSG_UNKNOWN_EMAIL
コード例 #3
0
async def test_inactive_user(client, capsys, cfg):
    reset_url = client.app.router["auth_reset_password"].url_for()

    async with NewUser({"status":
                        UserStatus.CONFIRMATION_PENDING.name}) as user:
        rp = await client.post(reset_url, json={
            "email": user["email"],
        })

    assert rp.url_obj.path == reset_url.path
    await assert_status(rp, web.HTTPOk, cfg.MSG_EMAIL_SENT.format(**user))

    out, err = capsys.readouterr()
    assert parse_test_marks(out)["reason"] == cfg.MSG_ACTIVATION_REQUIRED
コード例 #4
0
async def test_too_often(client, capsys, cfg):
    reset_url = client.app.router["auth_reset_password"].url_for()

    cfg = client.app[APP_LOGIN_CONFIG]
    db = cfg.STORAGE

    async with NewUser() as user:
        confirmation = await db.create_confirmation(
            user, ConfirmationAction.RESET_PASSWORD.name)
        rp = await client.post(reset_url, json={
            "email": user["email"],
        })
        await db.delete_confirmation(confirmation)

    assert rp.url_obj.path == reset_url.path
    await assert_status(rp, web.HTTPOk, cfg.MSG_EMAIL_SENT.format(**user))

    out, err = capsys.readouterr()
    assert parse_test_marks(out)["reason"] == cfg.MSG_OFTEN_RESET_PASSWORD
コード例 #5
0
async def test_too_often(client: TestClient, cfg: LoginOptions,
                         db: AsyncpgStorage, capsys):
    reset_url = client.app.router["auth_reset_password"].url_for()

    async with NewUser(app=client.app) as user:
        confirmation = await db.create_confirmation(
            user, ConfirmationAction.RESET_PASSWORD.name)
        rp = await client.post(
            reset_url,
            json={
                "email": user["email"],
            },
        )
        await db.delete_confirmation(confirmation)

    assert rp.url.path == reset_url.path
    await assert_status(rp, web.HTTPOk, cfg.MSG_EMAIL_SENT.format(**user))

    out, err = capsys.readouterr()
    assert parse_test_marks(out)["reason"] == cfg.MSG_OFTEN_RESET_PASSWORD