From f9ba59859af7364e267dcc8d49c3cacf70e1271a Mon Sep 17 00:00:00 2001 From: viliambalaz Date: Thu, 21 Jan 2021 22:18:05 +0100 Subject: [PATCH] #342 Remove sys.stdin.isatty --- .../management/commands/attachment_anonymization.py | 6 +++--- .../apps/anonymization/tests/test_management_commands.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/chcemvediet/apps/anonymization/management/commands/attachment_anonymization.py b/chcemvediet/apps/anonymization/management/commands/attachment_anonymization.py index 0c3367b55..ae363f23e 100644 --- a/chcemvediet/apps/anonymization/management/commands/attachment_anonymization.py +++ b/chcemvediet/apps/anonymization/management/commands/attachment_anonymization.py @@ -73,10 +73,10 @@ def handle(self, *args, **options): content = file.read() except IOError as e: raise CommandError(u'Could not open file: {}.'.format(e)) - elif not sys.stdin.isatty(): - content = sys.stdin.read() else: - raise CommandError(u'Missing content source.') + content = sys.stdin.read() + if not content: + raise CommandError(u'No content given.') attachments_finalization.delete() AttachmentFinalization.objects.create( diff --git a/chcemvediet/apps/anonymization/tests/test_management_commands.py b/chcemvediet/apps/anonymization/tests/test_management_commands.py index 26526ad26..7a1ce7d87 100644 --- a/chcemvediet/apps/anonymization/tests/test_management_commands.py +++ b/chcemvediet/apps/anonymization/tests/test_management_commands.py @@ -62,7 +62,9 @@ def test_content_is_read_from_stdin_if_file_argument_is_omitted(self): self.assertEqual(attachment_finalization.file.read(), u'Content from stdin.') def test_file_argument_and_stdin_together_may_not_be_omitted(self): - with self.assertRaisesMessage(CommandError, u'Missing content source.'): + self.addCleanup(setattr, sys, u'stdin', sys.stdin) + sys.stdin = StringIO(u'') + with self.assertRaisesMessage(CommandError, u'No content given.'): call_command(u'attachment_anonymization', self.attachment.pk) def test_preferred_content_source_is_file(self):