From bf4d12aac24b04056982bf33378e5f6a05cdd314 Mon Sep 17 00:00:00 2001 From: George Katsikas <giorgakis.katsikas@gmail.com> Date: Mon, 9 Oct 2023 13:23:06 +0200 Subject: [PATCH] remove print output from tests --- .../management/commands/mailgun_send_test_email.py | 3 +-- scipost_django/commentaries/tests/test_forms.py | 1 - scipost_django/mails/tests/test_files.py | 1 - scipost_django/mails/tests/test_model_based_backend.py | 10 +++++++++- scipost_django/theses/tests/test_forms.py | 2 -- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/scipost_django/apimail/management/commands/mailgun_send_test_email.py b/scipost_django/apimail/management/commands/mailgun_send_test_email.py index 888eca482..d419e9fc3 100644 --- a/scipost_django/apimail/management/commands/mailgun_send_test_email.py +++ b/scipost_django/apimail/management/commands/mailgun_send_test_email.py @@ -31,8 +31,7 @@ class Command(BaseCommand): auth=("api", settings.MAILGUN_API_KEY), data=data, ) - print(data) - print(response) + except Domain.MultipleObjectsReturned: raise APIMailError("Multiple domains found in mailgun_send_test_email") except Domain.DoesNotExist: diff --git a/scipost_django/commentaries/tests/test_forms.py b/scipost_django/commentaries/tests/test_forms.py index df1e420cb..4a6e195df 100644 --- a/scipost_django/commentaries/tests/test_forms.py +++ b/scipost_django/commentaries/tests/test_forms.py @@ -245,7 +245,6 @@ class TestRequestArxivPreprintForm(TestCase): **{"arxiv_identifier": random_arxiv_identifier_with_version_number}, } ) - print("form.errors:\n\t%s" % form.errors) self.assertTrue(form.is_valid()) def test_identifier_that_already_has_commentary_page_is_invalid(self): diff --git a/scipost_django/mails/tests/test_files.py b/scipost_django/mails/tests/test_files.py index 704bca0cd..2a6a4d686 100644 --- a/scipost_django/mails/tests/test_files.py +++ b/scipost_django/mails/tests/test_files.py @@ -34,4 +34,3 @@ class MailLogFilesTests(TestCase): except Exception as e: self.fail('Mail ("{}") configuration invalid:\n{}'.format(mail_code, e)) i += 1 - print("Tested {} files".format(i)) diff --git a/scipost_django/mails/tests/test_model_based_backend.py b/scipost_django/mails/tests/test_model_based_backend.py index 1ace4af5d..71b3ca589 100644 --- a/scipost_django/mails/tests/test_model_based_backend.py +++ b/scipost_django/mails/tests/test_model_based_backend.py @@ -1,3 +1,5 @@ +from contextlib import redirect_stdout +from io import StringIO from django.core.management import call_command from django.test import TestCase @@ -87,7 +89,13 @@ class ModelEmailBackendTests(TestCase): mail_util.send_mail() mail_log = MailLog.objects.last() - call_command("send_mails", id=mail_log.id) + + # Capture stdout to check for command output. + stdout = StringIO() + with redirect_stdout(stdout): + call_command("send_mails", id=mail_log.id) + + self.assertIn("Sent 1 mails.", stdout.getvalue()) mail_log.refresh_from_db() self.assertNotEqual(mail_log.body, "") diff --git a/scipost_django/theses/tests/test_forms.py b/scipost_django/theses/tests/test_forms.py index 773e83f81..7c6052720 100644 --- a/scipost_django/theses/tests/test_forms.py +++ b/scipost_django/theses/tests/test_forms.py @@ -50,7 +50,5 @@ class TestRequestThesisLink(TestCase): form = RequestThesisLinkForm(form_data, request=self.request) # Check if the user is properly saved to the new ThesisLink as `requested_by` - print(form.is_valid()) - print(form.errors) thesislink = form.save() self.assertEqual(thesislink.requested_by, self.contributor) -- GitLab