tmp
This commit is contained in:
parent
75bfe98006
commit
ac4dc0c192
2 changed files with 51 additions and 6 deletions
55
cof/tests.py
55
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)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue