def test_left_boundary(self): """ The first day of the given date range gets indexes (0, 0) """ first_date = '12032018' today = date(2018, 3, 12) week, day = get_date_indexes(first_date, today) assert day == 0, 'Day index must be 0' assert week == 0, 'Week index must be 0'
def test_from_monday_to_saturday_odd(self): """ Test indexes for the first six days of the given date range """ first_date = '12032018' for d in range(12, 18): today = date(2018, 3, d) week, day = get_date_indexes(first_date, today) assert day == d - 12, f'Day index must be {d - 12}' assert week == 0, 'Week index must be 0'
def test_day_after_right_boundary(self): """ The day after the last day of the given date range gets indexes of the first day of the date range (by modulo 14), i. e. (0, 0) """ first_date = '12032018' today = date(2018, 3, 26) week, day = get_date_indexes(first_date, today) assert day == 0, 'Day index must be 0' assert week == 0, 'Week index must be 0'
def test_even_sunday(self): """ The second (even) Sunday of the given date range gets indexes of the next day (by modulo 14), i.e. (0, 0) """ first_date = '12032018' today = date(2018, 3, 25) week, day = get_date_indexes(first_date, today) assert day == 0, 'Day index must be 0' assert week == 0, 'Week index must be 0'
def test_odd_sunday(self): """ The first (odd) Sunday of the given date range gets indexes of the next day, i.e. (1, 0) """ first_date = '12032018' today = date(2018, 3, 18) week, day = get_date_indexes(first_date, today) assert day == 0, 'Day index must be 0' assert week == 1, 'Week index must be 1'
def test_from_monday_to_saturday_even(self): """ Test indexes for the first six days (the second week) of the given date range """ first_date = '12032018' for d in range(19, 24): today = date(2018, 3, d) week, day = get_date_indexes(first_date, today) assert day == d - 19, f'Day index must be {d - 19}' assert week == 1, 'Week index must be 1'
def get_schedule(group_id, season): if season == 'autumn': season_key = '1' elif season == 'spring': season_key = '2' else: return error_response(422, 'INVALID_SEASON') group_name = get_repository().get_group_name(group_id) if group_name is None: return error_response(422, 'NO_SUCH_GROUP') range_ = get_repository().get_group_date_range(group_id, season) if range_ is None: return error_response(422, 'NO_SUCH_SCHEDULE') try: w, d = date.get_date_indexes(range_[0]) today = date.get_date_by_indexes(range_[0], w, d) return jsonify({ 'group': group_name, 'date_range': { 'begin': range_[0], 'end': range_[1] }, 'today': { 'week': w, 'dayOfWeek': d, 'date': today }, 'weeks': fetch_group_schedule(group_id, season_key, range_) }) except ParseException as ex: return error_response(422, str(ex))