Esempio n. 1
0
    def test_choice(self):
        """Test choices validations for the Integer field"""
        class StatusChoices(enum.Enum):
            """Set of choices for the status"""

            PENDING = (0, "Pending")
            SUCCESS = (1, "Success")
            ERROR = (2, "Error")

        status = Integer(choices=StatusChoices)
        assert status is not None

        # Test loading of values to the status field
        assert status._load(0) == 0
        with pytest.raises(ValidationError) as e_info:
            status._load(4)
        assert e_info.value.messages == {
            "unlinked":
            ["Value `4` is not a valid choice. "
             "Must be among [0, 1, 2]"]
        }
Esempio n. 2
0
    def test_min_value(self):
        """Test minimum value validation for the integer field"""

        with pytest.raises(ValidationError):
            age = Integer(min_value=5)
            age._load(3)
Esempio n. 3
0
 def test_type_validation(self):
     """Test type checking validation for the Field"""
     with pytest.raises(ValidationError):
         age = Integer()
         age._load("x")
Esempio n. 4
0
 def test_various_input_values(self):
     age = Integer()
     assert age._load(12) == 12
     assert age._load("12") == 12
     assert age._load(None) is None
     assert age._load("") is None