Loading tests/auth_tests/test_management.py +44 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,28 @@ class ChangepasswordManagementCommandTestCase(TestCase): call_command('changepassword', username='J\xfalia', stdout=self.stdout) class MultiDBChangepasswordManagementCommandTestCase(TestCase): multi_db = True @mock.patch.object(changepassword.Command, '_get_pass', return_value='not qwerty') def test_that_changepassword_command_with_database_option_uses_given_db(self, mock_get_pass): """ changepassword --database should operate on the specified DB. """ user = User.objects.db_manager('other').create_user(username='joe', password='qwerty') self.assertTrue(user.check_password('qwerty')) out = six.StringIO() call_command('changepassword', username='joe', database='other', stdout=out) command_output = out.getvalue().strip() self.assertEqual( command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'" ) self.assertTrue(User.objects.using('other').get(username="joe").check_password('not qwerty')) @override_settings( SILENCED_SYSTEM_CHECKS=['fields.W342'], # ForeignKey(unique=True) AUTH_PASSWORD_VALIDATORS=[{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'}], Loading Loading @@ -525,6 +547,28 @@ class CreatesuperuserManagementCommandTestCase(TestCase): test(self) class MultiDBCreatesuperuserTestCase(TestCase): multi_db = True def test_createsuperuser_command_with_database_option(self): """ changepassword --database should operate on the specified DB. """ new_io = six.StringIO() call_command( 'createsuperuser', interactive=False, username='joe', email='joe@somewhere.org', database='other', stdout=new_io, ) command_output = new_io.getvalue().strip() self.assertEqual(command_output, 'Superuser created successfully.') user = User.objects.using('other').get(username='joe') self.assertEqual(user.email, 'joe@somewhere.org') class CustomUserModelValidationTestCase(SimpleTestCase): @override_settings(AUTH_USER_MODEL='auth_tests.CustomUserNonListRequiredFields') @override_system_checks([check_user_model]) Loading tests/createsuperuser/__init__.pydeleted 100644 → 0 +0 −0 Empty file deleted. tests/createsuperuser/tests.pydeleted 100644 → 0 +0 −55 Original line number Diff line number Diff line from django.contrib.auth import models from django.contrib.auth.management.commands import changepassword from django.core.management import call_command from django.test import TestCase, mock from django.utils.six import StringIO class MultiDBChangepasswordManagementCommandTestCase(TestCase): multi_db = True def setUp(self): self.user = models.User.objects.db_manager('other').create_user(username='joe', password='qwerty') @mock.patch.object(changepassword.Command, '_get_pass', return_value='not qwerty') def test_that_changepassword_command_with_database_option_uses_given_db(self, mock_get_pass): """ Executing the changepassword management command with a database option should operate on the specified DB """ self.assertTrue(self.user.check_password('qwerty')) out = StringIO() call_command('changepassword', username='joe', database='other', stdout=out) command_output = out.getvalue().strip() self.assertEqual( command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'" ) self.assertTrue(models.User.objects.using('other').get(username="joe").check_password("not qwerty")) class MultiDBCreatesuperuserTestCase(TestCase): multi_db = True def test_createsuperuser_command_with_database_option(self): " createsuperuser command should operate on specified DB" new_io = StringIO() call_command( "createsuperuser", interactive=False, username="joe", email="joe@somewhere.org", database='other', stdout=new_io ) command_output = new_io.getvalue().strip() self.assertEqual(command_output, 'Superuser created successfully.') u = models.User.objects.using('other').get(username="joe") self.assertEqual(u.email, 'joe@somewhere.org') new_io.close() Loading
tests/auth_tests/test_management.py +44 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,28 @@ class ChangepasswordManagementCommandTestCase(TestCase): call_command('changepassword', username='J\xfalia', stdout=self.stdout) class MultiDBChangepasswordManagementCommandTestCase(TestCase): multi_db = True @mock.patch.object(changepassword.Command, '_get_pass', return_value='not qwerty') def test_that_changepassword_command_with_database_option_uses_given_db(self, mock_get_pass): """ changepassword --database should operate on the specified DB. """ user = User.objects.db_manager('other').create_user(username='joe', password='qwerty') self.assertTrue(user.check_password('qwerty')) out = six.StringIO() call_command('changepassword', username='joe', database='other', stdout=out) command_output = out.getvalue().strip() self.assertEqual( command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'" ) self.assertTrue(User.objects.using('other').get(username="joe").check_password('not qwerty')) @override_settings( SILENCED_SYSTEM_CHECKS=['fields.W342'], # ForeignKey(unique=True) AUTH_PASSWORD_VALIDATORS=[{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'}], Loading Loading @@ -525,6 +547,28 @@ class CreatesuperuserManagementCommandTestCase(TestCase): test(self) class MultiDBCreatesuperuserTestCase(TestCase): multi_db = True def test_createsuperuser_command_with_database_option(self): """ changepassword --database should operate on the specified DB. """ new_io = six.StringIO() call_command( 'createsuperuser', interactive=False, username='joe', email='joe@somewhere.org', database='other', stdout=new_io, ) command_output = new_io.getvalue().strip() self.assertEqual(command_output, 'Superuser created successfully.') user = User.objects.using('other').get(username='joe') self.assertEqual(user.email, 'joe@somewhere.org') class CustomUserModelValidationTestCase(SimpleTestCase): @override_settings(AUTH_USER_MODEL='auth_tests.CustomUserNonListRequiredFields') @override_system_checks([check_user_model]) Loading
tests/createsuperuser/tests.pydeleted 100644 → 0 +0 −55 Original line number Diff line number Diff line from django.contrib.auth import models from django.contrib.auth.management.commands import changepassword from django.core.management import call_command from django.test import TestCase, mock from django.utils.six import StringIO class MultiDBChangepasswordManagementCommandTestCase(TestCase): multi_db = True def setUp(self): self.user = models.User.objects.db_manager('other').create_user(username='joe', password='qwerty') @mock.patch.object(changepassword.Command, '_get_pass', return_value='not qwerty') def test_that_changepassword_command_with_database_option_uses_given_db(self, mock_get_pass): """ Executing the changepassword management command with a database option should operate on the specified DB """ self.assertTrue(self.user.check_password('qwerty')) out = StringIO() call_command('changepassword', username='joe', database='other', stdout=out) command_output = out.getvalue().strip() self.assertEqual( command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'" ) self.assertTrue(models.User.objects.using('other').get(username="joe").check_password("not qwerty")) class MultiDBCreatesuperuserTestCase(TestCase): multi_db = True def test_createsuperuser_command_with_database_option(self): " createsuperuser command should operate on specified DB" new_io = StringIO() call_command( "createsuperuser", interactive=False, username="joe", email="joe@somewhere.org", database='other', stdout=new_io ) command_output = new_io.getvalue().strip() self.assertEqual(command_output, 'Superuser created successfully.') u = models.User.objects.using('other').get(username="joe") self.assertEqual(u.email, 'joe@somewhere.org') new_io.close()