def test_set_reminder_stores_reminder_for_current_user(self): self.login(self.regular_user) self.task.set_reminder(ReminderOneDayBefore()) self.assertEqual(ReminderOneDayBefore(), self.task.get_reminder()) self.assertIsNone( self.task.get_reminder(user_id=self.dossier_responsible.getId()))
def test_clear_reminder_removes_existing_reminder(self): self.login(self.regular_user) self.task.set_reminder(ReminderOneDayBefore()) self.task.set_reminder(ReminderOneDayBefore(), user_id=self.dossier_responsible.getId()) self.task.clear_reminder() self.assertIsNone(self.task.get_reminder()) self.assertEqual( ReminderOneDayBefore(), self.task.get_reminder(user_id=self.dossier_responsible.getId()))
def test_calculate_trigger_date(self): deadline = date(2018, 7, 1) # 01. July 2018, Sunday self.assertEqual( date(2018, 7, 1), # Sunday ReminderSameDay().calculate_trigger_date(deadline)) self.assertEqual( date(2018, 6, 30), # Saturday ReminderOneDayBefore().calculate_trigger_date(deadline)) self.assertEqual( date(2018, 6, 24), # Sunday ReminderOneWeekBefore().calculate_trigger_date(deadline)) self.assertEqual( date(2018, 6, 25), # Monday ReminderBeginningOfWeek().calculate_trigger_date(deadline)) deadline = date(2018, 7, 2) # 02. July 2018, Monday self.assertEqual( date(2018, 7, 2), # Monday ReminderBeginningOfWeek().calculate_trigger_date(deadline)) self.assertEqual( date(2018, 12, 30), ReminderOnDate( {'date': date(2018, 12, 30)} ).calculate_trigger_date(deadline))
def test_reminders_can_be_serialized(self): self.assertEqual( {'option_type': 'same_day', 'option_title': 'At the morging of the deadline', 'params': {}}, ReminderSameDay().serialize()) self.assertEqual( {'option_type': 'one_day_before', 'option_title': 'One day before deadline', 'params': {}}, ReminderOneDayBefore().serialize()) self.assertEqual( {'option_type': 'one_week_before', 'option_title': 'One week before deadline', 'params': {}}, ReminderOneWeekBefore().serialize()) self.assertEqual( {'option_type': 'beginning_of_week', 'option_title': 'At the beginning of the week of the deadline', 'params': {}}, ReminderBeginningOfWeek().serialize()) self.assertEqual( {'option_type': 'on_date', 'option_title': 'On a specific date', 'params': {'date': date(2018, 12, 30)}}, ReminderOnDate({'date': date(2018, 12, 30)}).serialize())
def test_post_raises_409_when_adding_already_set_reminder(self, browser): self.login(self.regular_user, browser) self.task.set_reminder(ReminderOneDayBefore()) payload = {'option_type': ReminderOneDayBefore.option_type} with browser.expect_http_error(409): browser.open( self.task.absolute_url() + '/@reminder', data=json.dumps(payload), method='POST', headers=self.http_headers, ) self.assertEqual( ReminderOneDayBefore(), self.task.get_reminder())
def test_delete_removes_task_reminder(self, browser): self.login(self.regular_user, browser) self.task.set_reminder(ReminderOneDayBefore()) self.assertEqual( ReminderOneDayBefore(), self.task.get_reminder()) browser.open( self.task.absolute_url() + '/@reminder', method='DELETE', headers=self.http_headers, ) self.assertEqual(204, browser.status_code) self.assertIsNone( self.task.get_reminder())
def test_serialization_deserialization_rountrip(self): self.assertEqual( ReminderSameDay(), Reminder.deserialize(ReminderSameDay().serialize())) self.assertEqual( ReminderOneDayBefore(), Reminder.deserialize(ReminderOneDayBefore().serialize())) self.assertEqual( ReminderOneWeekBefore(), Reminder.deserialize(ReminderOneWeekBefore().serialize())) self.assertEqual( ReminderBeginningOfWeek(), Reminder.deserialize(ReminderBeginningOfWeek().serialize())) self.assertEqual( ReminderOnDate({'date': date(2018, 12, 30)}), Reminder.deserialize( ReminderOnDate({'date': date(2018, 12, 30)}).serialize()))
def test_reminders_of_responsbile_gets_cleared(self, browser): self.login(self.regular_user, browser) self.seq_subtask_1.set_reminder(ReminderOneDayBefore(), user_id=self.regular_user.id) self.assertEqual([self.regular_user.id], self.seq_subtask_1.get_reminders().keys()) browser.open(self.seq_subtask_1, view='accept_task_workflow_transition') self.assertEqual('OK', browser.contents) self.assertEqual({}, self.seq_subtask_1.get_reminders())
def test_create_reminder_notifications_adds_notifications_for_each_reminder_if_reaching_remind_day( self): self.login(self.administrator) today = date.today() self.task.responsible = self.dossier_responsible.getId() self.task.issuer = self.regular_user.getId() self.task.deadline = today self.subtask.responsible = self.dossier_responsible.getId() self.subtask.issuer = self.regular_user.getId() self.subtask.deadline = today + timedelta(days=1) self.set_workflow_state('task-state-open', self.subtask) self.sequential_task.responsible = self.dossier_responsible.getId() self.sequential_task.issuer = self.regular_user.getId() self.sequential_task.deadline = today + timedelta(days=5) with self.login(self.regular_user): self.task.set_reminder(ReminderSameDay()) self.task.sync() self.sequential_task.set_reminder(ReminderSameDay()) self.sequential_task.sync() with self.login(self.dossier_responsible): self.subtask.set_reminder(ReminderOneDayBefore()) self.subtask.sync() with freeze( pytz.UTC.localize(datetime.combine(today, datetime.min.time()))): create_reminder_notifications() task_reminder_activities = Activity.query.filter( Activity.kind == TaskReminderActivity.kind) self.assertEqual(2, task_reminder_activities.count()) notifications = [] [ notifications.extend(activity.notifications) for activity in task_reminder_activities ] self.assertEqual(2, len(notifications)) self.assertItemsEqual( [self.regular_user.getId(), self.dossier_responsible.getId()], [notification.userid for notification in notifications])
def test_extract_all_task_reminders_for_all_responsible_representatives( self): self.login(self.regular_user) self.task.set_reminder(ReminderOneDayBefore(), user_id=self.regular_user.id) self.task.set_reminder(ReminderOneDayBefore(), user_id=self.dossier_responsible.id) self.task.set_reminder(ReminderOneDayBefore(), user_id=self.secretariat_user.id) # single user collector = getAdapter(self.task, IDataCollector, name='task-reminders') self.assertEqual( { self.regular_user.id: { 'option_type': ReminderOneDayBefore.option_type, 'option_title': 'One day before deadline', 'params': {} } }, collector.extract()) # inbox group self.task.responsible = 'inbox:fa' collector = getAdapter(self.task, IDataCollector, name='task-reminders') self.assertEqual( { self.secretariat_user.id: { 'option_type': ReminderOneDayBefore.option_type, 'option_title': 'One day before deadline', 'params': {} } }, collector.extract())
def test_patch_updates_set_reminder(self, browser): self.login(self.regular_user, browser) self.task.set_reminder(ReminderOneDayBefore()) payload = {'option_type': ReminderOneWeekBefore.option_type} browser.open( self.task.absolute_url() + '/@reminder', data=json.dumps(payload), method='PATCH', headers=self.http_headers, ) self.assertEqual(204, browser.status_code) self.assertEqual( ReminderOneWeekBefore(), self.task.get_reminder())
def test_post_adds_task_reminder(self, browser): self.login(self.regular_user, browser) payload = {'option_type': ReminderOneDayBefore.option_type} self.assertIsNone( self.task.get_reminder()) browser.open( self.task.absolute_url() + '/@reminder', data=json.dumps(payload), method='POST', headers=self.http_headers, ) self.assertEqual(204, browser.status_code) self.assertEqual( ReminderOneDayBefore(), self.task.get_reminder())
def test_init_state_selected_option(self, browser): self.login(self.regular_user, browser=browser) browser.visit(self.task, view='tabbedview_view-overview') init_state = self._get_init_state(browser) selected_option = filter(lambda x: x.get('selected'), init_state.get('reminder_options')) self.assertEqual(1, len(selected_option)) self.assertEqual('no-reminder', selected_option[0].get('option_type')) self.task.set_reminder(ReminderOneDayBefore()) browser.visit(self.task, view='tabbedview_view-overview') init_state = self._get_init_state(browser) selected_option = filter(lambda x: x.get('selected'), init_state.get('reminder_options')) self.assertEqual(1, len(selected_option)) self.assertEqual(ReminderOneDayBefore.option_type, selected_option[0].get('option_type'))
def test_reminders_can_be_created_via_factory_method(self): self.assertEqual( ReminderSameDay(), Reminder.create('same_day')) self.assertEqual( ReminderOneDayBefore(), Reminder.create('one_day_before')) self.assertEqual( ReminderOneWeekBefore(), Reminder.create('one_week_before')) self.assertEqual( ReminderBeginningOfWeek(), Reminder.create('beginning_of_week')) self.assertEqual( ReminderOnDate({'date': date(2018, 12, 30)}), Reminder.create('on_date', {'date': date(2018, 12, 30)}))
def test_reminders_can_be_deserialized_from_data(self): self.assertEqual( ReminderSameDay(), Reminder.deserialize({'option_type': 'same_day'})) self.assertEqual( ReminderOneDayBefore(), Reminder.deserialize({'option_type': 'one_day_before'})) self.assertEqual( ReminderOneWeekBefore(), Reminder.deserialize({'option_type': 'one_week_before'})) self.assertEqual( ReminderBeginningOfWeek(), Reminder.deserialize({'option_type': 'beginning_of_week'})) self.assertEqual( ReminderOnDate({'date': date(2018, 12, 30)}), Reminder.deserialize({'option_type': 'on_date', 'params': {'date': date(2018, 12, 30)}}))
def test_set_reminder_updates_existing_reminder(self): self.login(self.regular_user) self.task.set_reminder(ReminderOneDayBefore()) self.task.set_reminder(ReminderOneWeekBefore()) self.assertEqual(ReminderOneWeekBefore(), self.task.get_reminder())