Exemplo n.º 1
0
    def test_shift_stores_in_database(self):
        user_id = 1
        start_time = now().replace(microsecond=0)
        end_time = start_time + timedelta(hours=1)

        shift = Shift(user_id, start_time, end_time, job_name='dd')
        shift.save_to_database()

        temp_shift = Shift.query.get(shift.id)

        self.assertEqual(temp_shift.start_time, shift.start_time)

        db.session.delete(shift)
        db.session.commit()
Exemplo n.º 2
0
 def __init__(self, user_id, start=None, end=None):
     self.user = User.get_user_by_id(user_id)
     self.start_date = start or beginning_of_week()
     self.end_date = end or end_of_week()
     self.shifts = Shift.get_shifts_by_user_id(user_id, start_time=start, end_time=end)
     self.row = [None] * self.get_count_of_days_in_range()
     self.populate_list_of_shifts()
Exemplo n.º 3
0
    def test_get_all_shifts_by_id(self):

        user_id = 3
        start_time_first = self.week_start - timedelta(days=10)
        start_time_next = self.week_start
        start_time_last = self.week_end + timedelta(days=10)

        shift1 = Shift(user_id, start_time_first, start_time_first + timedelta(hours=5))
        shift1.save_to_database()

        shift2 = Shift(user_id, start_time_next, start_time_next + timedelta(hours=5))
        shift2.save_to_database()

        shift3 = Shift(user_id, start_time_last, start_time_last + timedelta(hours=5))
        shift3.save_to_database()

        shift_list = Shift.get_shifts_by_user_id(user_id)

        self.assertEqual(len(shift_list), 3)

        db.session.delete(shift1)
        db.session.delete(shift2)
        db.session.delete(shift3)
        db.session.commit()
Exemplo n.º 4
0
    def test_get_all_shifts_before_end_time(self):

        user_id = 5
        first_start = beginning_of_week()
        first_end = first_start + timedelta(hours=5)
        second_start = first_start + timedelta(hours=10)
        second_end = second_start + timedelta(hours=5)

        shift1 = Shift(user_id, first_start, first_end)
        shift1.save_to_database()

        shift2 = Shift(user_id, second_start, second_end)
        shift2.save_to_database()

        search_end = second_end - timedelta(hours=1)

        shift_list = Shift.get_shifts_by_user_id(user_id, end_time=search_end)

        self.assertEqual(len(shift_list), 1)

        db.session.delete(shift1)
        db.session.delete(shift2)
        db.session.commit()