From a166412f8f0ed6c7e5e3cf31e8db90b0c8aa8964 Mon Sep 17 00:00:00 2001 From: LePetitTim Date: Mon, 24 Jul 2023 17:35:58 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Add=20tests=20mail=20managers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- georiviere/contribution/tests/test_models.py | 27 +++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/georiviere/contribution/tests/test_models.py b/georiviere/contribution/tests/test_models.py index 7cc72add..77a9d4bc 100644 --- a/georiviere/contribution/tests/test_models.py +++ b/georiviere/contribution/tests/test_models.py @@ -1,4 +1,5 @@ -from django.test import TestCase +from django.core import mail +from django.test import override_settings, TestCase from .factories import (ContributionFactory, ContributionPotentialDamageFactory, ContributionQualityFactory, ContributionQuantityFactory, ContributionFaunaFloraFactory, @@ -8,15 +9,26 @@ TypePollutionFactory) -class ContributionCategoriesTest(TestCase): - """Test for Category Contribution model""" +@override_settings(MANAGERS=[("Fake", "fake@fake.fake"), ]) +class ContributionMetaTest(TestCase): + """Test for Contribution model""" + + @override_settings(MANAGERS=["fake@fake.fake"]) + def test_contribution_try_send_report_fail(self): + self.assertEqual(len(mail.outbox), 0) + contribution = ContributionFactory(email_author='mail.mail@mail') + self.assertEqual(str(contribution), "mail.mail@mail") + self.assertEqual(len(mail.outbox), 0) def test_contribution_str(self): + self.assertEqual(len(mail.outbox), 0) contribution = ContributionFactory(email_author='mail.mail@mail') self.assertEqual(str(contribution), "mail.mail@mail") self.assertEqual(contribution.category, "No category") + self.assertEqual(len(mail.outbox), 1) def test_potentialdamage_str(self): + self.assertEqual(len(mail.outbox), 0) potential_damage = ContributionPotentialDamageFactory(type=2) self.assertEqual(str(potential_damage), "Contribution Potential Damage Excessive cutting of riparian forest") contribution = potential_damage.contribution @@ -24,8 +36,10 @@ def test_potentialdamage_str(self): f"{contribution.email_author} " f"Contribution Potential Damage Excessive cutting of riparian forest") self.assertEqual(contribution.category, potential_damage) + self.assertEqual(len(mail.outbox), 1) def test_quality_str(self): + self.assertEqual(len(mail.outbox), 0) quality = ContributionQualityFactory(type=2) self.assertEqual(str(quality), "Contribution Quality Pollution") contribution = quality.contribution @@ -33,8 +47,10 @@ def test_quality_str(self): f"{contribution.email_author} " f"Contribution Quality Pollution") self.assertEqual(contribution.category, quality) + self.assertEqual(len(mail.outbox), 1) def test_quantity_str(self): + self.assertEqual(len(mail.outbox), 0) quantity = ContributionQuantityFactory(type=2) self.assertEqual(str(quantity), "Contribution Quantity In the process of drying out") contribution = quantity.contribution @@ -42,8 +58,10 @@ def test_quantity_str(self): f"{contribution.email_author} " f"Contribution Quantity In the process of drying out") self.assertEqual(contribution.category, quantity) + self.assertEqual(len(mail.outbox), 1) def test_fauna_flora_str(self): + self.assertEqual(len(mail.outbox), 0) fauna_flora = ContributionFaunaFloraFactory(type=2) self.assertEqual(str(fauna_flora), "Contribution Fauna-Flora Heritage species") contribution = fauna_flora.contribution @@ -51,8 +69,10 @@ def test_fauna_flora_str(self): f"{contribution.email_author} " f"Contribution Fauna-Flora Heritage species") self.assertEqual(contribution.category, fauna_flora) + self.assertEqual(len(mail.outbox), 1) def test_landscape_elements_str(self): + self.assertEqual(len(mail.outbox), 0) landscape_elements = ContributionLandscapeElementsFactory(type=2) self.assertEqual(str(landscape_elements), "Contribution Landscape Element Fountain") contribution = landscape_elements.contribution @@ -60,6 +80,7 @@ def test_landscape_elements_str(self): f"{contribution.email_author} " f"Contribution Landscape Element Fountain") self.assertEqual(contribution.category, landscape_elements) + self.assertEqual(len(mail.outbox), 1) def test_severitytype_str(self): severity_type = SeverityTypeTypeFactory(label="Severity type 1")