def test_allowedvalues_ranges_validator(self):
        """Test allowed values - ranges"""

        allowed_value = AllowedValue()
        allowed_value.allowed_type = ALLOWEDVALUETYPE.RANGE
        allowed_value.minval = 1
        allowed_value.maxval = 11
        allowed_value.spacing = 2
        allowed_value.range_closure = RANGECLOSURETYPE.OPEN

        inpt = get_input(allowed_values = [allowed_value])

        inpt.data = 1
        self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE), 'Range OPEN closure')

        inpt.data = 12
        self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE), 'Value too big')

        inpt.data = 5
        self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE), 'Spacing not fit')

        inpt.data = 4
        self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE), 'Spacing fits')

        inpt.data = 11
        allowed_value.range_closure = RANGECLOSURETYPE.OPEN
        self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE), 'Open Range')

        allowed_value.range_closure = RANGECLOSURETYPE.OPENCLOSED
        self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE), 'OPENCLOSED Range')

        inpt.data = 1
        allowed_value.range_closure = RANGECLOSURETYPE.CLOSEDOPEN
        self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE), 'CLOSEDOPEN Range')
示例#2
0
    def test_combined_validator(self):
        """Test allowed values - ranges and values combination"""

        allowed_value1 = AllowedValue()
        allowed_value1.allowed_type = ALLOWEDVALUETYPE.RANGE
        allowed_value1.minval = 1
        allowed_value1.maxval = 11
        allowed_value1.spacing = 2
        allowed_value1.range_closure = RANGECLOSURETYPE.OPEN

        allowed_value2 = AllowedValue()
        allowed_value2.allowed_type = ALLOWEDVALUETYPE.VALUE
        allowed_value2.value = 15

        inpt = get_input(allowed_values=[allowed_value1, allowed_value2])

        inpt.data = 1
        self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE),
                        'Range OPEN closure')

        inpt.data = 15
        self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE),
                        'AllowedValue')

        inpt.data = 13
        self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE),
                         'Out of range')
    def test_combined_validator(self):
        """Test allowed values - ranges and values combination"""

        allowed_value1 = AllowedValue()
        allowed_value1.allowed_type = ALLOWEDVALUETYPE.RANGE
        allowed_value1.minval = 1
        allowed_value1.maxval = 11
        allowed_value1.spacing = 2
        allowed_value1.range_closure = RANGECLOSURETYPE.OPEN

        allowed_value2 = AllowedValue()
        allowed_value2.allowed_type = ALLOWEDVALUETYPE.VALUE
        allowed_value2.value = 15

        inpt = get_input(allowed_values = [allowed_value1, allowed_value2])

        inpt.data = 1
        self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE), 'Range OPEN closure')

        inpt.data = 15
        self.assertTrue(validate_allowed_values(inpt, MODE.SIMPLE), 'AllowedValue')

        inpt.data = 13
        self.assertFalse(validate_allowed_values(inpt, MODE.SIMPLE), 'Out of range')