@@ -265,6 +265,17 @@ def test_username_field_autocapitalize_none(self):
265
265
form = UserCreationForm ()
266
266
self .assertEqual (form .fields ['username' ].widget .attrs .get ('autocapitalize' ), 'none' )
267
267
268
+ def test_html_autocomplete_attributes (self ):
269
+ form = UserCreationForm ()
270
+ tests = (
271
+ ('username' , 'username' ),
272
+ ('password1' , 'new-password' ),
273
+ ('password2' , 'new-password' ),
274
+ )
275
+ for field_name , autocomplete in tests :
276
+ with self .subTest (field_name = field_name , autocomplete = autocomplete ):
277
+ self .assertEqual (form .fields [field_name ].widget .attrs ['autocomplete' ], autocomplete )
278
+
268
279
269
280
# To verify that the login form rejects inactive users, use an authentication
270
281
# backend that allows them.
@@ -492,6 +503,16 @@ def test_get_invalid_login_error(self):
492
503
self .assertEqual (error .code , 'invalid_login' )
493
504
self .assertEqual (error .params , {'username' : 'username' })
494
505
506
+ def test_html_autocomplete_attributes (self ):
507
+ form = AuthenticationForm ()
508
+ tests = (
509
+ ('username' , 'username' ),
510
+ ('password' , 'current-password' ),
511
+ )
512
+ for field_name , autocomplete in tests :
513
+ with self .subTest (field_name = field_name , autocomplete = autocomplete ):
514
+ self .assertEqual (form .fields [field_name ].widget .attrs ['autocomplete' ], autocomplete )
515
+
495
516
496
517
class SetPasswordFormTest (TestDataMixin , TestCase ):
497
518
@@ -572,6 +593,16 @@ def test_help_text_translation(self):
572
593
for french_text in french_help_texts :
573
594
self .assertIn (french_text , html )
574
595
596
+ def test_html_autocomplete_attributes (self ):
597
+ form = SetPasswordForm (self .u1 )
598
+ tests = (
599
+ ('new_password1' , 'new-password' ),
600
+ ('new_password2' , 'new-password' ),
601
+ )
602
+ for field_name , autocomplete in tests :
603
+ with self .subTest (field_name = field_name , autocomplete = autocomplete ):
604
+ self .assertEqual (form .fields [field_name ].widget .attrs ['autocomplete' ], autocomplete )
605
+
575
606
576
607
class PasswordChangeFormTest (TestDataMixin , TestCase ):
577
608
@@ -633,6 +664,11 @@ def test_password_whitespace_not_stripped(self):
633
664
self .assertEqual (form .cleaned_data ['new_password1' ], data ['new_password1' ])
634
665
self .assertEqual (form .cleaned_data ['new_password2' ], data ['new_password2' ])
635
666
667
+ def test_html_autocomplete_attributes (self ):
668
+ user = User .objects .get (username = 'testclient' )
669
+ form = PasswordChangeForm (user )
670
+ self .assertEqual (form .fields ['old_password' ].widget .attrs ['autocomplete' ], 'current-password' )
671
+
636
672
637
673
class UserChangeFormTest (TestDataMixin , TestCase ):
638
674
@@ -916,6 +952,10 @@ def test_custom_email_field(self):
916
952
self .assertEqual (len (mail .outbox ), 1 )
917
953
self .assertEqual (mail .outbox [0 ].to , [email ])
918
954
955
+ def test_html_autocomplete_attributes (self ):
956
+ form = PasswordResetForm ()
957
+ self .assertEqual (form .fields ['email' ].widget .attrs ['autocomplete' ], 'email' )
958
+
919
959
920
960
class ReadOnlyPasswordHashTest (SimpleTestCase ):
921
961
@@ -997,3 +1037,14 @@ def test_one_password(self):
997
1037
form2 = AdminPasswordChangeForm (user , {'password1' : 'test' , 'password2' : '' })
998
1038
self .assertEqual (form2 .errors ['password2' ], required_error )
999
1039
self .assertNotIn ('password1' , form2 .errors )
1040
+
1041
+ def test_html_autocomplete_attributes (self ):
1042
+ user = User .objects .get (username = 'testclient' )
1043
+ form = AdminPasswordChangeForm (user )
1044
+ tests = (
1045
+ ('password1' , 'new-password' ),
1046
+ ('password2' , 'new-password' ),
1047
+ )
1048
+ for field_name , autocomplete in tests :
1049
+ with self .subTest (field_name = field_name , autocomplete = autocomplete ):
1050
+ self .assertEqual (form .fields [field_name ].widget .attrs ['autocomplete' ], autocomplete )
0 commit comments