def test_schedule_feedback_done_with_penalties(self):
     self.subject.penalties = 2
     self.subject.save()
     self.feedback_class.create_batch(3, subject=self.subject)
     self.feedback_class.create(subject=self.subject, _done=True)
     FeedbackScheduler(self.subject).schedule()
     last_feedback = self.subject.get_last_feedback()
     self.assertEqual(last_feedback.date, next_monday_date() + timedelta(weeks=3))
     self.assertEqual(Subject.objects.get(title=self.subject.title).penalties, 0)
 def test_schedule_feedback_done_with_penalties(self):
     self.subject.penalties = 2
     self.subject.save()
     self.feedback_class.create_batch(3, subject=self.subject)
     self.feedback_class.create(subject=self.subject, _done=True)
     FeedbackScheduler(self.subject).schedule()
     last_feedback = self.subject.get_last_feedback()
     self.assertEqual(last_feedback.date,
                      next_monday_date() + timedelta(weeks=3))
     self.assertEqual(
         Subject.objects.get(title=self.subject.title).penalties, 0)
 def test_schedule_feedback_time_elapsed(self):
     previous_monday = previous_monday_date()
     next_monday = next_monday_date()
     self.feedback_class(subject=self.subject, date=previous_monday)
     fake_datetime = datetime.combine(next_monday, datetime_module.time(0)) - timedelta(minutes=17) ## next sunday 11:43pm.
     with patch("feedback.feedbacks_scheduler.current_time",
                return_value=timezone(settings.CURRENT_TIME_ZONE).localize(fake_datetime)):
         report_scheduler = FeedbackScheduler(self.subject).schedule()
     postponed_feedback = self.subject.get_last_feedback()
     self.assertEqual(postponed_feedback.date, next_monday)
     self.assertEqual(self.subject.penalties, 2)
     self.assertEqual(FeedbackSchedulerReport(self.subject.title, False, next_monday),
                      report_scheduler)
 def test_schedule_feedback_time_elapsed(self):
     previous_monday = previous_monday_date()
     next_monday = next_monday_date()
     self.feedback_class(subject=self.subject, date=previous_monday)
     fake_datetime = datetime.combine(
         next_monday, datetime_module.time(0)) - timedelta(
             minutes=17)  ## next sunday 11:43pm.
     with patch("feedback.feedbacks_scheduler.current_time",
                return_value=timezone(
                    settings.CURRENT_TIME_ZONE).localize(fake_datetime)):
         report_scheduler = FeedbackScheduler(self.subject).schedule()
     postponed_feedback = self.subject.get_last_feedback()
     self.assertEqual(postponed_feedback.date, next_monday)
     self.assertEqual(self.subject.penalties, 2)
     self.assertEqual(
         FeedbackSchedulerReport(self.subject.title, False, next_monday),
         report_scheduler)
Esempio n. 5
0
    def schedule(self):
        """Schedule next feedback session based on previous feedbacks

        Return: A tuple ()
        """
        is_last_feedback_done = self.last_feedback.done
        if is_last_feedback_done: ## Nice , create a new feedback session.
            next_feedback_date = self.calculate_next_feedback_date()
            self.subject.update_penalties(is_feedback_done=True)

            get_feedback_class()(subject=self.subject, date=next_feedback_date).save()

        elif not is_last_feedback_done and self.is_feedback_time_elapsed(): ## Not good, postpone the feedback to next monday, add penalties.
            self.last_feedback.date = next_monday_date()
            self.subject.update_penalties(is_feedback_done=False)
            self.last_feedback.save()

        return FeedbackSchedulerReport(subject=self.subject.title,
                                       done=is_last_feedback_done,
                                       next_feedback_date=self.subject.get_last_feedback().date)
Esempio n. 6
0
    def schedule(self):
        """Schedule next feedback session based on previous feedbacks

        Return: A tuple ()
        """
        is_last_feedback_done = self.last_feedback.done
        if is_last_feedback_done:  ## Nice , create a new feedback session.
            next_feedback_date = self.calculate_next_feedback_date()
            self.subject.update_penalties(is_feedback_done=True)

            get_feedback_class()(subject=self.subject,
                                 date=next_feedback_date).save()

        elif not is_last_feedback_done and self.is_feedback_time_elapsed(
        ):  ## Not good, postpone the feedback to next monday, add penalties.
            self.last_feedback.date = next_monday_date()
            self.subject.update_penalties(is_feedback_done=False)
            self.last_feedback.save()

        return FeedbackSchedulerReport(
            subject=self.subject.title,
            done=is_last_feedback_done,
            next_feedback_date=self.subject.get_last_feedback().date)
 def test_schedule_first_feedback_date(self):
     self.assertEqual(self.subject.get_last_feedback().date, next_monday_date())
Esempio n. 8
0
def create_first_feedback(sender, instance, **kwargs):
    """
    When a subject is created the first feedback session is schedule the very the next week.
    """
    if type(instance) == Subject and not instance.get_last_feedback():
        get_feedback_class()(subject=instance, date=next_monday_date()).save()
 def test_schedule_first_feedback_date(self):
     self.assertEqual(self.subject.get_last_feedback().date,
                      next_monday_date())
Esempio n. 10
0
 def calculate_next_feedback_date(self):
     next_feedback_date = next_monday_date() + timedelta(
         weeks=self.nbr_of_feedbacks - self.subject.penalties)
     if next_feedback_date < next_monday_date():
         next_feedback_date = next_monday_date()
     return next_feedback_date
Esempio n. 11
0
def create_next_week_feedback_sessions_template_context():
    next_week_feedbacks = Feedback.objects.filter(date=next_monday_date())
    return {"next_week_feedbacks" : next_week_feedbacks,
            "next_week_total_feedbacks_duration" : get_sum_of_feedbacks_duration(next_week_feedbacks)}
Esempio n. 12
0
 def calculate_next_feedback_date(self):
     next_feedback_date = next_monday_date() + timedelta(weeks=self.nbr_of_feedbacks - self.subject.penalties)
     if next_feedback_date < next_monday_date():
         next_feedback_date = next_monday_date()
     return next_feedback_date
Esempio n. 13
0
 def test_get_current_week_subjects(self):
     current_week_subject = SubjectFactory(title='current_week_subject')
     next_week_subject = SubjectFactory(title='next_week_subject')
     get_feedback_factory_class()(date=previous_monday_date(), subject=current_week_subject)
     get_feedback_factory_class()(date=next_monday_date(), subject=next_week_subject)
     self.assertEqual([current_week_subject], get_current_week_subjects())
Esempio n. 14
0
def create_first_feedback(sender, instance, **kwargs):
    """
    When a subject is created the first feedback session is schedule the very the next week.
    """
    if type(instance) == Subject and not instance.get_last_feedback():
        get_feedback_class()(subject=instance, date=next_monday_date()).save()