Unverified Commit 46250795 authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Implement tests for events.views.admin_details

parent 84402470
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
"description_nl": "Test", "description_nl": "Test",
"description_en": "Test", "description_en": "Test",
"photo": "Thom_Wiggers.jpg", "photo": "Thom_Wiggers.jpg",
"active": "True",
"permissions": [ "permissions": [
25, 25,
26, 26,
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
"fields": { "fields": {
"name_nl": "testcie2", "name_nl": "testcie2",
"name_en": "testcie2", "name_en": "testcie2",
"active": "True",
"description_nl": "testdesc2", "description_nl": "testdesc2",
"description_en": "testdesc2", "description_en": "testdesc2",
"photo": "Thom_Wiggers_4YRoxV3.jpg", "photo": "Thom_Wiggers_4YRoxV3.jpg",
...@@ -33,6 +35,7 @@ ...@@ -33,6 +35,7 @@
"fields": { "fields": {
"name_nl": "testbestuur1", "name_nl": "testbestuur1",
"name_en": "testboard1", "name_en": "testboard1",
"active": "True",
"description_nl": "testdesc1", "description_nl": "testdesc1",
"description_en": "testdesc1", "description_en": "testdesc1",
"since": "1990-09-01", "since": "1990-09-01",
......
import datetime import datetime
from django.contrib.auth.models import Permission
from django.test import Client, TestCase from django.test import Client, TestCase
from django.utils import timezone from django.utils import timezone
from activemembers.models import Committee, CommitteeMembership
from events.models import Event, Registration, RegistrationInformationField from events.models import Event, Registration, RegistrationInformationField
from members.models import Member from members.models import Member
class AdminTest(TestCase):
"""Tests for admin views"""
fixtures = ['members.json', 'committees.json']
@classmethod
def setUpTestData(cls):
cls.event = Event.objects.create(
pk=1,
title_nl='testevenement',
title_en='testevent',
description_en='desc',
description_nl='besch',
published=True,
start=(timezone.now() + datetime.timedelta(hours=1)),
end=(timezone.now() + datetime.timedelta(hours=2)),
location_en='test location',
location_nl='test locatie',
map_location='test map location',
price=0.00,
fine=0.00)
cls.member = Member.objects.filter(user__last_name="Wiggers").first()
cls.permission_change_event = Permission.objects.get(
content_type__model='event',
codename='change_event')
cls.member.user.user_permissions.add(cls.permission_change_event)
cls.member.user.is_superuser = False
cls.member.user.save()
cls.committee = Committee.objects.get(pk=1)
def setUp(self):
self.client.force_login(self.member.user)
def _remove_event_permission(self):
self.member.user.user_permissions.remove(self.permission_change_event)
def test_admin_details_need_change_event_access(self):
"""I need the event.change_event permission to do stuff"""
self._remove_event_permission()
response = self.client.get('/events/admin/1/')
self.assertEqual(302, response.status_code)
self.assertTrue(response.url.startswith('/login/'))
def test_admin_details_no_organiser_allowed_access(self):
"""If an event has no organiser, then I should be allowed access"""
response = self.client.get('/events/admin/1/')
self.assertEqual(200, response.status_code)
def test_admin_details_organiser_denied(self):
self.event.organiser = self.committee
self.event.save()
response = self.client.get('/events/admin/1/')
self.assertEqual(403, response.status_code)
def test_admin_details_organiser_allowed(self):
self.event.organiser = self.committee
CommitteeMembership.objects.create(
member=self.member,
committee=self.committee)
self.event.save()
response = self.client.get('/events/admin/1/')
self.assertEqual(200, response.status_code)
class RegistrationTest(TestCase): class RegistrationTest(TestCase):
"""Tests for registration view""" """Tests for registration view"""
......
Supports Markdown
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