Beispiel #1
0
  def test_start_failed(self, mock_mail):

    wf_admin = "*****@*****.**"

    with freeze_time("2015-02-01 13:39:20"):
      _, wf = self.wf_generator.generate_workflow(self.quarterly_wf)
      response, wf = self.wf_generator.activate_workflow(wf)
      print wf.next_cycle_start_date

      self.assert200(response)

    with freeze_time("2015-01-01 13:39:20"):
      _, notif_data = common.get_daily_notifications()
      self.assertNotIn(wf_admin, notif_data)

    with freeze_time("2015-01-29 13:39:20"):
      _, notif_data = common.get_daily_notifications()
      self.assertIn(wf_admin, notif_data)
      self.assertIn("cycle_starts_in", notif_data[wf_admin])

    with freeze_time("2015-03-05 13:39:20"):
      _, notif_data = common.get_daily_notifications()
      self.assertIn(wf_admin, notif_data)
      self.assertNotIn("cycle_started", notif_data[wf_admin])
      self.assertIn(wf_admin, notif_data)
      self.assertIn("cycle_start_failed", notif_data[wf_admin])

      common.send_daily_digest_notifications()

      _, notif_data = common.get_daily_notifications()
      self.assertNotIn(wf_admin, notif_data)
Beispiel #2
0
  def test_move_notif_to_history(self, mocked_send_email):
    """Tests moving notifications to history table."""
    # pylint: disable=unused-argument
    # pylint: disable=unused-variable
    date_time = "2018-06-10 16:55:15"
    with freeze_time(date_time):
      _, workflow = self.wf_generator.generate_workflow(
          self.one_time_workflow)

      _, cycle = self.wf_generator.generate_cycle(workflow)
      self.wf_generator.activate_workflow(workflow)

      notif_to_be_sent_ids = db.session.query(Notification.id).filter(and_(
          Notification.sent_at == None,  # noqa
          Notification.send_on == date.today(),
          Notification.repeating == false()
      )).all()

      self.assertEqual(db.session.query(Notification).count(), 5)
      self.assertEqual(db.session.query(NotificationHistory).count(), 0)

      with freeze_time(date_time):
        common.send_daily_digest_notifications()

      notif_count = db.session.query(Notification).filter(
          Notification.id.in_(notif_to_be_sent_ids)
      ).count()

      notif_history_count = db.session.query(NotificationHistory).count()

      self.assertEqual(notif_count, 0)
      self.assertEqual(notif_history_count, len(notif_to_be_sent_ids))
  def test_sending_overdue_notifications_for_tasks(self, is_vf_needed, _):
    """Overdue notifications should be sent for overdue tasks every day.

    Even if an overdue notification has already been sent, it should still be
    sent in every following daily digest f a task is still overdue.
    """
    with freeze_time("2017-05-15 14:25:36"):
      tmp = self.one_time_workflow.copy()
      tmp['is_verification_needed'] = is_vf_needed
      _, workflow = self.wf_generator.generate_workflow(tmp)
      self.wf_generator.generate_cycle(workflow)
      response, workflow = self.wf_generator.activate_workflow(workflow)
      self.assert200(response)

    tasks = workflow.cycles[0].cycle_task_group_object_tasks
    task1_id = tasks[0].id
    task2_id = tasks[1].id

    user = models.Person.query.get(self.user.id)

    with freeze_time("2017-05-14 08:09:10"):
      _, notif_data = common.get_daily_notifications()
      user_notifs = notif_data.get(user.email, {})
      self.assertNotIn("task_overdue", user_notifs)

    with freeze_time("2017-05-15 08:09:10"):  # task 1 due date
      _, notif_data = common.get_daily_notifications()
      user_notifs = notif_data.get(user.email, {})
      self.assertNotIn("task_overdue", user_notifs)

    with freeze_time("2017-05-16 08:09:10"):  # task 2 due date
      _, notif_data = common.get_daily_notifications()
      user_notifs = notif_data.get(user.email, {})
      self.assertIn("task_overdue", user_notifs)

      overdue_task_ids = sorted(user_notifs["task_overdue"].keys())
      self.assertEqual(overdue_task_ids, [task1_id])

    with freeze_time("2017-05-17 08:09:10"):  # after both tasks' due dates
      _, notif_data = common.get_daily_notifications()
      user_notifs = notif_data.get(user.email, {})
      self.assertIn("task_overdue", user_notifs)

      overdue_task_ids = sorted(user_notifs["task_overdue"].keys())
      self.assertEqual(overdue_task_ids, [task1_id, task2_id])

      common.send_daily_digest_notifications()

    # even after sending the overdue notifications, they are sent again the
    # day after, too
    with freeze_time("2017-05-18 08:09:10"):
      _, notif_data = common.get_daily_notifications()
      user_notifs = notif_data.get(user.email, {})
      self.assertIn("task_overdue", user_notifs)

      overdue_task_ids = sorted(user_notifs["task_overdue"].keys())
      self.assertEqual(overdue_task_ids, [task1_id, task2_id])
  def test_no_date_change(self, mock_mail):
    def get_person(person_id):
      return db.session.query(Person).filter(Person.id == person_id).one()

    with freeze_time("2015-04-10 03:21:34"):
      _, workflow = self.wf_generator.generate_workflow(
          self.one_time_workflow_1)

      _, cycle = self.wf_generator.generate_cycle(workflow)
      self.wf_generator.activate_workflow(workflow)

    with freeze_time("2015-04-11 03:21:34"):
      user = get_person(self.user.id)
      _, notif_data = common.get_daily_notifications()
      self.assertIn("cycle_started", notif_data[user.email])

    with freeze_time("2015-05-02 03:21:34"):
      _, notif_data = common.get_daily_notifications()
      self.assertIn(user.email, notif_data)
      self.assertIn("cycle_started", notif_data[user.email])
      self.assertNotIn("due_in", notif_data[user.email])
      self.assertNotIn("due_today", notif_data[user.email])

    with freeze_time("2015-05-02 03:21:34"):
      common.send_daily_digest_notifications()
      _, notif_data = common.get_daily_notifications()
      self.assertEqual(notif_data, {})

      # one email to admin and one to assigne
      self.assertEqual(mock_mail.call_count, 2)

    with freeze_time("2015-05-04 03:21:34"):  # one day before due date
      _, notif_data = common.get_daily_notifications()
      user = get_person(self.user.id)
      self.assertIn(user.email, notif_data)
      self.assertIn("due_in", notif_data[user.email])
      self.assertEqual(len(notif_data[user.email]["due_in"]), 2)

    with freeze_time("2015-05-04 03:21:34"):  # one day before due date
      common.send_daily_digest_notifications()
      _, notif_data = common.get_daily_notifications()
      self.assertEqual(notif_data, {})

      # one email to admin and one to assigne
      self.assertEqual(mock_mail.call_count, 3)

    with freeze_time("2015-05-05 03:21:34"):  # due date
      _, notif_data = common.get_daily_notifications()
      self.assertIn("due_today", notif_data[user.email])
      self.assertEqual(len(notif_data[user.email]["due_today"]), 2)
