Skip to content

Commit

Permalink
✅ Add tests mail managers
Browse files Browse the repository at this point in the history
  • Loading branch information
LePetitTim committed Jul 25, 2023
1 parent eca43c7 commit 9e19089
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions georiviere/contribution/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -8,59 +9,79 @@
TypePollutionFactory, ContributionStatusFactory)


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):
ContributionStatusFactory(label="Informé")
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
self.assertEqual(str(contribution),
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
self.assertEqual(str(contribution),
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
self.assertEqual(str(contribution),
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
self.assertEqual(str(contribution),
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
self.assertEqual(str(contribution),
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")
Expand Down

0 comments on commit 9e19089

Please sign in to comment.