Skip to content

Commit

Permalink
adding message to user
Browse files Browse the repository at this point in the history
  • Loading branch information
etchegom committed Jan 9, 2025
1 parent 0a1c534 commit 88613ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 13 additions & 5 deletions recoco/apps/tasks/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import datetime
import uuid
from unittest.mock import ANY, patch

import pytest
from actstream.models import Action
Expand Down Expand Up @@ -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
)
Expand Down
5 changes: 5 additions & 0 deletions recoco/apps/tasks/views/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))

Expand Down

0 comments on commit 88613ad

Please sign in to comment.