Beispiel #5
0
  def test_one_time_wf_activate_single_person(self, mock_mail):

    with freeze_time("2015-04-10"):
      user = "******"
      _, wf = self.wf_generator.generate_workflow(
          self.one_time_workflow_single_person)

      _, cycle = self.wf_generator.generate_cycle(wf)
      self.wf_generator.activate_workflow(wf)

    with freeze_time("2015-04-11"):
      _, notif_data = common.get_daily_notifications()
      self.assertIn("cycle_started", notif_data[user])
      self.assertIn(cycle.id, notif_data[user]["cycle_started"])
      self.assertIn("my_tasks", notif_data[user]["cycle_data"][cycle.id])
      self.assertIn("cycle_tasks", notif_data[user]["cycle_data"][cycle.id])
      self.assertIn(
          "my_task_groups", notif_data[user]["cycle_data"][cycle.id])
      self.assertIn("cycle_url", notif_data[user]["cycle_started"][cycle.id])

      cycle = Cycle.query.get(cycle.id)
      cycle_data = notif_data[user]["cycle_data"][cycle.id]
      for task in cycle.cycle_task_group_object_tasks:
        self.assertIn(task.id, cycle_data["my_tasks"])
        self.assertIn(task.id, cycle_data["cycle_tasks"])
        self.assertIn("title", cycle_data["my_tasks"][task.id])
        self.assertIn("title", cycle_data["cycle_tasks"][task.id])
        self.assertIn("cycle_task_url", cycle_data["cycle_tasks"][task.id])

    with freeze_time("2015-05-03"):  # two days before due date
      _, notif_data = common.get_daily_notifications()
      self.assertIn(user, notif_data)
      self.assertNotIn("due_in", notif_data[user])
      self.assertNotIn("due_today", notif_data[user])

    with freeze_time("2015-05-04"):  # one day before due date
      _, notif_data = common.get_daily_notifications()
      self.assertEqual(len(notif_data[user]["due_in"]), 2)

    with freeze_time("2015-05-05"):  # due date
      _, notif_data = common.get_daily_notifications()
      self.assertEqual(len(notif_data[user]["due_today"]), 2)

      common.send_daily_digest_notifications()
      self.assertEqual(mock_mail.call_count, 1)
  def test_move_end_date_to_past(self, mock_mail):
    def get_person(person_id):
      return db.session.query(Person).filter(Person.id == person_id).one()

    with freeze_time("2015-04-10 03:21:34"):
      _, workflow = self.wf_generator.generate_workflow(
          self.one_time_workflow_1)

      _, cycle = self.wf_generator.generate_cycle(workflow)
      self.wf_generator.activate_workflow(workflow)

    with freeze_time("2015-05-02 03:21:34"):
      common.send_daily_digest_notifications()
      _, notif_data = common.get_daily_notifications()
      self.assertEqual(notif_data, {})

      # one email to owner and one to assignee
      self.assertEqual(mock_mail.call_count, 2)

    with freeze_time("2015-05-03 03:21:34"):
      cycle = Cycle.query.get(cycle.id)
      task1 = CycleTaskGroupObjectTask.query.get(
          cycle.cycle_task_group_object_tasks[0].id)
      task2 = CycleTaskGroupObjectTask.query.get(
          cycle.cycle_task_group_object_tasks[1].id)

      self.wf_generator.modify_object(
          task1, data={"end_date": date(2015, 5, 1)})
      self.wf_generator.modify_object(
          task2, data={"end_date": date(2015, 5, 1)})

    with freeze_time("2015-05-03 03:21:34"):  # two days after due date
      user = get_person(self.user.id)
      _, notif_data = common.get_daily_notifications()
      self.assertNotEqual(notif_data, {})
      self.assertIn(user.email, notif_data)

      user_notifs = notif_data[user.email]
      self.assertNotIn("due_today", user_notifs)
      self.assertNotIn("due_in", user_notifs)

      self.assertIn("task_overdue", user_notifs)
      self.assertEqual(len(user_notifs["task_overdue"]), 2)
  def test_single_task_declined(self, mock_mail):
    """
    test moving the end date to the future, befor due_in and due_today
    notifications have been sent
    """

    with freeze_time("2015-05-01"):
      _, workflow = self.wf_generator.generate_workflow(
          self.one_time_workflow_1)

      _, cycle = self.wf_generator.generate_cycle(workflow)
      self.wf_generator.activate_workflow(workflow)

    with freeze_time("2015-05-02"):
      common.send_daily_digest_notifications()

      cycle = Cycle.query.get(cycle.id)
      task1 = CycleTaskGroupObjectTask.query.get(
          cycle.cycle_task_group_object_tasks[0].id)

      self.task_change_status(task1, "Finished")

      _, notif_data = common.get_daily_notifications()
      self.assertEqual(notif_data, {})

    with freeze_time("2015-05-02"):
      common.send_daily_digest_notifications()

      cycle = Cycle.query.get(cycle.id)
      task1 = CycleTaskGroupObjectTask.query.get(
          cycle.cycle_task_group_object_tasks[0].id)

      self.task_change_status(task1, "Declined")

      user = Person.query.get(self.user.id)
      _, notif_data = common.get_daily_notifications()

      self.assertIn(user.email, notif_data)
      self.assertIn("task_declined", notif_data[user.email])
  def test_marking_sent_notifications(self, mail_mock):
    mail_mock.return_value = True

    with freeze_time("2015-02-01"):
      _, wf = self.generator.generate_workflow(self.quarterly_wf_1)
      response, wf = self.generator.activate_workflow(wf)

      self.assert200(response)

      assignee = Person.query.get(self.assignee.id)

    with freeze_time("2015-01-01"):
      _, notif_data = common.get_daily_notifications()
      self.assertNotIn(assignee.email, notif_data)

    with freeze_time("2015-01-29"):
      common.send_daily_digest_notifications()
      _, notif_data = common.get_daily_notifications()
      self.assertNotIn(assignee.email, notif_data)

    with freeze_time("2015-02-01"):
      _, notif_data = common.get_daily_notifications()
      self.assertNotIn(assignee.email, notif_data)
