Reused a duplicated class in admin_scripts tests.

This commit is contained in:
Tim Graham 2018-09-11 10:49:45 -04:00
parent a0ef6a0e22
commit de8eb07c7a
1 changed files with 10 additions and 17 deletions

View File

@ -1459,6 +1459,13 @@ class ManageTestserver(AdminScriptTestCase):
# user-space commands are correctly handled - in particular, arguments to # user-space commands are correctly handled - in particular, arguments to
# the commands are correctly parsed and processed. # the commands are correctly parsed and processed.
########################################################################## ##########################################################################
class ColorCommand(BaseCommand):
requires_system_checks = False
def handle(self, *args, **options):
self.stdout.write('Hello, world!', self.style.ERROR)
self.stderr.write('Hello, world!', self.style.ERROR)
class CommandTypes(AdminScriptTestCase): class CommandTypes(AdminScriptTestCase):
"Tests for the various types of base command types that can be defined." "Tests for the various types of base command types that can be defined."
@ -1542,16 +1549,9 @@ class CommandTypes(AdminScriptTestCase):
self.assertNotEqual(style.ERROR('Hello, world!'), 'Hello, world!') self.assertNotEqual(style.ERROR('Hello, world!'), 'Hello, world!')
def test_command_color(self): def test_command_color(self):
class Command(BaseCommand):
requires_system_checks = False
def handle(self, *args, **options):
self.stdout.write('Hello, world!', self.style.ERROR)
self.stderr.write('Hello, world!', self.style.ERROR)
out = StringIO() out = StringIO()
err = StringIO() err = StringIO()
command = Command(stdout=out, stderr=err) command = ColorCommand(stdout=out, stderr=err)
call_command(command) call_command(command)
if color.supports_color(): if color.supports_color():
self.assertIn('Hello, world!\n', out.getvalue()) self.assertIn('Hello, world!\n', out.getvalue())
@ -1564,23 +1564,16 @@ class CommandTypes(AdminScriptTestCase):
def test_command_no_color(self): def test_command_no_color(self):
"--no-color prevent colorization of the output" "--no-color prevent colorization of the output"
class Command(BaseCommand):
requires_system_checks = False
def handle(self, *args, **options):
self.stdout.write('Hello, world!', self.style.ERROR)
self.stderr.write('Hello, world!', self.style.ERROR)
out = StringIO() out = StringIO()
err = StringIO() err = StringIO()
command = Command(stdout=out, stderr=err, no_color=True) command = ColorCommand(stdout=out, stderr=err, no_color=True)
call_command(command) call_command(command)
self.assertEqual(out.getvalue(), 'Hello, world!\n') self.assertEqual(out.getvalue(), 'Hello, world!\n')
self.assertEqual(err.getvalue(), 'Hello, world!\n') self.assertEqual(err.getvalue(), 'Hello, world!\n')
out = StringIO() out = StringIO()
err = StringIO() err = StringIO()
command = Command(stdout=out, stderr=err) command = ColorCommand(stdout=out, stderr=err)
call_command(command, no_color=True) call_command(command, no_color=True)
self.assertEqual(out.getvalue(), 'Hello, world!\n') self.assertEqual(out.getvalue(), 'Hello, world!\n')
self.assertEqual(err.getvalue(), 'Hello, world!\n') self.assertEqual(err.getvalue(), 'Hello, world!\n')