예제 #1
0
    def test_user_one_cannot_see_all_user_overtime(self):
        overtime_service = OvertimeService(self.user_one)

        expected = False
        actual = overtime_service.can_view_all_user_logs()

        self.assertEqual(expected, actual)
예제 #2
0
    def test_overtime_this_week(self) -> None:

        overtime_service = OvertimeService(self.user_one)

        expected = as_timedelta(1, 0)
        actual = overtime_service.get_current_weeks_overtime()

        self.assertEqual(expected, actual)
예제 #3
0
    def test_super_user_can_see_all_user_overtime(self):

        overtime_service = OvertimeService(self.super_user)

        expected = True
        actual = overtime_service.can_view_all_user_logs()

        self.assertEqual(expected, actual)
    def handle(self, *args, **options):

        user = self.get_or_create_superuser('admin')

        overtime = OvertimeService(user)

        for day in overtime.get_this_week_as_date_list():
            self.create_test_log_for_day(user, day, 8)

            if day == overtime.today:
                return
    def _create_overtime_for_user(self, user: User, user_num: int = 0) -> None:

        # Just to get a bit of variation
        log_in_hour = 7 + user_num
        overtime = OvertimeService(user)

        for day in overtime.get_this_week_as_date_list():
            self.create_test_log_for_day(user, day, log_in_hour)

            if day == overtime.today:
                return
예제 #6
0
    def test_can_calculate_overtime_for_all_users(self):
        overtime_service = OvertimeService(self.super_user)

        expected = {
            "User 1": {
                "overtime": as_timedelta(1, 0)
            },
            "Super User": {
                "overtime": datetime.timedelta(0)
            },
        }
        actual = overtime_service.get_overtime_for_all_users()

        self.assertEqual(expected, actual)
예제 #7
0
    def setUpTestData(cls):
        """This is called once before any tests are ran.
        e.g. its like setUp for the class.

        :return:
        """

        cls.user_model = get_user_model()
        cls.user_one = cls.user_model.objects.create_user("User 1",
                                                          "*****@*****.**",
                                                          "password1",
                                                          is_active=True)
        cls.super_user = cls.user_model.objects.create_superuser(
            "Super User", "*****@*****.**", "SuperUserPassword")

        os = OvertimeService(cls.user_one)
        cls.today = os.today

        test_data = [
            # time_in, break,  time_out
            ((8, 00), (0, 30), (16, 00)),
            ((8, 00), (0, 30), (16, 30)),
            ((8, 00), (0, 30), (16, 00)),
            ((8, 00), (0, 30), (16, 30)),
            ((8, 00), (0, 30), (16, 00)),
        ]

        for i, day in enumerate(os.get_this_week_as_date_list()):
            time_in, lunch, time_out = test_data[i]

            FlexiTimeLog.objects.create(
                user=cls.user_one,
                log_date=day,
                logged_in=as_time(*time_in),
                break_duration=as_time(*lunch),
                logged_out=as_time(*time_out),
            )