Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17327 (again) -- Moved createsuperuser tests added in r17665.

In their new location they won't cause multi-db-related errors when
users run contrib.auh tests together with their application tests.

Thanks brianriley for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17676 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4cd9b4bb5081338176e66dae14115130d50831a9 1 parent c4527b1
Ramiro Morales authored March 10, 2012
2  django/contrib/auth/tests/__init__.py
@@ -12,8 +12,6 @@
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,
51  django/contrib/auth/tests/management.py
@@ -2,7 +2,6 @@
2 2
 
3 3
 from django.contrib.auth import models, management
4 4
 from django.contrib.auth.management.commands import changepassword
5  
-from django.core.management import call_command
6 5
 from django.test import TestCase
7 6
 
8 7
 
@@ -70,53 +69,3 @@ def test_that_max_tries_exits_1(self):
70 69
             stdout=self.stdout,
71 70
             stderr=self.stderr
72 71
         )
73  
-
74  
-
75  
-class MultiDBChangepasswordManagementCommandTestCase(TestCase):
76  
-    multi_db = True
77  
-
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 option
88  
-        should operate on the specified DB
89  
-        """
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 = True
103  
-
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_io
114  
-        )
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()
0  tests/regressiontests/createsuperuser/__init__.py
No changes.
0  tests/regressiontests/createsuperuser/models.py
No changes.
57  tests/regressiontests/createsuperuser/tests.py
... ...
@@ -0,0 +1,57 @@
  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
+

0 notes on commit 4cd9b4b

Please sign in to comment.
Something went wrong with that request. Please try again.