class ReminderTest(unittest.TestCase): def setUp(self): session = mo.set_up_connection(DRIVER_NAME, CONNECTIONSTRING) self.serv = AppService(session) self.task = self.serv.create_task(user=TEST_USER, name=TEST_NAME) self.reminder = self.serv.create_reminder(task_id=self.task.id, user=TEST_USER, date=TEST_DATE_THIRD) def test_create_reminder(self): self.assertTrue(self.reminder.task, self.task) self.assertTrue(self.reminder.date, TEST_DATE_FIRST) self.serv.update_task(user=TEST_USER, task_id=self.task.id, end_date=TEST_DATE_THIRD) with self.assertRaises(ValueError): reminder = self.serv.create_reminder(task_id=self.task.id, user=TEST_USER, date=TEST_DATE_FIRST) def test_delete_reminder(self): with self.assertRaises(ex.ObjectNotFound): self.serv.delete_reminder(user=TEST_USER, reminder_id=TEST_RANDOM_INT) self.serv.delete_reminder(user=TEST_USER, reminder_id=self.reminder.id) def test_update_reminder(self): with self.assertRaises(ex.ObjectNotFound): self.serv.update_reminder(user=TEST_USER, reminder_id=TEST_RANDOM_INT) reminder = self.serv.update_reminder(user=TEST_USER, reminder_id=self.reminder.id, date=TEST_DATE_THIRD) self.assertEqual(reminder.date, TEST_DATE_THIRD) with self.assertRaises(ValueError): reminder = self.serv.update_reminder(user=TEST_USER, reminder_id=self.reminder.id, date=TEST_DATE_FIRST)
def reminder_handler(service: AppService, namespace): if namespace.action == 'create': reminder = service.create_reminder(user=namespace.user, task_id=namespace.task_id, date=namespace.date) print('Created reminder:') print(reminder) elif namespace.action == 'show': reminder_show_handler(service, namespace) elif namespace.action == 'edit': reminder = service.update_reminder(user=namespace.user, reminder_id=namespace.reminder_id, date=namespace.date) print('Updated reminder:') print(reminder) elif namespace.action == 'delete': service.delete_reminder(user=namespace.user, reminder_id=namespace.reminder_id) print(f'Reminder(ID={namespace.reminder_id}) has been deleted')