From d12d55ec26f127a09d9c133dd61dceaad2282b0e Mon Sep 17 00:00:00 2001 From: Aviral Dasgupta Date: Sun, 29 Apr 2012 17:26:22 +0530 Subject: [PATCH 1/2] Added regression test for #17967. --- tests/regressiontests/admin_views/tests.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 55a2639028..5f6467fb47 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -572,6 +572,24 @@ class AdminViewBasicTest(TestCase): except SuspiciousOperation: self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model") + def test_hide_change_password(self): + """ + Tests if the "change password" link in the admin is hidden if the User + does not have a usable password set. + (against 9bea85795705d015cdadc82c68b99196a8554f5c) + """ + user = User.objects.get(username='super') + password = user.password + user.set_unusable_password() + user.save() + + response = self.client.get('/test_admin/admin/') + if reverse('admin:password_change') in response.content: + self.fail('The "change password" link should not be displayed if a user does not have a usable password.') + + user.password = password + user.save() + class AdminViewFormUrlTest(TestCase): urls = "regressiontests.admin_views.urls" From 0525f6d8bdd8cf1aafaac40c4325aceb49b3c6f8 Mon Sep 17 00:00:00 2001 From: Aviral Dasgupta Date: Sun, 29 Apr 2012 21:30:41 +0530 Subject: [PATCH 2/2] Fixed some style issues in previous commit. --- tests/regressiontests/admin_views/tests.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 5f6467fb47..0be8b36b27 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -584,11 +584,8 @@ class AdminViewBasicTest(TestCase): user.save() response = self.client.get('/test_admin/admin/') - if reverse('admin:password_change') in response.content: - self.fail('The "change password" link should not be displayed if a user does not have a usable password.') - - user.password = password - user.save() + self.assertFalse(reverse('admin:password_change') in response.content, + msg='The "change password" link should not be displayed if a user does not have a usable password.') class AdminViewFormUrlTest(TestCase):