Esempio n. 1
0
def test_shop_remove_available_languages(admin_user):
    shop = factories.get_default_shop()
    client = SmartClient()

    with override_settings(LANGUAGES=[
        ("en", "English"),
        ("fi", "Finnish"),
    ],
                           LANGUAGE_CODE="en",
                           PARLER_DEFAULT_LANGUAGE_CODE="en"):
        # there is no language set for the shop, the first one will be used
        response = client.get(reverse("shuup:index"))
        assert get_language() == "en"

        # request js catalog file
        response = client.get(reverse("shuup:js-catalog"))
        assert get_language() == "en"

        # when requesting admin js catalog, the language should be any of the available
        client.get("shuup_admin:js-catalog")
        assert get_language() == "en"

        set_shop_available_languages(shop, ["fi"])

        response = client.get(reverse("shuup:index"))
        assert get_language() == "fi"

        response = client.get(reverse("shuup:js-catalog"))
        assert get_language() == "fi"

        client.get("shuup_admin:js-catalog")
        assert get_language() == "en"
Esempio n. 2
0
def test_shop_remove_available_languages(admin_user):
    shop = factories.get_default_shop()
    client = SmartClient()

    with override_settings(
        LANGUAGES=[
            ("en", "English"),
            ("fi", "Finnish"),
        ],
        LANGUAGE_CODE="en",
        PARLER_DEFAULT_LANGUAGE_CODE = "en"
    ):
        # there is no language set for the shop, the first one will be used
        response = client.get(reverse("shuup:index"))
        assert get_language() == "en"

        # request js catalog file
        response = client.get(reverse("shuup:js-catalog"))
        assert get_language() == "en"

        # when requesting admin js catalog, the language should be any of the available
        client.get("shuup_admin:js-catalog")
        assert get_language() == "en"

        set_shop_available_languages(shop, ["fi"])

        response = client.get(reverse("shuup:index"))
        assert get_language() == "fi"

        response = client.get(reverse("shuup:js-catalog"))
        assert get_language() == "fi"

        client.get("shuup_admin:js-catalog")
        assert get_language() == "en"
Esempio n. 3
0
def test_shop_available_languages(admin_user):
    original_language = get_language()
    shop = factories.get_default_shop()
    client = SmartClient()

    with override_settings(LANGUAGES=[("it", "Italian"), ("fr", "French"),
                                      ("fi", "Finnish"), ("pt", "Portuguese")],
                           LANGUAGE_CODE="it",
                           PARLER_DEFAULT_LANGUAGE_CODE="it"):
        # there is no language set for the shop, the first one will be used
        client.get(reverse("shuup:index"))
        assert get_language() == "it"

        # set an invalid language code
        with pytest.raises(ValueError):
            set_shop_available_languages(shop, ["xpto"])

        # limit the langauges for the shop to "fi" and "pt"
        set_shop_available_languages(shop, ["fi", "pt"])

        # the middleware will automatically set the language to "fi" as that is the first one available for the shop
        client.get(reverse("shuup:index"))
        assert get_language() == "fi"

        # the same won't happen for any other url - the middleware will only affect front urls
        client.get("shuup_admin:index")
        assert get_language() == "it"

        # test againt front again
        client.get(reverse("shuup:index"))
        assert get_language() == "fi"

        # again for admin
        client.get("shuup_admin:index")
        assert get_language() == "it"

    activate(original_language)
Esempio n. 4
0
def test_shop_available_languages(admin_user):
    original_language = get_language()
    shop = factories.get_default_shop()
    client = SmartClient()

    with override_settings(
        LANGUAGES=[
            ("it", "Italian"),
            ("fr", "French"),
            ("fi", "Finnish"),
            ("pt", "Portuguese")
        ],
        LANGUAGE_CODE="it",
        PARLER_DEFAULT_LANGUAGE_CODE = "it"
    ):
        # there is no language set for the shop, the first one will be used
        response = client.get(reverse("shuup:index"))
        assert get_language() == "it"

        # set an invalid language code
        with pytest.raises(ValueError):
            set_shop_available_languages(shop, ["xpto"])

        # limit the langauges for the shop to "fi" and "pt"
        set_shop_available_languages(shop, ["fi", "pt"])

        # the middleware will automatically set the language to "fi" as that is the first one available for the shop
        response = client.get(reverse("shuup:index"))
        assert get_language() == "fi"

        # the same won't happen for any other url - the middleware will only affect front urls
        client.get("shuup_admin:index")
        assert get_language() == "it"

        # test againt front again
        client.get(reverse("shuup:index"))
        assert get_language() == "fi"

        # again for admin
        client.get("shuup_admin:index")
        assert get_language() == "it"

        # remote all available languages
        set_shop_available_languages(shop, [])
        # this should fallback to settings.LAGUAGE_CODE
        response = client.get(reverse("shuup:index"))
        assert get_language() == "it"

    activate(original_language)
Esempio n. 5
0
 def form_valid(self, form):
     if self.name not in form.forms:
         return
     data = form.forms[self.name].cleaned_data
     set_shop_available_languages(self.object,
                                  data.get("available_languages", []))
Esempio n. 6
0
 def form_valid(self, form):
     if self.name not in form.forms:
         return
     data = form.forms[self.name].cleaned_data
     set_shop_available_languages(self.object, data.get("available_languages", []))