Ticket #17327: createsuperuser-multidb-tests-moved.diff
File createsuperuser-multidb-tests-moved.diff, 5.3 KB (added by , 13 years ago) |
---|
-
django/contrib/auth/tests/__init__.py
diff --git a/django/contrib/auth/tests/__init__.py b/django/contrib/auth/tests/__init__.py index cd314f6..cc61977 100644
a b from django.contrib.auth.tests.remote_user import (RemoteUserTest, 12 12 from django.contrib.auth.tests.management import ( 13 13 GetDefaultUsernameTestCase, 14 14 ChangepasswordManagementCommandTestCase, 15 MultiDBChangepasswordManagementCommandTestCase,16 MultiDBCreatesuperuserTestCase,17 15 ) 18 16 from django.contrib.auth.tests.models import (ProfileTestCase, NaturalKeysTestCase, 19 17 LoadDataWithoutNaturalKeysTestCase, LoadDataWithNaturalKeysTestCase, -
django/contrib/auth/tests/management.py
diff --git a/django/contrib/auth/tests/management.py b/django/contrib/auth/tests/management.py index 2287ab9..5ce338e 100644
a b class ChangepasswordManagementCommandTestCase(TestCase): 70 70 stdout=self.stdout, 71 71 stderr=self.stderr 72 72 ) 73 74 75 class MultiDBChangepasswordManagementCommandTestCase(TestCase):76 multi_db = True77 78 def setUp(self):79 self.user = models.User.objects.db_manager('other').create_user(username='joe', password='qwerty')80 self.stdout = StringIO()81 82 def tearDown(self):83 self.stdout.close()84 85 def test_that_changepassword_command_with_database_option_uses_given_db(self):86 """87 Executing the changepassword management command with a database option88 should operate on the specified DB89 """90 self.assertTrue(self.user.check_password('qwerty'))91 command = changepassword.Command()92 command._get_pass = lambda *args: 'not qwerty'93 94 command.execute("joe", database='other', stdout=self.stdout)95 command_output = self.stdout.getvalue().strip()96 97 self.assertEquals(command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'")98 self.assertTrue(models.User.objects.using('other').get(username="joe").check_password("not qwerty"))99 100 101 class MultiDBCreatesuperuserTestCase(TestCase):102 multi_db = True103 104 def test_createsuperuser_command_with_database_option(self):105 " createsuperuser command should operate on specified DB"106 new_io = StringIO()107 108 call_command("createsuperuser",109 interactive=False,110 username="joe",111 email="joe@somewhere.org",112 database='other',113 stdout=new_io114 )115 command_output = new_io.getvalue().strip()116 117 self.assertEqual(command_output, 'Superuser created successfully.')118 119 u = models.User.objects.using('other').get(username="joe")120 self.assertEqual(u.email, 'joe@somewhere.org')121 122 new_io.close() -
new file tests/regressiontests/createsuperuser/tests.py
diff --git a/tests/regressiontests/createsuperuser/__init__.py b/tests/regressiontests/createsuperuser/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/createsuperuser/models.py b/tests/regressiontests/createsuperuser/models.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/regressiontests/createsuperuser/tests.py b/tests/regressiontests/createsuperuser/tests.py new file mode 100644 index 0000000..4fdb592
- + 1 from StringIO import StringIO 2 3 from django.contrib.auth import models 4 from django.contrib.auth.management.commands import changepassword 5 from django.core.management import call_command 6 from django.test import TestCase 7 8 9 class MultiDBChangepasswordManagementCommandTestCase(TestCase): 10 multi_db = True 11 12 def setUp(self): 13 self.user = models.User.objects.db_manager('other').create_user(username='joe', password='qwerty') 14 self.stdout = StringIO() 15 16 def tearDown(self): 17 self.stdout.close() 18 19 def test_that_changepassword_command_with_database_option_uses_given_db(self): 20 """ 21 Executing the changepassword management command with a database option 22 should operate on the specified DB 23 """ 24 self.assertTrue(self.user.check_password('qwerty')) 25 command = changepassword.Command() 26 command._get_pass = lambda *args: 'not qwerty' 27 28 command.execute("joe", database='other', stdout=self.stdout) 29 command_output = self.stdout.getvalue().strip() 30 31 self.assertEquals(command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'") 32 self.assertTrue(models.User.objects.using('other').get(username="joe").check_password("not qwerty")) 33 34 35 class MultiDBCreatesuperuserTestCase(TestCase): 36 multi_db = True 37 38 def test_createsuperuser_command_with_database_option(self): 39 " createsuperuser command should operate on specified DB" 40 new_io = StringIO() 41 42 call_command("createsuperuser", 43 interactive=False, 44 username="joe", 45 email="joe@somewhere.org", 46 database='other', 47 stdout=new_io 48 ) 49 command_output = new_io.getvalue().strip() 50 51 self.assertEqual(command_output, 'Superuser created successfully.') 52 53 u = models.User.objects.using('other').get(username="joe") 54 self.assertEqual(u.email, 'joe@somewhere.org') 55 56 new_io.close() 57