Exemplo n.º 1
0
def test_locale_url():
    rf = RequestFactory()
    request = rf.get('/de', SCRIPT_NAME='/z')
    prefixer = urlresolvers.Prefixer(request)
    set_url_prefix(prefixer)
    s = render('{{ locale_url("mobile") }}')
    assert s == '/z/de/mobile'
Exemplo n.º 2
0
    def test_script_name(self):
        rf = RequestFactory()
        request = rf.get('/foo', SCRIPT_NAME='/oremj')
        prefixer = urlresolvers.Prefixer(request)
        assert prefixer.fix(prefixer.shortened_path) == ('/oremj/en-US/firefox/foo')

        # Now check reverse.
        set_url_prefix(prefixer)
        assert reverse('home') == '/oremj/en-US/firefox/'
Exemplo n.º 3
0
def activate_locale(locale=None, app=None):
    """Active an app or a locale."""
    prefixer = old_prefix = get_url_prefix()
    old_app = old_prefix.app
    old_locale = translation.get_language()
    if locale:
        rf = RequestFactory()
        prefixer = Prefixer(rf.get('/%s/' % (locale,)))
        translation.activate(locale)
    if app:
        prefixer.app = app
    set_url_prefix(prefixer)
    yield
    old_prefix.app = old_app
    set_url_prefix(old_prefix)
    translation.activate(old_locale)