def test_schedule_detail_mgr_init(self):
     ScheduleDetailMgr.instance()
     with self.assertRaises(
             Exception,
             msg="Invoking ScheduleDetailMgr() raises an exception"
     ) as error:
         ScheduleDetailMgr()
 def test_schedule_detail_mgr_service_dates_none(self):
     start, end = ScheduleDetailMgr.instance().get_service_start_and_end(
         'yard waste')
     self.assertTrue(
         start == None and end == None,
         "We get None back for start and end dates when they don't exist for a service"
     )
 def test_is_service_active_yard_waste_too_late(self):
     make_schedule_detail(detail_type='start-date',
                          service_type=ScheduleDetail.YARD_WASTE,
                          new_day=datetime.date(2017, 3, 1))
     make_schedule_detail(detail_type='end-date',
                          service_type=ScheduleDetail.YARD_WASTE,
                          new_day=datetime.date(2017, 11, 1))
     self.assertFalse(
         ScheduleDetailMgr.instance().is_service_active(
             'yard waste', datetime.date(2017, 12, 1)),
         "Yard waste is inactive after end")
 def test_is_service_active_yard_waste(self):
     make_schedule_detail(detail_type='start-date',
                          service_type=ScheduleDetail.YARD_WASTE,
                          new_day=datetime.date(2017, 3, 1))
     make_schedule_detail(detail_type='end-date',
                          service_type=ScheduleDetail.YARD_WASTE,
                          new_day=datetime.date(2017, 11, 1))
     self.assertTrue(
         ScheduleDetailMgr.instance().is_service_active(
             'yard waste', datetime.date(2017, 7, 1)),
         "Yard waste is active between start and end")
    def test_schedule_detail_mgr_service_dates(self):
        start_test = make_schedule_detail(
            detail_type='start-date',
            service_type=ScheduleDetail.YARD_WASTE,
            new_day=datetime.date(2017, 3, 1))
        end_test = make_schedule_detail(detail_type='end-date',
                                        service_type=ScheduleDetail.YARD_WASTE,
                                        new_day=datetime.date(2017, 11, 1))
        start, end = ScheduleDetailMgr.instance().get_service_start_and_end(
            'yard waste')

        self.assertEqual(
            start.new_day, start_test.new_day,
            "get_service_start_and_end() returns start date for a service")
        self.assertEqual(
            end.new_day, end_test.new_day,
            "get_service_start_and_end() returns end date for a service")
Beispiel #6
0
def add_additional_services(services, date, add_yard_waste_year_round=False):
    """
    Add in any services that are implicitly included in this list of services
    (e.g., yard waste is included whenever bulk is in the list).
    Note:  services that are not year-round should only be included if they
    are active for the given date, unless add_yard_waste_year_round is True.
    """
    if ScheduleDetail.ALL in services:
        services = ScheduleDetail.YEAR_ROUND_SERVICES.copy()

    # Special handling for yard waste, since it is on same schedule as bulk
    if includes_yard_waste(services) and (
            add_yard_waste_year_round
            or ScheduleDetailMgr.instance().is_service_active(
                ScheduleDetail.YARD_WASTE, date)):
        services.append(ScheduleDetail.YARD_WASTE)

    return services
Beispiel #7
0
    def has_service_on_date_week(self, service_type, date):
        """
        Returns true if the subscriber gets pickups for the given service
        on the week that the given date belongs to (i.e., checks whether the week
        is 'A' or 'B' and matches that with the subscriber's week type for the service)
        """

        if service_type == ScheduleDetail.TRASH:
            return True  # pragma: no cover  (should not get here)

        # examine all the subscriber's routes
        for route_id in util.split_csv(self.waste_area_ids):

            # get route info for this route, and check whether it matches the service
            route_info = ScheduleDetailMgr.instance().get_route_info(route_id)
            if route_info and ScheduleDetail.is_same_service_type(
                    service_type, route_info['services']):

                # now check if this route offers service on the given week
                week_type = BiWeekType.from_str(route_info['week'])
                if ScheduleDetail.check_date_service(date, week_type):
                    return True

        return False  # pragma: no cover  (should not get here)
 def test_is_service_active_default(self):
     self.assertFalse(
         ScheduleDetailMgr.instance().is_service_active(
             'yard waste', datetime.date(2017, 7, 1)),
         "When service start and end dates are not set up it is inactive")
 def test_is_service_active_trash(self):
     self.assertTrue(
         ScheduleDetailMgr.instance().is_service_active(
             'trash', datetime.date(2017, 7, 1)),
         "Year round services are active")
 def test_schedule_detail_mgr_singleton(self):
     self.assertEqual(id(ScheduleDetailMgr.instance()),
                      id(ScheduleDetailMgr.instance()),
                      "Only one instance of ScheduleDetailMgr exists")