[damned-lies] Add test for leaving team



commit bde51747756e3f492288ff0f3ffe60e37867799d
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu Sep 28 17:08:21 2017 +0200

    Add test for leaving team

 people/views.py                              |    2 ++
 teams/tests.py                               |    8 ++++++++
 templates/people/person_team_membership.html |    4 ++--
 3 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/people/views.py b/people/views.py
index 94b7ef9..ebbbc30 100644
--- a/people/views.py
+++ b/people/views.py
@@ -11,6 +11,7 @@ from django.db import IntegrityError
 from django.http import HttpResponseRedirect
 from django.shortcuts import render, get_object_or_404
 from django.utils.translation import ugettext_lazy, ugettext as _
+from django.views.decorators.http import require_POST
 from django.views.generic import ListView, DetailView, UpdateView
 
 from common.utils import lc_sorted
@@ -96,6 +97,7 @@ def person_team_join(request):
     return render(request, 'people/person_team_join_form.html', context)
 
 @login_required
+@require_POST
 def person_team_leave(request, team_slug):
     person = get_object_or_404(Person, username=request.user.username)
     team = get_object_or_404(Team, name=team_slug)
diff --git a/teams/tests.py b/teams/tests.py
index 2a42c82..ea85e43 100644
--- a/teams/tests.py
+++ b/teams/tests.py
@@ -148,6 +148,14 @@ class TeamTest(TeamsAndRolesTests):
         # Mail should be sent in the target team's language (i.e. French here)
         self.assertIn("rejoindre", mail.outbox[0].body)
 
+    def test_leave_team(self):
+        Role.objects.create(team=self.t, person=self.pn, role='translator')
+        self.client.login(username='jn', password='password')
+        response = self.client.post(reverse('person_team_leave', args=[self.t.name]))
+        self.assertRedirects(response, reverse('person_detail_username', args=[self.pn.username]))
+        self.pn.refresh_from_db()
+        self.assertEqual(self.pn.role_set.count(), 0)
+
     def test_edit_team(self):
         """ Test team edit form """
         edit_url = reverse('team_edit', args = ['fr'], current_app='teams')
diff --git a/templates/people/person_team_membership.html b/templates/people/person_team_membership.html
index 11a0fe1..3dc8578 100644
--- a/templates/people/person_team_membership.html
+++ b/templates/people/person_team_membership.html
@@ -9,9 +9,9 @@
       {% with role.get_role_display as role_name %}
       <li>{% blocktrans with role.team|linked_with:role.team.get_description|safe as team_name %}Member of 
{{ team_name }} team ({{ role_name }}){% endblocktrans %}
           {% if on_own_page %}
-          <form class="inline" method="GET" action="{% url 'person_team_leave' role.team.name %}">
+          <form class="inline" method="post" action="{% url 'person_team_leave' role.team.name %}">
             {% csrf_token %}
-            <input type="submit" value="{% trans "Leave" %}"
+            <input type="submit" value="{% trans 'Leave' %}"
                    onClick="javascript:return confirm('{% trans "Are you sure you want to leave the team?" 
%}')">
           </form>
           {% endif %}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]