Example #1
0
def test_includeme():
    config_settings = {}
    config = pretend.stub(
        add_request_method=pretend.call_recorder(lambda f, name, reify: None),
        get_settings=lambda: config_settings,
    )

    i18n.includeme(config)

    assert config.add_request_method.calls == [
        pretend.call(i18n._locale, name="locale", reify=True),
    ]
    assert config_settings == {
        "jinja2.filters": {
            "format_date":
            "warehouse.i18n.filters:format_date",
            "format_datetime":
            "warehouse.i18n.filters:format_datetime",
            "format_rfc822_datetime":
            "warehouse.i18n.filters:format_rfc822_datetime",
        },
        "jinja2.globals": {
            "l20n": "warehouse.i18n.l20n:l20n",
        },
    }
Example #2
0
def test_includeme():
    config_settings = {}
    config = pretend.stub(
        add_translation_dirs=pretend.call_recorder(lambda s: None),
        set_locale_negotiator=pretend.call_recorder(lambda f: None),
        add_request_method=pretend.call_recorder(lambda f, name, reify: None),
        get_settings=lambda: config_settings,
    )

    i18n.includeme(config)

    assert config.add_translation_dirs.calls == [
        pretend.call("warehouse:locale/")
    ]
    assert config.set_locale_negotiator.calls == [
        pretend.call(i18n._negotiate_locale)
    ]
    assert config.add_request_method.calls == [
        pretend.call(i18n._locale, name="locale", reify=True)
    ]
    assert config_settings == {
        "jinja2.filters": {
            "format_date": "warehouse.i18n.filters:format_date",
            "format_datetime": "warehouse.i18n.filters:format_datetime",
            "format_rfc822_datetime":
            "warehouse.i18n.filters:format_rfc822_datetime",
            "format_number": "warehouse.i18n.filters:format_number",
        },
        "jinja2.globals": {
            "KNOWN_LOCALES": "warehouse.i18n:KNOWN_LOCALES"
        },
    }
Example #3
0
def test_includeme():
    config_settings = {}
    config = pretend.stub(
        add_request_method=pretend.call_recorder(lambda f, name, reify: None),
        get_settings=lambda: config_settings,
    )

    i18n.includeme(config)

    assert config.add_request_method.calls == [
        pretend.call(i18n._locale, name="locale", reify=True)
    ]
    assert config_settings == {
        "jinja2.filters": {
            "format_date": "warehouse.i18n.filters:format_date",
            "format_datetime": "warehouse.i18n.filters:format_datetime",
            "format_rfc822_datetime": "warehouse.i18n.filters:format_rfc822_datetime",
            "format_number": "warehouse.i18n.filters:format_number",
        }
    }
Example #4
0
def test_includeme():
    config_settings = {}
    config = pretend.stub(
        add_request_method=pretend.call_recorder(lambda f, name, reify: None),
        get_settings=lambda: config_settings,
    )

    i18n.includeme(config)

    assert config.add_request_method.calls == [
        pretend.call(i18n._locale, name="locale", reify=True),
        pretend.call(i18n._translation, name="translation", reify=True),
    ]
    assert config_settings == {
        "jinja2.filters": {
            "format_date": "warehouse.i18n.filters:format_date",
        },
        "jinja2.finalize": i18n.translate_value,
        "jinja2.i18n.domain": "warehouse",
        "jinja2.i18n.gettext": i18n.JinjaRequestTranslation,
    }
Example #5
0
def test_includeme():
    config_settings = {}
    config = pretend.stub(
        add_request_method=pretend.call_recorder(lambda f, name, reify: None),
        get_settings=lambda: config_settings,
    )

    i18n.includeme(config)

    assert config.add_request_method.calls == [
        pretend.call(i18n._locale, name="locale", reify=True),
        pretend.call(i18n._translation, name="translation", reify=True),
    ]
    assert config_settings == {
        "jinja2.filters": {
            "format_date": "warehouse.i18n.filters:format_date",
        },
        "jinja2.finalize": i18n.translate_value,
        "jinja2.i18n.domain": "warehouse",
        "jinja2.i18n.gettext": i18n.JinjaRequestTranslation,
    }