~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/createsuperuser/tests.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.contrib.auth import models
 
2
from django.contrib.auth.management.commands import changepassword
 
3
from django.core.management import call_command
 
4
from django.test import TestCase
 
5
from django.utils.six import StringIO
 
6
 
 
7
 
 
8
class MultiDBChangepasswordManagementCommandTestCase(TestCase):
 
9
    multi_db = True
 
10
 
 
11
    def setUp(self):
 
12
        self.user = models.User.objects.db_manager('other').create_user(username='joe', password='qwerty')
 
13
        self.stdout = StringIO()
 
14
 
 
15
    def tearDown(self):
 
16
        self.stdout.close()
 
17
 
 
18
    def test_that_changepassword_command_with_database_option_uses_given_db(self):
 
19
        """
 
20
        Executing the changepassword management command with a database option
 
21
        should operate on the specified DB
 
22
        """
 
23
        self.assertTrue(self.user.check_password('qwerty'))
 
24
        command = changepassword.Command()
 
25
        command._get_pass = lambda *args: 'not qwerty'
 
26
 
 
27
        command.execute("joe", database='other', stdout=self.stdout)
 
28
        command_output = self.stdout.getvalue().strip()
 
29
 
 
30
        self.assertEqual(command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'")
 
31
        self.assertTrue(models.User.objects.using('other').get(username="joe").check_password("not qwerty"))
 
32
 
 
33
 
 
34
class MultiDBCreatesuperuserTestCase(TestCase):
 
35
    multi_db = True
 
36
 
 
37
    def test_createsuperuser_command_with_database_option(self):
 
38
        " createsuperuser command should operate on specified DB"
 
39
        new_io = StringIO()
 
40
 
 
41
        call_command("createsuperuser",
 
42
            interactive=False,
 
43
            username="joe",
 
44
            email="joe@somewhere.org",
 
45
            database='other',
 
46
            stdout=new_io
 
47
        )
 
48
        command_output = new_io.getvalue().strip()
 
49
 
 
50
        self.assertEqual(command_output, 'Superuser created successfully.')
 
51
 
 
52
        u = models.User.objects.using('other').get(username="joe")
 
53
        self.assertEqual(u.email, 'joe@somewhere.org')
 
54
 
 
55
        new_io.close()
 
56