class FeedbackSchedulerTestCase(TestCase): def setUp(self): self.subject = SubjectFactory() self.feedback_class = get_feedback_factory_class() def test_nbr_of_feedbacks(self): self.feedback_class.create_batch(5, subject=self.subject) self.assertEqual(FeedbackScheduler(self.subject).nbr_of_feedbacks, 6) def test_schedule_first_feedback(self): self.assertEqual(FeedbackScheduler(self.subject).nbr_of_feedbacks, 1) def test_schedule_first_feedback_date(self): self.assertEqual(self.subject.get_last_feedback().date, next_monday_date()) def test_schedule_feedback_done(self): feedback = self.feedback_class.create(subject=self.subject) feedback.done = True feedback.save() self.assertEqual(FeedbackScheduler(self.subject).nbr_of_feedbacks, 2) 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)
class SubjectTestCase(TestCase): def setUp(self): self.subject = SubjectFactory() self.feedback = self.subject.get_last_feedback() def test_save_subject(self): self.assertTrue( isinstance(Feedback.objects.get(subject=self.subject), Feedback)) def test_get_last_feedback(self): self.assertEqual(Feedback.objects.get(subject=self.subject), self.feedback) def test_update_penalties_no_penalties_feedback_done(self): self.subject.update_penalties(True) self.assertEqual(self.subject.penalties, 0) def test_update_penalties_penalties_feedback_done(self): self.subject.penalties = 2 self.subject.update_penalties(True) self.assertEqual(self.subject.penalties, 0) def test_update_penalties_penalties_feedback_not_done(self): self.subject.penalties = 2 self.subject.update_penalties(False) self.assertEqual(self.subject.penalties, 4)
class UpdateFeedbacksTestCase(TestCase): """" Test update_feedbacks command.""" def setUp(self): self.subject = SubjectFactory() def test_update_feedbacks_with_google_calendar(self): feedback = self.subject.get_last_feedback() self.assertEqual(feedback.duration, datetime.timedelta(hours=2)) feedback.google_calendar_client.update_event(feedback.event_id, fields={'location' : '01:00', 'description' : 'd'}) feedback.date = previous_monday_date() feedback.save() call_command('update_feedbacks') self.assertEqual(2, Feedback.objects.filter(subject=self.subject).count()) last_feedback = self.subject.get_last_feedback() self.assertEqual(last_feedback.duration, datetime.timedelta(hours=1)) self.assertEqual(last_feedback.google_calendar_client.get_event(last_feedback.event_id)['location'], '1:00')
class FeedbackTestCase(TestCase): def setUp(self): self.subject = SubjectFactory() self.feedback = self.subject.get_last_feedback() def test_last_feedback_duration_attribute(self): self.feedback.duration = timedelta(hours=3) self.feedback.save() feedback = Feedback(subject=self.subject) feedback.save() self.assertEqual(feedback.duration, self.feedback.duration)
class FeedbackSchedulerTestCase(TestCase): def setUp(self): self.subject = SubjectFactory() self.feedback_class = get_feedback_factory_class() def test_nbr_of_feedbacks(self): self.feedback_class.create_batch(5, subject=self.subject) self.assertEqual(FeedbackScheduler(self.subject).nbr_of_feedbacks, 6) def test_schedule_first_feedback(self): self.assertEqual(FeedbackScheduler(self.subject).nbr_of_feedbacks, 1) def test_schedule_first_feedback_date(self): self.assertEqual(self.subject.get_last_feedback().date, next_monday_date()) def test_schedule_feedback_done(self): feedback = self.feedback_class.create(subject=self.subject) feedback.done = True feedback.save() self.assertEqual(FeedbackScheduler(self.subject).nbr_of_feedbacks, 2) 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)
class UpdateFeedbacksTestCase(TestCase): """" Test update_feedbacks command.""" def setUp(self): self.subject = SubjectFactory() def test_update_feedbacks_with_google_calendar(self): feedback = self.subject.get_last_feedback() self.assertEqual(feedback.duration, datetime.timedelta(hours=2)) feedback.google_calendar_client.update_event(feedback.event_id, fields={ 'location': '01:00', 'description': 'd' }) feedback.date = previous_monday_date() feedback.save() call_command('update_feedbacks') self.assertEqual(2, Feedback.objects.filter(subject=self.subject).count()) last_feedback = self.subject.get_last_feedback() self.assertEqual(last_feedback.duration, datetime.timedelta(hours=1)) self.assertEqual( last_feedback.google_calendar_client.get_event( last_feedback.event_id)['location'], '1:00')
class GoogleCalendarFeedbackTestCase(TestCase): def setUp(self): self.subject = SubjectFactory() self.feedback = self.subject.get_last_feedback() def _update_date(self, new_date=date(2016, 9, 18)): updated_date = new_date self.assertNotEqual(self.feedback.date, updated_date) self.feedback.date = updated_date self.feedback.save() return updated_date def test_save_feedback(self): self.assertTrue(self.feedback.google_calendar_client.get_event(self.feedback.event_id)) def test_is_done(self): self.assertFalse(self.feedback.done) self.feedback.google_calendar_client.update_event(self.feedback.event_id, {"description" :"d"}) self.assertTrue(self.feedback.done) def test_update_date(self): updated_date = self._update_date() event = self.feedback.google_calendar_client.get_event(self.feedback.event_id) self.assertEqual(event["start"]["date"], updated_date.strftime("%Y-%m-%d")) self.assertEqual(event["end"]["date"], updated_date.strftime("%Y-%m-%d")) def test_event_color_after_feedback_creation(self): self.subject.penalties = 2 feedback = GoogleCalendarFeedbackFactory(subject=self.subject) event = self.feedback.google_calendar_client.get_event(feedback.event_id) self.assertEqual(event["colorId"], '6') def test_event_color_after_date_change(self): event = self.feedback.google_calendar_client.get_event(self.feedback.event_id) self.assertEqual(event["colorId"], '2') self.feedback.subject.penalties = 13 self._update_date() event = self.feedback.google_calendar_client.get_event(self.feedback.event_id) self.assertEqual(event["colorId"], '11') def test_set_duration_field_from_calendar(self): self.assertEqual(self.feedback.duration, timedelta(seconds=7200)) self.feedback.google_calendar_client.update_event(self.feedback.event_id, {"location" :"03:30"}) self.feedback.set_duration_field_from_calendar(self.feedback.google_calendar_client.get_event(self.feedback.event_id)) self.assertEqual(self.feedback.duration, timedelta(hours=3, minutes=30)) feedback = GoogleCalendarFeedbackFactory(subject=self.subject) self.assertEqual(feedback.duration, timedelta(hours=3, minutes=30)) def test_delete_feedback(self): client = self.feedback.google_calendar_client event_id = self.feedback.event_id self.feedback.delete() self.assertEqual("cancelled", client.get_event(event_id)["status"])
class SubjectTestCase(TestCase): def setUp(self): self.subject = SubjectFactory() self.feedback = self.subject.get_last_feedback() def test_save_subject(self): self.assertTrue(isinstance(Feedback.objects.get(subject=self.subject), Feedback)) def test_get_last_feedback(self): self.assertEqual(Feedback.objects.get(subject=self.subject), self.feedback) def test_update_penalties_no_penalties_feedback_done(self): self.subject.update_penalties(True) self.assertEqual(self.subject.penalties, 0) def test_update_penalties_penalties_feedback_done(self): self.subject.penalties = 2 self.subject.update_penalties(True) self.assertEqual(self.subject.penalties, 0) def test_update_penalties_penalties_feedback_not_done(self): self.subject.penalties = 2 self.subject.update_penalties(False) self.assertEqual(self.subject.penalties, 4)
def setUp(self): self.subject = SubjectFactory() self.reports = [FeedbackSchedulerReport("Histoire de l'economie", False, date(year=2016, month=10, day=2)), FeedbackSchedulerReport("Histoire de France", True, date(year=2016, month=11, day=2))]
def setUp(self): self.subject = SubjectFactory() self.feedback_class = get_feedback_factory_class()
def setUp(self): self.subject = SubjectFactory()
def setUp(self): self.subject = SubjectFactory() self.feedback = self.subject.get_last_feedback()
class GoogleCalendarFeedbackTestCase(TestCase): def setUp(self): self.subject = SubjectFactory() self.feedback = self.subject.get_last_feedback() def _update_date(self, new_date=date(2016, 9, 18)): updated_date = new_date self.assertNotEqual(self.feedback.date, updated_date) self.feedback.date = updated_date self.feedback.save() return updated_date def test_save_feedback(self): self.assertTrue( self.feedback.google_calendar_client.get_event( self.feedback.event_id)) def test_is_done(self): self.assertFalse(self.feedback.done) self.feedback.google_calendar_client.update_event( self.feedback.event_id, {"description": "d"}) self.assertTrue(self.feedback.done) def test_update_date(self): updated_date = self._update_date() event = self.feedback.google_calendar_client.get_event( self.feedback.event_id) self.assertEqual(event["start"]["date"], updated_date.strftime("%Y-%m-%d")) self.assertEqual(event["end"]["date"], updated_date.strftime("%Y-%m-%d")) def test_event_color_after_feedback_creation(self): self.subject.penalties = 2 feedback = GoogleCalendarFeedbackFactory(subject=self.subject) event = self.feedback.google_calendar_client.get_event( feedback.event_id) self.assertEqual(event["colorId"], '6') def test_event_color_after_date_change(self): event = self.feedback.google_calendar_client.get_event( self.feedback.event_id) self.assertEqual(event["colorId"], '2') self.feedback.subject.penalties = 13 self._update_date() event = self.feedback.google_calendar_client.get_event( self.feedback.event_id) self.assertEqual(event["colorId"], '11') def test_set_duration_field_from_calendar(self): self.assertEqual(self.feedback.duration, timedelta(seconds=7200)) self.feedback.google_calendar_client.update_event( self.feedback.event_id, {"location": "03:30"}) self.feedback.set_duration_field_from_calendar( self.feedback.google_calendar_client.get_event( self.feedback.event_id)) self.assertEqual(self.feedback.duration, timedelta(hours=3, minutes=30)) feedback = GoogleCalendarFeedbackFactory(subject=self.subject) self.assertEqual(feedback.duration, timedelta(hours=3, minutes=30)) def test_delete_feedback(self): client = self.feedback.google_calendar_client event_id = self.feedback.event_id self.feedback.delete() self.assertEqual("cancelled", client.get_event(event_id)["status"])
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())