Ejemplo n.º 1
0
 def setUp(self):
     if not settings.REGION_STORES:
         raise SkipTest()
     if not settings.USE_CARRIER_URLS:
         raise SkipTest()
     set_carrier(None)
     set_url_prefix(None)
Ejemplo n.º 2
0
    def process_request(self, request):
        carrier = stored_carrier = None
        is_legacy = False
        set_url_prefix(None)
        set_carrier(None)

        # If I have a cookie use that carrier.
        remembered = request.COOKIES.get('carrier')
        if remembered in CARRIER_MAP:
            carrier = stored_carrier = remembered

        choice = request.REQUEST.get('carrier')
        if choice in CARRIER_MAP:
            carrier = choice
        elif 'carrier' in request.GET:
            # We are clearing the carrier.
            carrier = None

        # Legacy /<carrier>/ (don't break Gaia).
        for name in CARRIER_MAP:
            if request.path.startswith('/%s' % name):
                is_legacy = True
                carrier = name
                break

        # Update cookie if value have changed.
        if carrier != stored_carrier:
            request.set_cookie('carrier', carrier)

        if carrier and is_legacy:
            orig_path = request.path_info
            new_path = orig_path[len(carrier) + 1:] or '/'
            request.path_info = new_path

        set_carrier(carrier)
Ejemplo n.º 3
0
    def process_request(self, request):
        carrier = stored_carrier = None
        is_legacy = False
        set_url_prefix(None)
        set_carrier(None)

        # If I have a cookie use that carrier.
        remembered = request.COOKIES.get("carrier")
        if remembered in CARRIER_MAP:
            carrier = stored_carrier = remembered

        choice = request.REQUEST.get("carrier")
        if choice in CARRIER_MAP:
            carrier = choice
        elif "carrier" in request.GET:
            # We are clearing the carrier.
            carrier = None

        # Legacy /<carrier>/ (don't break Gaia).
        for name in CARRIER_MAP:
            if request.path.startswith("/%s" % name):
                is_legacy = True
                carrier = name
                break

        # Update cookie if value have changed.
        if carrier != stored_carrier:
            request.set_cookie("carrier", carrier)

        if carrier and is_legacy:
            orig_path = request.path_info
            new_path = orig_path[len(carrier) + 1 :] or "/"
            return redirect(urlparams(new_path, carrier=carrier))

        set_carrier(carrier)
Ejemplo n.º 4
0
def test_locale_url():
    rf = test_utils.RequestFactory()
    request = rf.get('/de', SCRIPT_NAME='/z')
    prefixer = urlresolvers.Prefixer(request)
    urlresolvers.set_url_prefix(prefixer)
    s = render('{{ locale_url("mobile") }}')
    eq_(s, '/z/de/mobile')
Ejemplo n.º 5
0
def test_locale_url():
    rf = test_utils.RequestFactory()
    request = rf.get('/de', SCRIPT_NAME='/z')
    prefixer = urlresolvers.Prefixer(request)
    urlresolvers.set_url_prefix(prefixer)
    s = render('{{ locale_url("mobile") }}')
    eq_(s, '/z/de/mobile')
Ejemplo n.º 6
0
    def process_request(self, request):
        carrier = stored_carrier = None
        is_legacy = False
        set_url_prefix(None)
        set_carrier(None)

        # If I have a cookie use that carrier.
        remembered = request.COOKIES.get('carrier')
        if remembered in settings.CARRIER_URLS:
            carrier = stored_carrier = remembered

        choice = request.REQUEST.get('carrier')
        if choice in settings.CARRIER_URLS:
            carrier = choice
        elif 'carrier' in request.GET:
            # We are clearing the carrier.
            carrier = None

        # Legacy /<carrier>/ (don't break Gaia).
        for name in settings.CARRIER_URLS:
            if request.path.startswith('/%s' % name):
                is_legacy = True
                carrier = name
                break

        # Update cookie if value have changed.
        if carrier != stored_carrier:
            request.set_cookie('carrier', carrier)

        if carrier and is_legacy:
            orig_path = request.path_info
            new_path = orig_path[len(carrier) + 1:] or '/'
            request.path_info = new_path

        set_carrier(carrier)
Ejemplo n.º 7
0
def default_prefixer(sender, **kwargs):
    """Make sure each test starts with a default URL prefixer."""
    request = http.HttpRequest()
    request.META['SCRIPT_NAME'] = ''
    prefixer = urlresolvers.Prefixer(request)
    prefixer.app = settings.DEFAULT_APP
    prefixer.locale = settings.LANGUAGE_CODE
    urlresolvers.set_url_prefix(prefixer)
Ejemplo n.º 8
0
 def activate(self, locale):
     old_prefix = get_url_prefix()
     old_locale = translation.get_language()
     rf = test_utils.RequestFactory()
     set_url_prefix(Prefixer(rf.get('/%s/' % (locale,))))
     translation.activate(locale)
     yield
     set_url_prefix(old_prefix)
     translation.activate(old_locale)