Beispiel #9
0
  def test_single_task_accepted(self, mock_mail):
    """Test moving the end date to the future on accepted task.

    It is done before due_in and due_today notifications have been sent.
    """

    with freeze_time("2015-05-01"):
      _, workflow = self.wf_generator.generate_workflow(
          self.one_time_workflow_1)

      _, cycle = self.wf_generator.generate_cycle(workflow)
      self.wf_generator.activate_workflow(workflow)

    with freeze_time("2015-05-02"):
      common.send_daily_digest_notifications()

      cycle = Cycle.query.get(cycle.id)
      task1 = CycleTaskGroupObjectTask.query.get(
          cycle.cycle_task_group_object_tasks[0].id)

      self.task_change_status(task1, "Finished")

      _, notif_data = common.get_daily_notifications()
      self.assertEqual(notif_data, {})

    with freeze_time("2015-05-03 13:20:34"):
      cycle = Cycle.query.get(cycle.id)
      task1 = CycleTaskGroupObjectTask.query.get(
          cycle.cycle_task_group_object_tasks[0].id)

      self.task_change_status(task1)

      generate_cycle_tasks_notifs()
      user = Person.query.get(self.user.id)
      _, notif_data = common.get_daily_notifications()
      self.assertNotIn(user.email, notif_data)
      self.assertIn("all_tasks_completed", notif_data["*****@*****.**"])
