Verified Commit 2fff7a72 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Add test for RegistrationInformationFieldInline

parent e51fe10d
import datetime
from unittest import mock
from django.contrib.admin import AdminSite
from django.http import HttpResponseRedirect
from django.test import TestCase, RequestFactory
from django.utils import timezone
from events.admin import DoNextModelAdmin
from events.models import Event
from activemembers.models import Committee, CommitteeMembership
from events.admin import DoNextModelAdmin, RegistrationInformationFieldInline
from events.models import Event, RegistrationInformationField
from members.models import Member
class DoNextModelAdminTest(TestCase):
......@@ -56,3 +60,82 @@ class DoNextModelAdminTest(TestCase):
response = self.admin.response_change(request, None)
self.assertIsInstance(response, HttpResponseRedirect)
self.assertEqual('/test', response.url)
class RegistrationInformationFieldInlineTest(TestCase):
fixtures = ['members.json', 'committees.json']
@classmethod
def setUpTestData(cls):
cls.committee = Committee.objects.get(pk=1)
cls.event = Event.objects.create(
pk=1,
organiser=cls.committee,
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(last_name="Wiggers").first()
cls.member.is_superuser = True
cls.member.save()
CommitteeMembership.objects.create(
member=cls.member,
committee=cls.committee
)
RegistrationInformationField.objects.create(
pk=1,
event=cls.event,
type=RegistrationInformationField.BOOLEAN_FIELD,
name_en="test bool",
name_nl="test bool",
required=False
)
RegistrationInformationField.objects.create(
pk=2,
event=cls.event,
type=RegistrationInformationField.INTEGER_FIELD,
name_en="test int",
name_nl="test int",
required=False
)
RegistrationInformationField.objects.create(
pk=3,
event=cls.event,
type=RegistrationInformationField.TEXT_FIELD,
name_en="test text",
name_nl="test text",
required=False
)
def setUp(self):
self.site = AdminSite()
self.inline = RegistrationInformationFieldInline(Event,
self.site)
self.rf = RequestFactory()
def test_get_formset(self):
request = self.rf.get('/admin/events/event/1/change/')
request.user = self.member
formset = self.inline.get_formset(request, None)
self.assertEqual(0, formset.form.declared_fields['order'].initial)
formset = self.inline.get_formset(request, self.event)
self.assertEqual(3, formset.form.declared_fields['order'].initial)
class EventAdminTest(TestCase):
def setUp(self):
pass
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