summaryrefslogtreecommitdiff
path: root/tests/auth_tests/test_management.py
diff options
context:
space:
mode:
authorAnton Samarchyan <desecho@gmail.com>2017-03-01 17:29:50 -0500
committerTim Graham <timograham@gmail.com>2017-03-01 17:29:50 -0500
commit7588d7e439a5deb7f534bdeb2abe407b937e3c1a (patch)
tree898a1fd05c11036d2519f379ea5656e6086e7b2b /tests/auth_tests/test_management.py
parentfede65260aaf3a5100d1c07de771707dd50b1f35 (diff)
Improved test coverage for django.contrib.auth.
Diffstat (limited to 'tests/auth_tests/test_management.py')
-rw-r--r--tests/auth_tests/test_management.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py
index 28e8c6328e..20de17c163 100644
--- a/tests/auth_tests/test_management.py
+++ b/tests/auth_tests/test_management.py
@@ -1,4 +1,5 @@
import builtins
+import getpass
import sys
from datetime import date
from io import StringIO
@@ -110,6 +111,28 @@ class ChangepasswordManagementCommandTestCase(TestCase):
self.stdout.close()
self.stderr.close()
+ @mock.patch.object(getpass, 'getpass', return_value='password')
+ def test_get_pass(self, mock_get_pass):
+ call_command('changepassword', username='joe', stdout=self.stdout)
+ self.assertIs(User.objects.get(username='joe').check_password('password'), True)
+
+ @mock.patch.object(getpass, 'getpass', return_value='')
+ def test_get_pass_no_input(self, mock_get_pass):
+ with self.assertRaisesMessage(CommandError, 'aborted'):
+ call_command('changepassword', username='joe', stdout=self.stdout)
+
+ @mock.patch.object(changepassword.Command, '_get_pass', return_value='new_password')
+ def test_system_username(self, mock_get_pass):
+ """The system username is used if --username isn't provided."""
+ username = getpass.getuser()
+ User.objects.create_user(username=username, password='qwerty')
+ call_command('changepassword', stdout=self.stdout)
+ self.assertIs(User.objects.get(username=username).check_password('new_password'), True)
+
+ def test_nonexistent_username(self):
+ with self.assertRaisesMessage(CommandError, "user 'test' does not exist"):
+ call_command('changepassword', username='test', stdout=self.stdout)
+
@mock.patch.object(changepassword.Command, '_get_pass', return_value='not qwerty')
def test_that_changepassword_command_changes_joes_password(self, mock_get_pass):
"Executing the changepassword management command should change joe's password"
@@ -183,6 +206,11 @@ class MultiDBChangepasswordManagementCommandTestCase(TestCase):
)
class CreatesuperuserManagementCommandTestCase(TestCase):
+ def test_no_email_argument(self):
+ new_io = StringIO()
+ with self.assertRaisesMessage(CommandError, 'You must use --email with --noinput.'):
+ call_command('createsuperuser', interactive=False, username='joe', stdout=new_io)
+
def test_basic_usage(self):
"Check the operation of the createsuperuser management command"
# We can use the management command to create a superuser