Skip to content

Commit

Permalink
Write a test for the fixed email selection behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault committed Sep 30, 2024
1 parent 81d0d7e commit e43d4c9
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion envergo/evaluations/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def test_eval_wizard_all_steps(
data = {
"project_description": "Bla bla bla",
"user_type": "instructor",
"urbanism_department_emails": ["contact@example.org"],
"urbanism_department_emails": ["urbanism@example.org"],
"project_owner_emails": "sponsor1@example.org,sponsor2@example.org",
"project_owner_phone": "0612345678",
}
Expand All @@ -265,11 +265,52 @@ def test_eval_wizard_all_steps(
assert len(callbacks) == 1
mock_post.assert_called_once()
assert len(mailoutbox) == 1
assert mailoutbox[0].to == ["urbanism@example.org"]
assert "Vous recevrez une réponse dans les trois jours ouvrés" in mailoutbox[0].body
evalreq.refresh_from_db()
assert evalreq.submitted is True


def test_eval_wizard_request_confirmation_recipient(
settings,
client,
mailoutbox,
django_capture_on_commit_callbacks,
moulinette_config,
):
"""When the user is the petitioner, the confirmation email is sent to the project owner."""
settings.MATTERMOST_ENDPOINT = "https://example.org/mattermost-endpoint/"

qs = Request.objects.all()
assert qs.count() == 0

url = reverse("request_eval_wizard_step_1")
data = {
"address": "42 rue du Test, 44000 Testville",
"project_description": "Bla bla bla",
}
res = client.post(url, data=data)
url = reverse("request_eval_wizard_step_2")
data = {
"user_type": "petitioner",
"send_eval_to_project_owner": True,
"project_owner_emails": "sponsor1@example.org,sponsor2@example.org",
"project_owner_phone": "0612345678",
}
res = client.post(url, data=data)
assert res.status_code == 302

evalreq = qs[0]
url = reverse("request_eval_wizard_step_3", args=[evalreq.reference])
with django_capture_on_commit_callbacks(execute=True) as callbacks:
res = client.post(url, data=data)
assert res.status_code == 302

assert len(callbacks) == 1
assert len(mailoutbox) == 1
assert mailoutbox[0].to == ["sponsor1@example.org", "sponsor2@example.org"]


@patch("envergo.utils.mattermost.requests.post")
def test_eval_is_only_submitted_once(
mock_post,
Expand Down

0 comments on commit e43d4c9

Please sign in to comment.