def test_invalid_date(self): data = { 'description': u'', 'title': u'', 'title_not_announced': u'1', 'location': u'', 'department_suggest': u'', 'start': u'94872394', 'topics': u'', 'speaker_suggest': u'', 'location_suggest': u'', 'department_organiser': u'', 'speakers': u'', 'booking_type': u'nr', 'audience': u'public', 'topic_suggest': u'', 'status': models.EVENT_IN_PREPARATION, 'end': VALID_DATE_STRING, } form = forms.EventForm(data) self.assertEquals(form.is_valid(), False, "blanked form should not validate") errors = form.errors.as_data() logging.info("form errors: %s", errors) self.assertIn('start', errors) self.assertEquals(len(errors), 1)
def test_all_fields_blanked(self): data = { 'description': u'', 'title': u'', 'location': u'', 'department_suggest': u'', 'start': u'', 'topics': u'', 'speaker_suggest': u'', 'location_suggest': u'', 'department_organiser': u'', 'speakers': u'', 'topic_suggest': u'', 'end': u'', } form = forms.EventForm(data) self.assertEquals(form.is_valid(), False, "blanked form should not validate") errors = form.errors.as_data() logging.info("form errors: %s", errors) self.assertEquals(len(errors), 5) self.assertIn('booking_type', errors) self.assertIn('status', errors) self.assertIn('start', errors) self.assertIn('end', errors) self.assertIn('__all__', errors)
def test_empty(self): form = forms.EventForm({}) self.assertEquals(form.is_valid(), False, "empty form should not validate") errors = form.errors.as_data() logging.info("form errors: %s", errors) self.assertEquals(len(errors), 5) self.assertIn('booking_type', errors) self.assertIn('start', errors) self.assertIn('end', errors) self.assertIn('status', errors) self.assertIn('__all__', errors)
def test_title_not_announced_true_title_blank(self): data = { 'title': '', 'title_not_announced': 'true', } form = forms.EventForm(data) errors = form.errors.as_data() logging.info("form errors: %s", errors) self.assertNotIn("Either provide the Title or mark it as TBA", form.errors.get('__all__', [])) self.assertNotIn('title', form.errors) self.assertNotIn('title_not_announced', form.errors)
def test_happy(self): data = { 'description': u'', 'title': u'', 'title_not_announced': u'1', 'location': u'', 'department_suggest': u'', 'start': VALID_DATE_STRING, 'topics': u'', 'speaker_suggest': u'', 'location_suggest': u'', 'department_organiser': u'', 'speakers': u'', 'booking_type': u'nr', 'audience': u'public', 'topic_suggest': u'', 'status': models.EVENT_IN_PREPARATION, 'end': VALID_DATE_STRING, } form = forms.EventForm(data) errors = form.errors.as_data() logging.info("form errors: %s", errors) self.assertTrue(form.is_valid(), "form should validate")