Beispiel #10
0
  def test_move_end_date_to_future(self, mock_mail):
    """
    test moving the end date to the future, befor due_in and due_today
    notifications have been sent
    """
    def get_person(person_id):
      return db.session.query(Person).filter(Person.id == person_id).one()

    with freeze_time("2015-04-10 03:21:34"):
      _, workflow = self.wf_generator.generate_workflow(
          self.one_time_workflow_1)

      _, cycle = self.wf_generator.generate_cycle(workflow)
      self.wf_generator.activate_workflow(workflow)

    with freeze_time("2015-04-11 03:21:34"):
      user = get_person(self.user.id)
      _, notif_data = common.get_daily_notifications()
      self.assertIn("cycle_started", notif_data[user.email])

    with freeze_time("2015-05-02 03:21:34"):
      _, notif_data = common.get_daily_notifications()
      self.assertIn(user.email, notif_data)
      self.assertIn("cycle_started", notif_data[user.email])
      self.assertNotIn("due_in", notif_data[user.email])
      self.assertNotIn("due_today", notif_data[user.email])

    with freeze_time("2015-05-02 03:21:34"):
      common.send_daily_digest_notifications()
      _, notif_data = common.get_daily_notifications()
      self.assertEqual(notif_data, {})

      # one email to owner and one to assigne
      self.assertEqual(mock_mail.call_count, 2)

    with freeze_time("2015-05-03 03:21:34"):
      cycle = Cycle.query.get(cycle.id)
      task1 = CycleTaskGroupObjectTask.query.get(
          cycle.cycle_task_group_object_tasks[0].id)
      task2 = CycleTaskGroupObjectTask.query.get(
          cycle.cycle_task_group_object_tasks[1].id)

      self.wf_generator.modify_object(
          task1, data={"end_date": date(2015, 5, 15)})
      self.wf_generator.modify_object(
          task2, data={"end_date": date(2015, 5, 15)})

    with freeze_time("2015-05-04 03:21:34"):  # one day befor due date
      _, notif_data = common.get_daily_notifications()
      user = get_person(self.user.id)
      self.assertEqual(notif_data, {})

    with freeze_time("2015-05-05 03:21:34"):  # due date
      _, notif_data = common.get_daily_notifications()
      self.assertEqual(notif_data, {})

    with freeze_time("2015-05-14 03:21:34"):  # due date
      _, notif_data = common.get_daily_notifications()
      self.assertIn(user.email, notif_data)
      self.assertIn("due_in", notif_data[user.email])
      self.assertEqual(len(notif_data[user.email]["due_in"]),
                       len(self.random_objects))

    with freeze_time("2015-05-15 03:21:34"):  # due date
      _, notif_data = common.get_daily_notifications()
      self.assertIn(user.email, notif_data)

      # yesterdays mail has not been sent
      self.assertIn("due_in", notif_data[user.email])

      self.assertIn("due_today", notif_data[user.email])
      self.assertEqual(len(notif_data[user.email]["due_today"]),
                       len(self.random_objects))
    def test_move_end_date_to_today(self, mock_mail):
        def get_person(person_id):
            return db.session.query(Person).filter(
                Person.id == person_id).one()

        with freeze_time("2015-04-10 03:21:34"):
            _, workflow = self.wf_generator.generate_workflow(
                self.one_time_workflow_1)

            _, cycle = self.wf_generator.generate_cycle(workflow)
            self.wf_generator.activate_workflow(workflow)

        with freeze_time("2015-05-02 03:21:34"):
            common.send_daily_digest_notifications()
            _, notif_data = common.get_daily_notifications()
            self.assertEqual(notif_data, {})

            # one email to owner and one to assigne
            self.assertEqual(mock_mail.call_count, 2)

        with freeze_time("2015-05-03 03:21:34"):
            cycle = Cycle.query.get(cycle.id)
            task1 = CycleTaskGroupObjectTask.query.get(
                cycle.cycle_task_group_object_tasks[0].id)
            task2 = CycleTaskGroupObjectTask.query.get(
                cycle.cycle_task_group_object_tasks[1].id)

            self.wf_generator.modify_object(
                task1, data={"end_date": date(2015, 5, 3)})
            self.wf_generator.modify_object(
                task2, data={"end_date": date(2015, 5, 4)})

        with freeze_time("2015-05-03 03:21:34"):  # one day before due date
            user = get_person(self.user.id)
            _, notif_data = common.get_daily_notifications()

            self.assertNotEqual(notif_data, {})
            self.assertIn(user.email, notif_data)
            self.assertIn("due_today", notif_data[user.email])
            self.assertIn("due_in", notif_data[user.email])
            self.assertEqual(len(notif_data[user.email]["due_today"]), 1)

            common.send_daily_digest_notifications()

        with freeze_time("2015-05-04 03:21:34"):  # due date (of task2)
            user = get_person(self.user.id)
            _, notif_data = common.get_daily_notifications()
            self.assertIn(user.email, notif_data)
            self.assertIn("due_today", notif_data[user.email])
            self.assertNotIn("due_in", notif_data[user.email])
            common.send_daily_digest_notifications()

        # check that overdue notifications are sent even on days after the day a
        # task has become due, unlike the "due_today" and "due_in" notifications
        with freeze_time("2015-05-05 03:21:34"):  # 1+ days after due date(s)
            _, notif_data = common.get_daily_notifications()
            self.assertNotEqual(notif_data, {})
            self.assertIn(user.email, notif_data)

            user_notifs = notif_data[user.email]
            self.assertNotIn("due_today", user_notifs)
            self.assertNotIn("due_in", user_notifs)

            self.assertIn("task_overdue", user_notifs)
            self.assertEqual(len(user_notifs["task_overdue"]), 2)
  def test_move_end_date_to_today(self, mock_mail):
    def get_person(person_id):
      return db.session.query(Person).filter(Person.id == person_id).one()

    with freeze_time("2015-04-10 03:21:34"):
      _, workflow = self.wf_generator.generate_workflow(
          self.one_time_workflow_1)

      _, cycle = self.wf_generator.generate_cycle(workflow)
      self.wf_generator.activate_workflow(workflow)

    with freeze_time("2015-05-02 03:21:34"):
      common.send_daily_digest_notifications()
      _, notif_data = common.get_daily_notifications()
      self.assertEqual(notif_data, {})

      # one email to admin and one to assigne
      self.assertEqual(mock_mail.call_count, 2)

    with freeze_time("2015-05-03 03:21:34"):
      cycle = Cycle.query.get(cycle.id)
      task1 = CycleTaskGroupObjectTask.query.get(
          cycle.cycle_task_group_object_tasks[0].id)
      task2 = CycleTaskGroupObjectTask.query.get(
          cycle.cycle_task_group_object_tasks[1].id)

      self.wf_generator.modify_object(
          task1, data={"end_date": date(2015, 5, 3)})
      self.wf_generator.modify_object(
          task2, data={"end_date": date(2015, 5, 4)})

    with freeze_time("2015-05-03 03:21:34"):  # one day before due date
      user = get_person(self.user.id)
      _, notif_data = common.get_daily_notifications()

      self.assertNotEqual(notif_data, {})
      self.assertIn(user.email, notif_data)
      self.assertIn("due_today", notif_data[user.email])
      self.assertIn("due_in", notif_data[user.email])
      self.assertEqual(len(notif_data[user.email]["due_today"]), 1)

      common.send_daily_digest_notifications()

    with freeze_time("2015-05-04 03:21:34"):  # due date (of task2)
      user = get_person(self.user.id)
      _, notif_data = common.get_daily_notifications()
      self.assertIn(user.email, notif_data)
      self.assertIn("due_today", notif_data[user.email])
      self.assertNotIn("due_in", notif_data[user.email])
      common.send_daily_digest_notifications()

    # check that overdue notifications are sent even on days after the day a
    # task has become due, unlike the "due_today" and "due_in" notifications
    with freeze_time("2015-05-05 03:21:34"):  # 1+ days after due date(s)
      _, notif_data = common.get_daily_notifications()
      self.assertNotEqual(notif_data, {})
      self.assertIn(user.email, notif_data)

      user_notifs = notif_data[user.email]
      self.assertNotIn("due_today", user_notifs)
      self.assertNotIn("due_in", user_notifs)

      self.assertIn("task_overdue", user_notifs)
      self.assertEqual(len(user_notifs["task_overdue"]), 2)
    def test_move_end_date_to_future(self, mock_mail):
        """Test moving the end date to the future.

    It is done before due_in and due_today notifications have been sent.
    """
        with freeze_time("2015-04-10 03:21:34"):
            _, workflow = self.wf_generator.generate_workflow(
                self.one_time_workflow_1)

            _, cycle = self.wf_generator.generate_cycle(workflow)
            self.wf_generator.activate_workflow(workflow)

        assignee = self.user
        task_assignees = [assignee, self.secondary_assignee]
        with freeze_time("2015-04-11 03:21:34"):
            _, notif_data = common.get_daily_notifications()
            # cycle started notifs available only for contact
            self.assertIn("cycle_started", notif_data[assignee.email])

        with freeze_time("2015-05-02 03:21:34"):
            _, notif_data = common.get_daily_notifications()
            for user in task_assignees:
                self.assertIn(user.email, notif_data)
                self.assertNotIn("due_in", notif_data[user.email])
                self.assertNotIn("due_today", notif_data[user.email])
            # cycle started notifs available only for contact
            self.assertIn("cycle_started", notif_data[assignee.email])

        with freeze_time("2015-05-02 03:21:34"):
            common.send_daily_digest_notifications()
            _, notif_data = common.get_daily_notifications()
            self.assertEqual(notif_data, {})

            # one email to admin and one each to assigne and secondary assignee
            self.assertEqual(mock_mail.call_count, 3)

        with freeze_time("2015-05-03 03:21:34"):
            cycle = Cycle.query.get(cycle.id)
            task1 = CycleTaskGroupObjectTask.query.get(
                cycle.cycle_task_group_object_tasks[0].id)
            task2 = CycleTaskGroupObjectTask.query.get(
                cycle.cycle_task_group_object_tasks[1].id)

            self.wf_generator.modify_object(
                task1, data={"end_date": date(2015, 5, 15)})
            self.wf_generator.modify_object(
                task2, data={"end_date": date(2015, 5, 15)})

        with freeze_time("2015-05-04 03:21:34"):  # one day before due date
            _, notif_data = common.get_daily_notifications()
            self.assertEqual(notif_data, {})

        with freeze_time("2015-05-05 03:21:34"):  # due date
            _, notif_data = common.get_daily_notifications()
            self.assertEqual(notif_data, {})

        with freeze_time("2015-05-14 03:21:34"):  # due date
            _, notif_data = common.get_daily_notifications()
            for user in task_assignees:
                self.assertIn(user.email, notif_data)
                self.assertIn("due_in", notif_data[user.email])
                self.assertEqual(len(notif_data[user.email]["due_in"]),
                                 len(self.random_objects))

        with freeze_time("2015-05-15 03:21:34"):  # due date
            _, notif_data = common.get_daily_notifications()
            for user in task_assignees:
                self.assertIn(user.email, notif_data)

                self.assertIn("due_in", notif_data[user.email])

                self.assertIn("due_today", notif_data[user.email])
                self.assertEqual(len(notif_data[user.email]["due_today"]),
                                 len(self.random_objects))