Ejemplo n.º 9
0
 def activate(self, locale):
     old_prefix = get_url_prefix()
     old_locale = translation.get_language()
     rf = test_utils.RequestFactory()
     set_url_prefix(Prefixer(rf.get('/%s/' % (locale, ))))
     translation.activate(locale)
     yield
     set_url_prefix(old_prefix)
     translation.activate(old_locale)
Ejemplo n.º 10
0
    def test_script_name(self):
        rf = RequestFactory()
        request = rf.get('/foo', SCRIPT_NAME='/oremj')
        prefixer = urlresolvers.Prefixer(request)
        eq_(prefixer.fix(prefixer.shortened_path), '/oremj/en-US/firefox/foo')

        # Now check reverse.
        urlresolvers.set_url_prefix(prefixer)
        set_script_prefix('/oremj')
        eq_(urlresolvers.reverse('home'), '/oremj/en-US/firefox/')
Ejemplo n.º 11
0
    def test_script_name(self):
        rf = RequestFactory()
        request = rf.get('/foo', SCRIPT_NAME='/oremj')
        prefixer = urlresolvers.Prefixer(request)
        eq_(prefixer.fix(prefixer.shortened_path), '/oremj/en-US/firefox/foo')

        # Now check reverse.
        urlresolvers.set_url_prefix(prefixer)
        set_script_prefix('/oremj')
        eq_(urlresolvers.reverse('home'), '/oremj/en-US/firefox/')
Ejemplo n.º 12
0
    def test_script_name(self):
        rf = test_utils.RequestFactory()
        request = rf.get("/foo", SCRIPT_NAME="/oremj")
        prefixer = urlresolvers.Prefixer(request)
        eq_(prefixer.fix(prefixer.shortened_path), "/oremj/en-US/firefox/foo")

        # Now check reverse.
        urlresolvers.set_url_prefix(prefixer)
        set_script_prefix("/oremj")
        eq_(urlresolvers.reverse("home"), "/oremj/en-US/firefox/")
Ejemplo n.º 13
0
 def activate(self, 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 = test_utils.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)
Ejemplo n.º 14
0
 def activate(self, 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,)))
         tower.activate(locale)
     if app:
         prefixer.app = app
     set_url_prefix(prefixer)
     yield
     old_prefix.app = old_app
     set_url_prefix(old_prefix)
     tower.activate(old_locale)
Ejemplo n.º 15
0
 def process_request(self, request):
     carrier = None
     set_url_prefix(None)
     set_carrier(None)
     for name in settings.CARRIER_URLS:
         if request.path.startswith('/%s' % name):
             carrier = name
             break
     if carrier:
         orig_path = request.path_info
         request.path_info = orig_path[len('/%s' % carrier):]
         if request.path_info == '' and settings.APPEND_SLASH:
             # e.g. /telefonica -> /telefonica/
             # Note that this is an exceptional case. All other slash
             # appending is handled further down the middleware chain.
             return HttpResponsePermanentRedirect(orig_path + '/')
         set_url_prefix(CarrierPrefixer(request, carrier))
     set_carrier(carrier)
Ejemplo n.º 16
0
    def process_request(self, request):
        carrier = stored_carrier = None
        set_url_prefix(None)
        set_carrier(None)

        # If I have a cookie use that carrier.
        remembered = request.COOKIES.get('carrier')
        if remembered in CARRIER_MAP:
            carrier = stored_carrier = remembered

        choice = request.REQUEST.get('carrier')
        if choice in CARRIER_MAP:
            carrier = choice
        elif 'carrier' in request.GET:
            # We are clearing the carrier.
            carrier = None

        # Update cookie if value have changed.
        if carrier != stored_carrier:
            request.set_cookie('carrier', carrier)

        set_carrier(carrier)
Ejemplo n.º 17
0
    def process_request(self, request):
        carrier = stored_carrier = None
        set_url_prefix(None)
        set_carrier(None)

        # If I have a cookie use that carrier.
        remembered = request.COOKIES.get('carrier')
        if remembered in CARRIER_MAP:
            carrier = stored_carrier = remembered

        choice = request.REQUEST.get('carrier')
        if choice in CARRIER_MAP:
            carrier = choice
        elif 'carrier' in request.GET:
            # We are clearing the carrier.
            carrier = None

        # Update cookie if value have changed.
        if carrier != stored_carrier:
            request.set_cookie('carrier', carrier)

        set_carrier(carrier)
Ejemplo n.º 18
0
 def setUp(self):
     set_carrier(None)
     set_url_prefix(None)
Ejemplo n.º 19
0
 def setUp(self):
     set_carrier(None)
     set_url_prefix(None)