From 88613adf276d0ee87566b40409fa7f3ce4b258ba Mon Sep 17 00:00:00 2001 From: Etchegoyen Matthieu Date: Thu, 9 Jan 2025 09:37:30 +0100 Subject: [PATCH] adding message to user --- recoco/apps/tasks/tests/test_tasks.py | 18 +++++++++++++----- recoco/apps/tasks/views/tasks.py | 5 +++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/recoco/apps/tasks/tests/test_tasks.py b/recoco/apps/tasks/tests/test_tasks.py index abfa431ec..224c95e5d 100644 --- a/recoco/apps/tasks/tests/test_tasks.py +++ b/recoco/apps/tasks/tests/test_tasks.py @@ -9,6 +9,7 @@ import datetime import uuid +from unittest.mock import ANY, patch import pytest from actstream.models import Action @@ -156,15 +157,22 @@ def test_task_recommendation_is_deleted(request, client): recommendation_id = recommendation.pk - with login(client, groups=["example_com_staff"]): - response = client.post( - reverse("projects-task-recommendation-delete", args=(recommendation_id,)), - data={"resource": recommendation.resource.pk}, - ) + with patch("recoco.apps.tasks.views.tasks.messages") as mock_messages: + with login(client, groups=["example_com_staff"]): + response = client.post( + reverse( + "projects-task-recommendation-delete", args=(recommendation_id,) + ), + data={"resource": recommendation.resource.pk}, + ) assert response.status_code == 302 assertRedirects(response, reverse("projects-task-recommendation-list")) + mock_messages.success.assert_called_once_with( + request=ANY, message="Le pré-fléchage a bien été supprimé" + ) + assert ( models.TaskRecommendation.on_site.filter(pk=recommendation_id).exists() is False ) diff --git a/recoco/apps/tasks/views/tasks.py b/recoco/apps/tasks/views/tasks.py index b5c4c7dfa..5bb7a2834 100644 --- a/recoco/apps/tasks/views/tasks.py +++ b/recoco/apps/tasks/views/tasks.py @@ -7,6 +7,7 @@ created : 2021-05-26 15:56:20 CEST """ +from django.contrib import messages from django.contrib.auth.decorators import login_required from django.http import Http404, HttpResponseForbidden from django.shortcuts import get_object_or_404, redirect, render @@ -390,6 +391,10 @@ def task_recommendation_delete(request, recommendation_id): models.TaskRecommendation, site=request.site, pk=recommendation_id ) task_recommendation.delete() + messages.success( + request=request, + message="Le pré-fléchage a bien été supprimé", + ) return redirect(reverse("projects-task-recommendation-list"))