def test_register_permit_contact(self): form = AttendeeRegistrationForm( data={ 'email': '*****@*****.**', 'password1': 's3cr3t', 'password2': 's3cr3t', 'accept_general_contact': 'checked', 'accept_devday_contact': 'checked' }) valid = form.is_valid() self.assertTrue(valid, form.errors) request = HttpRequest() view = AttendeeRegistrationView(request=request) user = view.register(form) now = timezone.now() self.assertIsInstance(user, DevDayUser) self.assertIsNotNone(user.contact_permission_date) self.assertLessEqual(user.contact_permission_date, now) self.assertFalse(user.is_active) attendees = user.attendees self.assertEqual(attendees.count(), 1) attendee = attendees.first() self.assertIsInstance(attendee, Attendee) self.assertEqual(len(mail.outbox), 1)
def test_register_minimum_fields(self): form = AttendeeRegistrationForm( data={ 'email': '*****@*****.**', 'password1': 's3cr3t', 'password2': 's3cr3t' }) valid = form.is_valid() self.assertTrue(valid, form.errors) request = HttpRequest() view = AttendeeRegistrationView(request=request) user = view.register(form) self.assertIsInstance(user, DevDayUser) self.assertIsNone(user.contact_permission_date) self.assertFalse(user.is_active) attendees = user.attendees self.assertEqual(attendees.count(), 1) attendee = attendees.first() self.assertIsInstance(attendee, Attendee) self.assertIsNotNone(attendee.event) self.assertEqual(len(mail.outbox), 1)
def test_form_save_no_commit(self): form = AttendeeRegistrationForm( event=self.event, data={ "email": "*****@*****.**", "password1": "s3cr3t", "password2": "s3cr3t", }, ) user = form.save(commit=False) self.assertIsNone(user.id) self.assertFalse(user.is_active) self.assertIsNone(user.contact_permission_date) self.assertTrue(user.check_password("s3cr3t"))
def test_init_creates_form_helper(self): form = AttendeeRegistrationForm(event=self.event) self.assertIsInstance(form.helper, FormHelper) self.assertEqual(form.helper.form_action, "/{}/attendee/register/".format(self.event.slug)) self.assertEqual(form.helper.form_method, "post") self.assertTrue(form.helper.html5_required)
def test_init_creates_layout(self): form = AttendeeRegistrationForm(event=self.event) self.assertIsInstance(form.helper.layout, Layout) layout_fields = [name for [_, name] in form.helper.layout.get_field_names()] self.assertListEqual( layout_fields, ["email", "password1", "password2", "accept_general_contact"] )
def test_init_creates_layout(self): form = AttendeeRegistrationForm() self.assertIsInstance(form.helper.layout, Layout) layout_fields = [name for [_, name] in form.helper.layout.get_field_names()] self.assertListEqual( layout_fields, ['email', 'first_name', 'last_name', 'password1', 'password2', 'position', 'organization', 'twitter_handle', 'source', 'accept_general_contact'] )
def test_init_creates_form_helper(self): form = AttendeeRegistrationForm() self.assertIsInstance(form.helper, FormHelper) self.assertEqual(form.helper.form_action, '/attendee/register/') self.assertEqual(form.helper.form_method, 'post') self.assertTrue(form.helper.html5_required)
def test_get_user_form(self): form = AttendeeRegistrationForm() self.assertIsInstance(form.get_user_form(), DevDayRegistrationForm)