def test_reminders_checks(self): with self.assertRaises(ValueError): Event('Too many reminders', start=20 / Jul / 2020, reminders=[EmailReminder()] * 6) with self.assertRaises(ValueError): Event('Default and overrides together', start=20 / Jul / 2020, reminders=EmailReminder(), default_reminders=True) e = Event('Almost too many reminders', start=20 / Jul / 2020, reminders=[EmailReminder()] * 5) with self.assertRaises(ValueError): e.add_email_reminder()
def _to_object(json_reminder): method = json_reminder['method'] if method == 'email': return EmailReminder(int(json_reminder['minutes'])) elif method == 'popup': return PopupReminder(int(json_reminder['minutes'])) else: raise ValueError( 'Unexpected method "{}" for a reminder.'.format(method))
def test_to_json(self): reminder_json = {'method': 'email', 'minutes': 55} reminder = EmailReminder(55) self.assertDictEqual(ReminderSerializer.to_json(reminder), reminder_json) reminder_json = {'method': 'popup', 'minutes': 13} reminder = PopupReminder(13) self.assertDictEqual(ReminderSerializer.to_json(reminder), reminder_json) serializer = ReminderSerializer(reminder) self.assertDictEqual(serializer.get_json(), reminder_json)
def test_email_reminder(self): reminder = EmailReminder(34) self.assertEqual(reminder.method, 'email') self.assertEqual(reminder.minutes_before_start, 34)
def test_repr_str(self): reminder = EmailReminder(34) self.assertEqual(reminder.__repr__(), "<EmailReminder - minutes_before_start:34>") self.assertEqual(reminder.__str__(), "EmailReminder - minutes_before_start:34")