def test_default_language_finnish(): activate("en") test_name_en = "Test shop" test_name_fi = "Testi kauppa" shop = get_default_shop() shop.name = test_name_en shop.public_name = test_name_en shop.save() shop_form = ShopBaseForm(instance=shop, languages=settings.LANGUAGES) assert shop_form.languages[0] == "fi" data = get_form_data(shop_form, prepared=True) assert data.get("name__en") == test_name_en assert not data.get("name__fi") shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES) shop_form.full_clean() assert not shop_form.is_valid() and shop_form.errors data["name__fi"] = test_name_fi data["public_name__fi"] = test_name_fi shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES) shop_form.full_clean() assert shop_form.is_valid() and not shop_form.errors shop_form.save() shop.set_current_language("en") assert shop.name == test_name_en, "English activated" shop.set_current_language("fi") assert shop.name == test_name_fi, "Finnish activated"
def test_form_labels(): shop_form = ShopBaseForm(languages=[("en", "en")]) assert shop_form.base_fields["name__en"].label == "Name" shop_form = ShopBaseForm(languages=[("en", "en"), ("fi", "fi")]) assert shop_form.base_fields["name__en"].label == "Name [English]" assert shop_form.base_fields["name__fi"].label == "Name [Finnish]"
def test_default_language_english(): activate("en") test_name_en = "Test shop" shop = get_default_shop() shop.name = test_name_en shop.public_name = test_name_en shop.save() shop_form = ShopBaseForm(instance=shop, languages=settings.LANGUAGES) data = get_form_data(shop_form, prepared=True) assert data.get("name__en") == test_name_en assert not data.get("name__fi") shop_form = ShopBaseForm(data=data, instance=shop, languages=settings.LANGUAGES) shop_form.full_clean() assert shop_form.is_valid() and not shop_form.errors