diff options
author | Nick Pope <nick@nickpope.me.uk> | 2021-02-19 17:17:11 +0000 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-03-24 07:45:33 +0100 |
commit | a96c730431196b119559bbb18a0e85e6ee8b2597 (patch) | |
tree | 5cc8c42ed5fc8fe9d72851617541f184ae4b99ed /tests/model_enums | |
parent | 41e39c41c9225bc3cbd5f333694e0a4d113136be (diff) | |
download | django-a96c730431196b119559bbb18a0e85e6ee8b2597.tar.gz |
Fixed #32460 -- Allowed "label"/"do_not_call_in_templates" members in model choice enums.
Diffstat (limited to 'tests/model_enums')
-rw-r--r-- | tests/model_enums/tests.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/model_enums/tests.py b/tests/model_enums/tests.py index 3bfec1596a..78f8b146be 100644 --- a/tests/model_enums/tests.py +++ b/tests/model_enums/tests.py @@ -159,6 +159,26 @@ class ChoicesTests(SimpleTestCase): with self.assertRaises(AttributeError): models.TextChoices('Properties', 'choices labels names values') + def test_label_member(self): + # label can be used as a member. + Stationery = models.TextChoices('Stationery', 'label stamp sticker') + self.assertEqual(Stationery.label.label, 'Label') + self.assertEqual(Stationery.label.value, 'label') + self.assertEqual(Stationery.label.name, 'label') + + def test_do_not_call_in_templates_member(self): + # do_not_call_in_templates is not implicitly treated as a member. + Special = models.IntegerChoices('Special', 'do_not_call_in_templates') + self.assertEqual( + Special.do_not_call_in_templates.label, + 'Do Not Call In Templates', + ) + self.assertEqual(Special.do_not_call_in_templates.value, 1) + self.assertEqual( + Special.do_not_call_in_templates.name, + 'do_not_call_in_templates', + ) + class Separator(bytes, models.Choices): FS = b'\x1c', 'File Separator' |