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'])
def test_inital_datetime_correct_when_timezone_given(self): europe = pytz.timezone('Europe/Warsaw') timezone = { 'tz': europe, 'number': 374, } start = europe.localize(datetime.datetime.now()) end = europe.localize(datetime.datetime.now() + datetime.timedelta(minutes=30)) event = Event(start=start, end=end) form = EventForm(instance=event, timezone=timezone, user=self.profile) self.assertAlmostEqual(form.initial['start'], start, delta=datetime.timedelta(seconds=1)) self.assertAlmostEqual(form.initial['end'], end, delta=datetime.timedelta(seconds=1)) self.assertEqual(form.initial['timezone'], timezone['number'])