def test_is_complete_parameterized(self): # (started_at, finished_at, expected_value) parameters = [ (None, None, False), (datetime(2017, 1, 1), None, False), (None, datetime(2017, 1, 2), False), (datetime(2017, 1, 1), datetime(2017, 1, 2), True), ] for started_at, finished_at, expected_value in parameters: attendance = Attendance.create(started_at=started_at, finished_at=finished_at, user=self.user) self.assertEqual(attendance.is_complete, expected_value)
def on_start_working(message, user, *args): if not user.trackable: return last_attendance = user.last_attendance() has_unfinished_work = last_attendance and not last_attendance.finished_at attendance = Attendance.create(started_at=datetime.utcnow(), user=user) attendance.save() message.react('stopwatch') if has_unfinished_work: message.reply( dedent("""\ I think you missed to inform finishing the last one. However I'll record you start your work now."""))
def test_working_time_parameterized(self): # (started_at, finished_at, expected_value) parameters = [ (None, None, None), (datetime(2017, 1, 1), None, None), (None, datetime(2017, 1, 2), None), (datetime(2017, 1, 1), datetime(2017, 1, 2), timedelta(days=1)), ] for started_at, finished_at, expected_value in parameters: attendance = Attendance.create(started_at=started_at, finished_at=finished_at, user=self.user) self.assertEqual(attendance.working_time, expected_value)
def on_finish_working(message, user, *args): if not user.trackable: return attendance = user.last_attendance() if not attendance or attendance.finished_at: attendance = Attendance.create(user=user) attendance.finished_at = datetime.utcnow() has_unstarted_work = not attendance.started_at and attendance.finished_at attendance.save() message.react('stopwatch') if has_unstarted_work: message.reply( dedent("""\ I think you missed to inform starting this work. However I'll record you finish your work now."""))
def test_last_attendance_returns_attendance(self): """ last_attendance() returns the last created Attendance object when the user has multiple attendances. """ started_and_finished_datetimes = [ (datetime(2017, 1, 1), datetime(2017, 1, 2)), (datetime(2017, 1, 2), datetime(2017, 1, 3)), (datetime(2017, 1, 3), datetime(2017, 1, 4)), ] for started_at, finished_at in started_and_finished_datetimes: attendance = Attendance.create(started_at=started_at, finished_at=finished_at, user=self.user) self.assertEqual(self.user.last_attendance(), attendance)
def test_working_time_display_parameterized(self): # (started_at, finished_at, expected_value) parameters = [ (None, None, None), (datetime(2017, 1, 1), None, None), (None, datetime(2017, 1, 2), None), (datetime(2017, 1, 1), datetime(2017, 1, 1, 12, 34, 56), '12:34:56'), (datetime(2017, 1, 1), datetime(2017, 1, 2), '24:00:00'), (datetime(2017, 1, 1), datetime(2017, 1, 2, 1), '25:00:00'), (datetime(2017, 1, 1), datetime(2017, 1, 3), '48:00:00'), (datetime(2017, 1, 1), datetime(2017, 1, 5, 4), '100:00:00'), ] for started_at, finished_at, expected_value in parameters: attendance = Attendance.create(started_at=started_at, finished_at=finished_at, user=self.user) self.assertEqual(attendance.working_time_display, expected_value)
def test_finished_at_display(self): finished_at = datetime(2017, 1, 1) attendance = Attendance.create(finished_at=finished_at, user=self.user) self.assertEqual(attendance.finished_at_display, '2017-01-01 09:00:00')
def test_started_at_display(self): started_at = datetime(2017, 1, 1) attendance = Attendance.create(started_at=started_at, user=self.user) self.assertEqual(attendance.started_at_display, '2017-01-01 09:00:00')