Exemplo n.º 1
0
    def test_is_valid_time(self):
        ReservationRule(start_time=datetime.time(10, 0),
                        end_time=datetime.time(6, 0),
                        days_changed=1,
                        start_days=1,
                        max_inside_border_crossed=5,
                        machine_type=self.machine_type,
                        max_hours=10).save()
        ReservationRule(start_time=datetime.time(6, 0),
                        end_time=datetime.time(12, 0),
                        days_changed=2,
                        start_days=2,
                        max_inside_border_crossed=16,
                        machine_type=self.machine_type,
                        max_hours=16).save()

        self.assertTrue(
            ReservationRule.valid_time(datetime.datetime(2018, 11, 5, 12, 0),
                                       datetime.datetime(2018, 11, 5, 18, 0),
                                       self.machine_type),
            "Periods that cover only one rule, should be valid if they are valid in that rule"
        )
        self.assertFalse(
            ReservationRule.valid_time(datetime.datetime(2018, 11, 5, 12, 0),
                                       datetime.datetime(2018, 11, 5, 23, 0),
                                       self.machine_type),
            "Periods that cover only one rule, should be valid if they are valid in that rule"
        )
        self.assertTrue(
            ReservationRule.valid_time(datetime.datetime(2018, 11, 6, 12, 0),
                                       datetime.datetime(2018, 11, 7, 3, 0),
                                       self.machine_type),
            "Periods that cover only one rule, should be valid if they are valid in that rule"
        )
        self.assertFalse(
            ReservationRule.valid_time(datetime.datetime(2018, 11, 6, 12, 0),
                                       datetime.datetime(2018, 11, 7, 18, 0),
                                       self.machine_type),
            "Periods that cover only one rule, should be valid if they are valid in that rule"
        )

        self.assertTrue(
            ReservationRule.valid_time(datetime.datetime(2018, 11, 6, 3, 0),
                                       datetime.datetime(2018, 11, 6, 18, 0),
                                       self.machine_type),
            "A period may still be valid, even though its total duration is larger than what is allowed in"
            "one of the rules it partially covers")

        self.assertFalse(
            ReservationRule.valid_time(datetime.datetime(2018, 11, 6, 1, 0),
                                       datetime.datetime(2018, 11, 6, 22, 0),
                                       self.machine_type),
            "A period may be valid in each rule, it can still be invalid due to its total duration"
        )

        self.assertFalse(
            ReservationRule.valid_time(datetime.datetime(2018, 11, 6, 0, 0),
                                       datetime.datetime(2018, 11, 6, 12, 0),
                                       self.machine_type),
            "A period may not be valid in one of the rules is covers")
Exemplo n.º 2
0
 def test_is_valid_time_max_interval(self):
     self.assertFalse(
         ReservationRule.valid_time(datetime.datetime(2018, 11, 5, 0, 0),
                                    datetime.datetime(2018, 11, 12, 0, 1),
                                    self.machine_type), """
                      Reservations should not be valid if they are longer than 1 week, as the logic won't work 
                      correctly. Reservations can still be longer than 1 week if they are allowed to ignore the
                      rules.
                      """)