Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Added regression test for #17967. #22

Merged
merged 2 commits into from almost 2 years ago

2 participants

Aviral Dasgupta Alex Gaynor
Aviral Dasgupta

@aaugustin Here's a regression test for #17967. Hope it's okay.

tests/regressiontests/admin_views/tests.py
@@ -572,6 +572,24 @@ def test_allowed_filtering_15103(self):
572 572
         except SuspiciousOperation:
573 573
             self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model")
574 574
 
  575
+    def test_hide_change_password(self):
  576
+        """
  577
+        Tests if the "change password" link in the admin is hidden if the User
  578
+        does not have a usable password set.
  579
+        (against 9bea85795705d015cdadc82c68b99196a8554f5c)
  580
+        """
  581
+        user = User.objects.get(username='super')
  582
+        password = user.password
  583
+        user.set_unusable_password()
  584
+        user.save()
  585
+
  586
+        response = self.client.get('/test_admin/admin/')
  587
+        if reverse('admin:password_change') in response.content:
  588
+            self.fail('The "change password" link should not be displayed if a user does not have a usable password.')
1
Alex Gaynor Owner
alex added a note April 29, 2012

It's generally the style of the Django tests to do:

self.assertFalse(..., msg="foo")

rather than have the if statement (there may even be an assertNotContains or similar, that'd be even more optimal)..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tests/regressiontests/admin_views/tests.py
((5 lines not shown))
  576
+        """
  577
+        Tests if the "change password" link in the admin is hidden if the User
  578
+        does not have a usable password set.
  579
+        (against 9bea85795705d015cdadc82c68b99196a8554f5c)
  580
+        """
  581
+        user = User.objects.get(username='super')
  582
+        password = user.password
  583
+        user.set_unusable_password()
  584
+        user.save()
  585
+
  586
+        response = self.client.get('/test_admin/admin/')
  587
+        if reverse('admin:password_change') in response.content:
  588
+            self.fail('The "change password" link should not be displayed if a user does not have a usable password.')
  589
+
  590
+        user.password = password
  591
+        user.save()
6
Alex Gaynor Owner
alex added a note April 29, 2012

No need to save the user here, we only needed to test the one assert.

Aviral Dasgupta
aviraldg added a note April 29, 2012

What about test cases that might come after this one?

Alex Gaynor Owner
alex added a note April 29, 2012

Test cases are isolated, objects created in one aren't visible to another.

Aviral Dasgupta
aviraldg added a note April 29, 2012

The user object here is actually the one created from the fixtures that we're modifying.

Alex Gaynor Owner
alex added a note April 29, 2012

It doesn't matter, the semantics are that the changes you make aren't visible to other tests. Remove these lines and try running all the tests, you'll see!

Aviral Dasgupta
aviraldg added a note April 29, 2012

Oh, I didn't know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Alex Gaynor alex merged commit e75bd7e into from April 29, 2012
Alex Gaynor alex closed this April 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
15  tests/regressiontests/admin_views/tests.py
@@ -572,6 +572,21 @@ def test_allowed_filtering_15103(self):
572 572
         except SuspiciousOperation:
573 573
             self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model")
574 574
 
  575
+    def test_hide_change_password(self):
  576
+        """
  577
+        Tests if the "change password" link in the admin is hidden if the User
  578
+        does not have a usable password set.
  579
+        (against 9bea85795705d015cdadc82c68b99196a8554f5c)
  580
+        """
  581
+        user = User.objects.get(username='super')
  582
+        password = user.password
  583
+        user.set_unusable_password()
  584
+        user.save()
  585
+
  586
+        response = self.client.get('/test_admin/admin/')
  587
+        self.assertFalse(reverse('admin:password_change') in response.content,
  588
+            msg='The "change password" link should not be displayed if a user does not have a usable password.')
  589
+
575 590
 
576 591
 class AdminViewFormUrlTest(TestCase):
577 592
     urls = "regressiontests.admin_views.urls"
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.