diff options
| author | Baptiste Mispelon <bmispelon@gmail.com> | 2014-02-17 04:24:34 +0100 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2014-02-17 04:58:31 +0100 |
| commit | 116d39842dab2569013856e9f3701a7cb6554f09 (patch) | |
| tree | e647016ebd37ae96e0d87250335f63a5068013a4 /tests/user_commands | |
| parent | 3c547a423f5394d816b5a942570abd904f07bfba (diff) | |
Added the possibility to pass a stdin object to a management command.
This makes testing certain features easier.
Thanks to AeroNotix for the original patch.
Diffstat (limited to 'tests/user_commands')
| -rw-r--r-- | tests/user_commands/tests.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py index bf555e66b9..e184d0e6df 100644 --- a/tests/user_commands/tests.py +++ b/tests/user_commands/tests.py @@ -2,6 +2,7 @@ import sys from django.core import management from django.core.management import CommandError +from django.core.management.base import BaseCommand from django.core.management.utils import popen_wrapper from django.test import SimpleTestCase from django.utils import translation @@ -60,6 +61,32 @@ class CommandTests(SimpleTestCase): management.call_command('leave_locale_alone_true', stdout=out) self.assertEqual(out.getvalue(), "pl\n") + def test_passing_stdin(self): + """ + You can pass a stdin object to a command's options and it should be + available on self.stdin. + """ + class CustomCommand(BaseCommand): + def handle(self, *args, **kwargs): + pass + + sentinel = object() + command = CustomCommand() + command.execute(stdin=sentinel, stdout=StringIO()) + self.assertIs(command.stdin, sentinel) + + def test_passing_stdin_default(self): + """ + If stdin is not passed as an option, the default should be sys.stdin. + """ + class CustomCommand(BaseCommand): + def handle(self, *args, **kwargs): + return 'OK' + + command = CustomCommand() + command.execute(stdout=StringIO()) + self.assertIs(command.stdin, sys.stdin) + class UtilsTests(SimpleTestCase): |
