Debian Codegraph @

tests/admin_views/test_forms.py

raw
1 from django.contrib.admin.forms import AdminAuthenticationForm
2 from django.contrib.admin.helpers import AdminForm
3 from django.contrib.auth.models import User
4 from django.test import SimpleTestCase, TestCase, override_settings
5
6 from .admin import ArticleForm
7
8
9 # To verify that the login form rejects inactive users, use an authentication
10 # backend that allows them.
11 @override_settings(
12 AUTHENTICATION_BACKENDS=["django.contrib.auth.backends.AllowAllUsersModelBackend"]
13 )
14 class AdminAuthenticationFormTests(TestCase):
15 @classmethod
16 def setUpTestData(cls):
17 User.objects.create_user(
18 username="inactive", password="password", is_active=False
19 )
20
21 def test_inactive_user(self):
22 data = {
23 "username": "inactive",
24 "password": "password",
25 }
26 form = AdminAuthenticationForm(None, data)
27 self.assertEqual(form.non_field_errors(), ["This account is inactive."])
28
29
30 class AdminFormTests(SimpleTestCase):
31 def test_repr(self):
32 fieldsets = (
33 (
34 "My fields",
35 {
36 "classes": ["collapse"],
37 "fields": ("url", "title", "content", "sites"),
38 },
39 ),
40 )
41 form = ArticleForm()
42 admin_form = AdminForm(form, fieldsets, {})
43 self.assertEqual(
44 repr(admin_form),
45 "<AdminForm: form=ArticleForm fieldsets=(('My fields', "
46 "{'classes': ['collapse'], "
47 "'fields': ('url', 'title', 'content', 'sites')}),)>",
48 )