Beispiel #14
0
    def test_sending_overdue_notifications_for_tasks(self, is_vf_needed, _):
        """Overdue notifications should be sent for overdue tasks every day.

    Even if an overdue notification has already been sent, it should still be
    sent in every following daily digest f a task is still overdue.
    """
        with freeze_time("2017-05-15 14:25:36"):
            tmp = self.one_time_workflow.copy()
            tmp['is_verification_needed'] = is_vf_needed
            _, workflow = self.wf_generator.generate_workflow(tmp)
            self.wf_generator.generate_cycle(workflow)
            response, workflow = self.wf_generator.activate_workflow(workflow)
            self.assert200(response)

        tasks = workflow.cycles[0].cycle_task_group_object_tasks
        task1_id = tasks[0].id
        task2_id = tasks[1].id

        task_assignees = [self.user, self.secondary_assignee]
        with freeze_time("2017-05-14 08:09:10"):
            _, notif_data = common.get_daily_notifications()
            for user in task_assignees:
                user_notifs = notif_data.get(user.email, {})
                self.assertNotIn("task_overdue", user_notifs)

        with freeze_time("2017-05-15 08:09:10"):  # task 1 due date
            _, notif_data = common.get_daily_notifications()
            for user in task_assignees:
                user_notifs = notif_data.get(user.email, {})
                self.assertNotIn("task_overdue", user_notifs)

        with freeze_time("2017-05-16 08:09:10"):  # task 2 due date
            _, notif_data = common.get_daily_notifications()
            for user in task_assignees:
                user_notifs = notif_data.get(user.email, {})
                self.assertIn("task_overdue", user_notifs)

                overdue_task_ids = sorted(user_notifs["task_overdue"].keys())
                self.assertEqual(overdue_task_ids, [task1_id])

        with freeze_time("2017-05-17 08:09:10"):  # after both tasks' due dates
            _, notif_data = common.get_daily_notifications()
            for user in task_assignees:
                user_notifs = notif_data.get(user.email, {})
                self.assertIn("task_overdue", user_notifs)

                overdue_task_ids = sorted(user_notifs["task_overdue"].keys())
                self.assertEqual(overdue_task_ids, [task1_id, task2_id])

        common.send_daily_digest_notifications()

        # even after sending the overdue notifications, they are sent again the
        # day after, too
        with freeze_time("2017-05-18 08:09:10"):
            _, notif_data = common.get_daily_notifications()
            for user in task_assignees:
                user_notifs = notif_data.get(user.email, {})
                self.assertIn("task_overdue", user_notifs)

                overdue_task_ids = sorted(user_notifs["task_overdue"].keys())
                self.assertEqual(overdue_task_ids, [task1_id, task2_id])