From 273140007ed106ff370c38fe4b0660422e33e59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Sun, 20 Oct 2013 21:42:17 +0200 Subject: [PATCH] Fix url_name_args problems in user and group views. Add tests. --- openslides/participant/views.py | 4 +++ tests/participant/test_views.py | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/openslides/participant/views.py b/openslides/participant/views.py index f11431eb4..452387e90 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -95,6 +95,7 @@ class UserCreateView(CreateView): context_object_name = 'edit_user' form_class = UserCreateForm success_url_name = 'user_overview' + url_name_args = [] def manipulate_object(self, form): self.object.username = gen_username( @@ -125,6 +126,7 @@ class UserUpdateView(UpdateView): context_object_name = 'edit_user' form_class = UserUpdateForm success_url_name = 'user_overview' + url_name_args = [] def get_form_kwargs(self, *args, **kwargs): form_kwargs = super(UserUpdateView, self).get_form_kwargs(*args, **kwargs) @@ -397,6 +399,7 @@ class GroupCreateView(CreateView): model = Group form_class = GroupForm success_url_name = 'user_group_overview' + url_name_args = [] def get(self, request, *args, **kwargs): delete_default_permissions() @@ -413,6 +416,7 @@ class GroupUpdateView(UpdateView): context_object_name = 'group' form_class = GroupForm success_url_name = 'user_group_overview' + url_name_args = [] def get(self, request, *args, **kwargs): delete_default_permissions() diff --git a/tests/participant/test_views.py b/tests/participant/test_views.py index 38ae8b18f..1b57563fe 100644 --- a/tests/participant/test_views.py +++ b/tests/participant/test_views.py @@ -17,6 +17,35 @@ from openslides.participant.models import get_protected_perm, Group, User from openslides.utils.test import TestCase +class UserViews(TestCase): + """ + Tests some views for users. + """ + def setUp(self): + self.admin = User.objects.get(pk=1) + self.client = Client() + self.client.login(username='admin', password='admin') + + def test_create(self): + response = self.client.get('/participant/new/') + self.assertTemplateUsed(response, 'participant/edit.html') + self.assertContains(response, 'New participant') + response = self.client.post('/participant/new/', {'first_name': 'test_name_ho8hui2niz4nohSupahb'}) + self.assertRedirects(response, '/participant/') + + def test_update(self): + response = self.client.get('/participant/1/edit/') + self.assertTemplateUsed(response, 'participant/edit.html') + self.assertContains(response, 'Edit participant') + response = self.client.post( + '/participant/1/edit/', + {'user_name': 'test_name_unaewae5Ir0saijeac2I', + 'first_name': 'test_name_aJi5jaizaVingaeF3Ohj', + 'groups': '4', + 'is_active': 'yes'}) + self.assertRedirects(response, '/participant/') + + class GroupViews(TestCase): """ Tests the detail view for groups and later also the other views. @@ -54,6 +83,20 @@ class GroupViews(TestCase): self.assertEqual(match[1], 'admins_first_name Administrator') self.assertEqual(match[0], 'aWei4ien6Se0vie0xeiv uquahx3Wohtieph9baer') + def test_create(self): + response = self.client.get('/participant/group/new/') + self.assertTemplateUsed(response, 'participant/group_edit.html') + self.assertContains(response, 'New group') + response = self.client.post('/participant/group/new/', {'name': 'test_group_name_Oeli1aeXoobohv8eikai'}) + self.assertRedirects(response, '/participant/group/') + + def test_update(self): + response = self.client.get('/participant/group/1/edit/') + self.assertTemplateUsed(response, 'participant/group_edit.html') + self.assertContains(response, 'Edit group') + response = self.client.post('/participant/group/1/edit/', {'name': 'test_group_name_ahFeicoz5jedie4Fop0U'}) + self.assertRedirects(response, '/participant/group/') + class LockoutProtection(TestCase): """