Skip to content

Commit

Permalink
Add TranslatedField blank validation test, see #HEA-141
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispreee committed Jan 17, 2024
1 parent 7f45ef0 commit 25b2d1b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion apps/common/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.test import TestCase
from django.utils import translation

from common.fields import translation_fields
from common.tests.factories import ClassifiedProductFactory


Expand All @@ -21,7 +22,21 @@ def setUpTestData(cls):
description_pt="description pt",
)

def test_translated_fields(self):
def test_blank_permission(self):
# ClassifiedProduct common_name is blank=True, so all variants can be blank.
# ClassifiedProduct description is blank=False. This validation should be applied to default language only.
# So this tests that description_en blank=False, other languages, and all common_name variants blank=True.
for translated_field in ("common_name", "description"):
for field_name in translation_fields(translated_field):
blankable = field_name != "description_en"
with self.subTest(field=field_name):
self.assertEqual(
self.product._meta.get_field(field_name).blank,
blankable,
f"Field {field_name} blank is {self.product._meta.get_field(field_name).blank}",
)

def test_translation(self):
self.assertEqual(self.product.common_name_en, "common_name en")
self.assertEqual(self.product.description_en, "description en")
# Check properties return default language
Expand Down

0 comments on commit 25b2d1b

Please sign in to comment.