|
10 | 10 | from django.db import connection, transaction
|
11 | 11 | from django.db.models import Q
|
12 | 12 | from django.http import QueryDict
|
13 |
| -from django.test import Client, TestCase |
| 13 | +from django.test import Client, TestCase, LiveServerTestCase |
14 | 14 | from django.urls import reverse
|
15 | 15 | from django.utils.functional import classproperty
|
16 | 16 | from django_enum import TextChoices
|
|
30 | 30 | # ExternEnum
|
31 | 31 | # )
|
32 | 32 | from django_enum.tests.djenum.forms import EnumTesterForm
|
33 |
| -from django_enum.tests.djenum.models import BadDefault, EnumTester |
| 33 | +from django_enum.tests.djenum.models import BadDefault, EnumTester, AdminDisplayBug35 |
34 | 34 | from django_test_migrations.constants import MIGRATION_TEST_MARKER
|
35 | 35 | from django_test_migrations.contrib.unittest_case import MigratorTestCase
|
36 | 36 |
|
@@ -964,6 +964,53 @@ def test_query(self):
|
964 | 964 | self.assertRaises(ValueError, self.MODEL_CLASS.objects.filter, big_pos_int=type('WrongType')())
|
965 | 965 |
|
966 | 966 |
|
| 967 | +class TestAdmin(EnumTypeMixin, LiveServerTestCase): |
| 968 | + |
| 969 | + BUG35_CLASS = AdminDisplayBug35 |
| 970 | + |
| 971 | + def test_admin_list_display_bug35(self): |
| 972 | + from django.contrib.auth import get_user_model |
| 973 | + |
| 974 | + get_user_model().objects.create_superuser( |
| 975 | + username='admin', |
| 976 | + |
| 977 | + password='admin_password', |
| 978 | + ) |
| 979 | + self.client.login(username='admin', password='admin_password') |
| 980 | + |
| 981 | + obj = self.BUG35_CLASS.objects.create() |
| 982 | + |
| 983 | + resp = self.client.get( |
| 984 | + reverse(f'admin:{self.BUG35_CLASS._meta.label_lower.replace(".", "_")}_changelist') |
| 985 | + ) |
| 986 | + self.assertContains(resp, '<td class="field-int_enum">Value 2</td>') |
| 987 | + change_link = reverse( |
| 988 | + f'admin:{self.BUG35_CLASS._meta.label_lower.replace(".", "_")}_change', |
| 989 | + args=[obj.id] |
| 990 | + ) |
| 991 | + self.assertContains(resp, f'<a href="{change_link}">Value1</a>') |
| 992 | + |
| 993 | + def test_admin_change_display_bug35(self): |
| 994 | + from django.contrib.auth import get_user_model |
| 995 | + |
| 996 | + get_user_model().objects.create_superuser( |
| 997 | + username='admin', |
| 998 | + |
| 999 | + password='admin_password', |
| 1000 | + ) |
| 1001 | + self.client.login(username='admin', password='admin_password') |
| 1002 | + |
| 1003 | + obj = self.BUG35_CLASS.objects.create() |
| 1004 | + resp = self.client.get( |
| 1005 | + reverse( |
| 1006 | + f'admin:{self.BUG35_CLASS._meta.label_lower.replace(".", "_")}_change', |
| 1007 | + args=[obj.id] |
| 1008 | + ) |
| 1009 | + ) |
| 1010 | + self.assertContains(resp, '<div class="readonly">Value1</div>') |
| 1011 | + self.assertContains(resp, '<div class="readonly">Value 2</div>') |
| 1012 | + |
| 1013 | + |
967 | 1014 | class TestFormField(EnumTypeMixin, TestCase):
|
968 | 1015 |
|
969 | 1016 | MODEL_CLASS = EnumTester
|
@@ -1788,6 +1835,7 @@ def test_bulk_update(self):
|
1788 | 1835 | SingleEnumPerf,
|
1789 | 1836 | SingleFieldPerf,
|
1790 | 1837 | SingleNoCoercePerf,
|
| 1838 | + AdminDisplayBug35 |
1791 | 1839 | )
|
1792 | 1840 | from enum_properties import EnumProperties, s
|
1793 | 1841 |
|
@@ -2100,6 +2148,11 @@ def test_saving(self):
|
2100 | 2148 | self.assertEqual(tester.text, None)
|
2101 | 2149 |
|
2102 | 2150 |
|
| 2151 | + class TestEnumPropAdmin(TestAdmin): |
| 2152 | + |
| 2153 | + BUG35_CLASS = AdminDisplayBug35 |
| 2154 | + |
| 2155 | + |
2103 | 2156 | class TestSymmetricEmptyValEquivalency(TestCase):
|
2104 | 2157 |
|
2105 | 2158 | def test(self):
|
|
0 commit comments