diff options
| author | Florian Apolloner <florian@apolloner.eu> | 2013-02-26 09:53:47 +0100 |
|---|---|---|
| committer | Florian Apolloner <florian@apolloner.eu> | 2013-02-26 14:36:57 +0100 |
| commit | 89f40e36246100df6a11316c31a76712ebc6c501 (patch) | |
| tree | 6e65639683ddaf2027908d1ecb1739e0e2ff853b /tests/createsuperuser | |
| parent | b3d2ccb5bfbaf6e7fe1f98843baaa48c35a70950 (diff) | |
Merged regressiontests and modeltests into the test root.
Diffstat (limited to 'tests/createsuperuser')
| -rw-r--r-- | tests/createsuperuser/__init__.py | 0 | ||||
| -rw-r--r-- | tests/createsuperuser/models.py | 0 | ||||
| -rw-r--r-- | tests/createsuperuser/tests.py | 56 |
3 files changed, 56 insertions, 0 deletions
diff --git a/tests/createsuperuser/__init__.py b/tests/createsuperuser/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/createsuperuser/__init__.py diff --git a/tests/createsuperuser/models.py b/tests/createsuperuser/models.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/createsuperuser/models.py diff --git a/tests/createsuperuser/tests.py b/tests/createsuperuser/tests.py new file mode 100644 index 0000000000..7303b1f2e7 --- /dev/null +++ b/tests/createsuperuser/tests.py @@ -0,0 +1,56 @@ +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 +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') + self.stdout = StringIO() + + def tearDown(self): + self.stdout.close() + + def test_that_changepassword_command_with_database_option_uses_given_db(self): + """ + Executing the changepassword management command with a database option + should operate on the specified DB + """ + self.assertTrue(self.user.check_password('qwerty')) + command = changepassword.Command() + command._get_pass = lambda *args: 'not qwerty' + + command.execute("joe", database='other', stdout=self.stdout) + command_output = self.stdout.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() + |
