Esempio n. 1
0
    def clean(self):
        cleaned_data = super().clean()

        rule = ReservationRule(machine_type=cleaned_data["machine_type"], max_hours=0, max_inside_border_crossed=0,
                               start_time=cleaned_data["start_time"], end_time=cleaned_data["end_time"],
                               days_changed=cleaned_data["days_changed"], start_days=self.get_start_days(cleaned_data))

        rule.is_valid_rule(raise_error=True)

        return cleaned_data
Esempio n. 2
0
    def test_is_valid_rule_external(self):
        ReservationRule(start_time=datetime.time(10, 0),
                        end_time=datetime.time(6, 0),
                        days_changed=1,
                        start_days=53,
                        max_inside_border_crossed=0,
                        machine_type=self.machine_type,
                        max_hours=0).save()

        rule = ReservationRule(start_time=datetime.time(12, 0),
                               end_time=datetime.time(18, 0),
                               days_changed=0,
                               start_days=66,
                               max_inside_border_crossed=0,
                               machine_type=self.machine_type,
                               max_hours=0)

        self.assertTrue(rule.is_valid_rule())

        rule = ReservationRule(start_time=datetime.time(5, 0),
                               end_time=datetime.time(12, 0),
                               days_changed=0,
                               start_days=2,
                               max_inside_border_crossed=0,
                               machine_type=self.machine_type,
                               max_hours=0)

        self.assertFalse(rule.is_valid_rule())
        try:
            rule.is_valid_rule(raise_error=True)
            self.fail(
                "An exception should have been raised for a check on a non valid rule with raise_error set"
            )
        except ValidationError:
            pass

        try:
            rule.save()
            self.fail("Valid rules should not be saveable")
        except ValidationError:
            pass

        rule.machine_type = MachineTypeField.get_machine_type(2)
        self.assertTrue(
            rule.is_valid_rule(),
            "Rules for different machine types should not effect the validity of each other"
        )
Esempio n. 3
0
    def test_is_valid_rule_internal(self):
        rule = ReservationRule(start_time=datetime.time(10, 0),
                               end_time=datetime.time(6, 0),
                               days_changed=1,
                               start_days=53,
                               max_inside_border_crossed=0,
                               machine_type=self.machine_type,
                               max_hours=0)
        self.assertTrue(
            rule.is_valid_rule(),
            "A rule with a difference of less than 24h between start_time and end_time should not overlap with it self"
        )

        rule = ReservationRule(start_time=datetime.time(10, 0),
                               end_time=datetime.time(12, 0),
                               days_changed=1,
                               start_days=3,
                               max_inside_border_crossed=0,
                               machine_type=self.machine_type,
                               max_hours=0)

        self.assertFalse(
            rule.is_valid_rule(),
            "A rule with periods of more than 24h cannot have two successive days"
        )

        rule = ReservationRule(start_time=datetime.time(10, 0),
                               end_time=datetime.time(12, 0),
                               days_changed=1,
                               start_days=65,
                               max_inside_border_crossed=0,
                               machine_type=self.machine_type,
                               max_hours=0)

        self.assertFalse(
            rule.is_valid_rule(),
            "A rule with periods of more than 24h cannot have two successive days"
        )
        try:
            rule.is_valid_rule(raise_error=True)
            self.fail(
                "An exception should have been raised for a check on a non valid rule with raise_error set"
            )
        except ValidationError:
            pass

        rule = ReservationRule(start_time=datetime.time(10, 0),
                               end_time=datetime.time(12, 0),
                               days_changed=7,
                               start_days=1,
                               max_inside_border_crossed=0,
                               machine_type=self.machine_type,
                               max_hours=0)

        self.assertFalse(rule.is_valid_rule(),
                         "A rule cannot cover more than a week")
        try:
            rule.is_valid_rule(raise_error=True)
            self.fail(
                "An exception should have been raised for a check on a non valid rule with raise_error set"
            )
        except ValidationError:
            pass