From dbcd7b064e7278614f29fc45468d461e263d4da7 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Wed, 23 Oct 2019 16:14:06 +0200 Subject: Fixed #30902 -- Added __str__() for model choice enums. Allows expected behavior when cast to str, also matching behaviour of created instances with those fetched from the DB. Thanks to Simon Charette, Nick Pope, and Shai Berger for reviews. --- tests/model_enums/tests.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/model_enums/tests.py b/tests/model_enums/tests.py index 6b4bd6e7fd..e1810e673a 100644 --- a/tests/model_enums/tests.py +++ b/tests/model_enums/tests.py @@ -143,6 +143,12 @@ class ChoicesTests(SimpleTestCase): APPLE = 1, 'Apple' PINEAPPLE = 1, 'Pineapple' + def test_str(self): + for test in [Gender, Suit, YearInSchool, Vehicle]: + for member in test: + with self.subTest(member=member): + self.assertEqual(str(test[member.name]), str(member.value)) + class Separator(bytes, models.Choices): FS = b'\x1c', 'File Separator' -- cgit v1.3