def test_blank_data(self): form = EventForm(user=self.profile, data={}) self.assertFalse(form.is_valid(user=self.profile)) fields = ['title', 'start', 'end', 'timezone', 'calendar'] for field in fields: self.assertIn( "This field is required.", form.errors[field] )
def test_hours_skipped_in_validation_when_all_day_event(self): form = EventForm(data={ 'calendar': 1, 'title': 'Episode 9', 'desc': 'Bla', 'all_day': True, 'start': '2016-12-13 15:19', 'end': '2016-12-13 14:13', 'timezone': '374' }, user=self.profile) self.assertTrue(form.is_valid(user=self.profile))
def test_no_description_is_valid(self): form = EventForm(data={ 'calendar': 1, 'title': 'Episode 9', 'desc': '', 'all_day': True, 'start': '2016-12-13 15:19', 'end': '2016-12-13 16:13', 'timezone': '374' }, user=self.profile) self.assertTrue(form.is_valid(user=self.profile))
def test_validation_works_when_hours_skipped(self): form = EventForm(data={ 'calendar': 1, 'title': 'Episode 9', 'desc': 'Bla', 'all_day': True, 'start': '2016-12-13 15:19', 'end': '2016-12-12 16:13', 'timezone': '374' }, user=self.profile) self.assertFalse(form.is_valid(user=self.profile)) self.assertIn(END_BEFORE_START_ERROR, form.non_field_errors())
def test_end_before_start_not_valid(self): form = EventForm(data={ 'calendar': 1, 'title': 'Episode 9', 'desc': 'Bla', 'all_day': False, 'start': '2016-12-13 15:19', 'end': '2016-12-11 16:13', 'timezone': '374' }, user=self.profile) self.assertFalse(form.is_valid(user=self.profile)) self.assertIn(END_BEFORE_START_ERROR, form.non_field_errors())
def test_checks_timezone(self): tz_len = len(pytz.common_timezones_set) form = EventForm(data={ 'calendar': 1, 'title': 'Episode 9', 'desc': 'Bla', 'all_day': True, 'start': '2016-12-13 15:19', 'end': '2016-12-12 16:13', 'timezone': str(tz_len + 10), }, user=self.profile) self.assertFalse(form.is_valid(user=self.profile)) self.assertIn(WRONG_TIMEZONE_ERROR, form.errors['timezone'])