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

« back to all changes in this revision

Viewing changes to tests/user_commands/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
import sys
 
2
 
 
3
from django.core import management
 
4
from django.core.management import CommandError
 
5
from django.core.management.utils import popen_wrapper
 
6
from django.test import SimpleTestCase
 
7
from django.utils import translation
 
8
from django.utils.six import StringIO
 
9
 
 
10
 
 
11
class CommandTests(SimpleTestCase):
 
12
    def test_command(self):
 
13
        out = StringIO()
 
14
        management.call_command('dance', stdout=out)
 
15
        self.assertEqual(out.getvalue(),
 
16
            "I don't feel like dancing Rock'n'Roll.\n")
 
17
 
 
18
    def test_command_style(self):
 
19
        out = StringIO()
 
20
        management.call_command('dance', style='Jive', stdout=out)
 
21
        self.assertEqual(out.getvalue(),
 
22
            "I don't feel like dancing Jive.\n")
 
23
 
 
24
    def test_language_preserved(self):
 
25
        out = StringIO()
 
26
        with translation.override('fr'):
 
27
            management.call_command('dance', stdout=out)
 
28
            self.assertEqual(translation.get_language(), 'fr')
 
29
 
 
30
    def test_explode(self):
 
31
        """ Test that an unknown command raises CommandError """
 
32
        self.assertRaises(CommandError, management.call_command, ('explode',))
 
33
 
 
34
    def test_system_exit(self):
 
35
        """ Exception raised in a command should raise CommandError with
 
36
            call_command, but SystemExit when run from command line
 
37
        """
 
38
        with self.assertRaises(CommandError):
 
39
            management.call_command('dance', example="raise")
 
40
        old_stderr = sys.stderr
 
41
        sys.stderr = err = StringIO()
 
42
        try:
 
43
            with self.assertRaises(SystemExit):
 
44
                management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
 
45
        finally:
 
46
            sys.stderr = old_stderr
 
47
        self.assertIn("CommandError", err.getvalue())
 
48
 
 
49
    def test_default_en_us_locale_set(self):
 
50
        # Forces en_us when set to true
 
51
        out = StringIO()
 
52
        with translation.override('pl'):
 
53
            management.call_command('leave_locale_alone_false', stdout=out)
 
54
            self.assertEqual(out.getvalue(), "en-us\n")
 
55
 
 
56
    def test_configured_locale_preserved(self):
 
57
        # Leaves locale from settings when set to false
 
58
        out = StringIO()
 
59
        with translation.override('pl'):
 
60
            management.call_command('leave_locale_alone_true', stdout=out)
 
61
            self.assertEqual(out.getvalue(), "pl\n")
 
62
 
 
63
 
 
64
class UtilsTests(SimpleTestCase):
 
65
 
 
66
    def test_no_existent_external_program(self):
 
67
        self.assertRaises(CommandError, popen_wrapper, ['a_42_command_that_doesnt_exist_42'])