From ac4dc0c1925d842f784472d125dbc3c04543874d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sun, 23 Jul 2017 19:57:18 +0100 Subject: [PATCH] tmp --- cof/tests.py | 55 ++++++++++++++++++++++++++++++++++++++++++++---- gestion/views.py | 2 -- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/cof/tests.py b/cof/tests.py index 0f5a89e8..982d5558 100644 --- a/cof/tests.py +++ b/cof/tests.py @@ -1,6 +1,5 @@ from django.contrib.auth.models import Group, Permission, User -from django.contrib.contenttypes.models import ContentType -from django.test import TestCase +from django.test import TestCase, Client from cof.models import CofProfile @@ -12,11 +11,41 @@ def create_cofprofile(username): return CofProfile.objects.create(profile=p) -class TestCofProfile(TestCase): +def create_buro(username, password=None): + buro_group = Group.objects.get(name="cof_buro") + members_group = Group.objects.get(name="cof_members") + u = User.objects.create_user(username=username, password=password) + u.groups.add(buro_group, members_group) + return u + + +class PatchPerms: + """ + Setup permissions since there are not set correctly after the migrations. + Issue fixed by commit b68590ffd7 + """ + @classmethod + def setUpTestData(cls): + print("PatchPerms: remove me!") + buro_group = Group.objects.get(name="cof_buro") + members_group = Group.objects.get(name="cof_members") + member_p = Permission.objects.get( + content_type__app_label="cof", + codename="member" + ) + buro_p = Permission.objects.get( + content_type__app_label="cof", + codename="buro" + ) + buro_group.permissions.add(buro_p) + members_group.permissions.add(member_p) + + +class TestCofProfile(PatchPerms, TestCase): def test_str(self): cofp = create_cofprofile('foo') - # XXX. should by default new CofProfiles be COF members? self.assertFalse(cofp.profile.user.has_perm('cof.member')) + # adding/removing a user from the group should impact the # permission group = Group.objects.get(name='cof_members') @@ -25,3 +54,21 @@ class TestCofProfile(TestCase): cofp = CofProfile.objects.first() self.assertTrue(cofp.profile.user.has_perm('cof.member')) + + +class TestRegistration(PatchPerms, TestCase): + def setUp(self): + self.buro = create_buro("foo", password="foofoo") + self.other = User.objects.create(username="bar") + + def test_get_view(self): + client = Client() + client.login(username="foo", password="foofoo") + urls = [ + "/cof/registration", + "/cof/registration/form/", + "/cof/registration/form/bar?user_type=normal", + "/cof/registration/form/baz?user_type=clipper", + ] + for url in urls: + self.assertEqual(200, client.get(url).status_code) diff --git a/gestion/views.py b/gestion/views.py index b00fb812..bd1803dd 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -153,10 +153,8 @@ class RegistrationView(TemplateView): self.user = get_object_or_404(User, username=username) context = self.get_context_data() - print(vars(self)) return super().render_to_response(context) - # def post(self, request, username): def post(self, request): # the `user_exists` POST parameter indicates that we should expect the # user to be in the database already. Otherwise we return a 404 page.