Commit bde51747 authored by Claude Paroz's avatar Claude Paroz

Add test for leaving team

parent dfc9e052
......@@ -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)
......
......@@ -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')
......
......@@ -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 %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment