Added tests for model field's choices iterator/iterable values.

This commit is contained in:
Natalia 2023-08-16 15:15:31 -03:00 committed by Mariusz Felisiak
parent 6934fc3f6e
commit f1c0a3baf7
3 changed files with 28 additions and 0 deletions

View file

@ -157,16 +157,27 @@ class ChoicesTests(SimpleTestCase):
cls.empty_choices_text = Choiceful._meta.get_field("empty_choices_text")
cls.with_choices = Choiceful._meta.get_field("with_choices")
cls.choices_from_enum = Choiceful._meta.get_field("choices_from_enum")
cls.choices_from_iterator = Choiceful._meta.get_field("choices_from_iterator")
def test_choices(self):
self.assertIsNone(self.no_choices.choices)
self.assertEqual(self.empty_choices.choices, ())
self.assertEqual(self.empty_choices_bool.choices, ())
self.assertEqual(self.empty_choices_text.choices, ())
self.assertEqual(self.with_choices.choices, [(1, "A")])
self.assertEqual(
self.choices_from_iterator.choices, [(0, "0"), (1, "1"), (2, "2")]
)
def test_flatchoices(self):
self.assertEqual(self.no_choices.flatchoices, [])
self.assertEqual(self.empty_choices.flatchoices, [])
self.assertEqual(self.empty_choices_bool.flatchoices, [])
self.assertEqual(self.empty_choices_text.flatchoices, [])
self.assertEqual(self.with_choices.flatchoices, [(1, "A")])
self.assertEqual(
self.choices_from_iterator.flatchoices, [(0, "0"), (1, "1"), (2, "2")]
)
def test_check(self):
self.assertEqual(Choiceful.check(), [])
@ -196,6 +207,7 @@ class ChoicesTests(SimpleTestCase):
def test_choices_from_enum(self):
# Choices class was transparently resolved when given as argument.
self.assertEqual(self.choices_from_enum.choices, Choiceful.Suit.choices)
self.assertEqual(self.choices_from_enum.flatchoices, Choiceful.Suit.choices)
class GetFieldDisplayTests(SimpleTestCase):