Esempio n. 1
0
def test_xlation(app, client, get_message_local):
    # Test form and email translation
    app.config["BABEL_DEFAULT_LOCALE"] = "fr_FR"
    assert check_xlation(app, "fr_FR"), "You must run python setup.py compile_catalog"

    authenticate(client)

    response = client.get("/change", follow_redirects=True)
    with app.test_request_context():
        # Check header
        assert (
            f'<h1>{localize_callback("Change password")}</h1>'.encode() in response.data
        )
        submit = localize_callback(_default_field_labels["change_password"])
        assert f'value="{submit}"'.encode() in response.data

    with app.mail.record_messages() as outbox:
        response = client.post(
            "/change",
            data={
                "password": "******",
                "new_password": "******",
                "new_password_confirm": "new strong password",
            },
            follow_redirects=True,
        )

    with app.test_request_context():
        assert get_message_local("PASSWORD_CHANGE").encode("utf-8") in response.data
        assert b"Home Page" in response.data
        assert len(outbox) == 1
        assert (
            localize_callback(
                app.config["SECURITY_EMAIL_SUBJECT_PASSWORD_CHANGE_NOTICE"]
            )
            in outbox[0].subject
        )
        assert (
            str(markupsafe.escape(localize_callback("Your password has been changed.")))
            in outbox[0].html
        )
        assert localize_callback("Your password has been changed") in outbox[0].body
def test_xlation(app, client, get_message_local):
    # Test form and email translation
    app.config["BABEL_DEFAULT_LOCALE"] = "fr_FR"
    assert check_xlation(
        app, "fr_FR"), "You must run python setup.py compile_catalog"

    response = client.get("/register", follow_redirects=True)
    with app.app_context():
        # Check header
        assert (f'<h1>{localize_callback("Register")}</h1>'.encode("utf-8")
                in response.data)
        submit = localize_callback(_default_field_labels["register"])
        assert f'value="{submit}"'.encode("utf-8") in response.data

    with app.mail.record_messages() as outbox:
        response = client.post(
            "/register",
            data={
                "email": "*****@*****.**",
                "password": "******",
                "password_confirm": "new strong password",
            },
            follow_redirects=True,
        )

    with app.app_context():
        assert (get_message_local("CONFIRM_REGISTRATION",
                                  email="*****@*****.**").encode("utf-8")
                in response.data)
        assert b"Home Page" in response.data
        assert len(outbox) == 1
        assert (localize_callback(
            app.config["SECURITY_EMAIL_SUBJECT_REGISTER"])
                in outbox[0].subject)
        assert (str(
            markupsafe.escape(
                localize_callback(
                    "You can confirm your email through the link below:")))
                in outbox[0].html)
        assert (localize_callback(
            "You can confirm your email through the link below:")
                in outbox[0].body)
Esempio n. 3
0
 def fn(key, **kwargs):
     return localize_callback(app.config["SECURITY_MSG_" + key][0], **kwargs)