コード例 #1
0
    def test_choice(self):
        """ Test choices validations for the string field """
        class StatusChoices(enum.Enum):
            """ Set of choices for the status"""
            PENDING = 'Pending'
            SUCCESS = 'Success'
            ERROR = 'Error'

        status = String(max_length=10, choices=StatusChoices)
        assert status is not None

        # Test loading of values to the status field
        assert status._load('Pending') == 'Pending'
        with pytest.raises(ValidationError) as e_info:
            status._load('Failure')
        assert e_info.value.messages == {
            'unlinked': [
                "Value `'Failure'` is not a valid choice. "
                "Must be one of ['Pending', 'Success', 'Error']"
            ]
        }
コード例 #2
0
    def test_min_length(self):
        """ Test minimum length validation for the string field"""

        with pytest.raises(ValidationError):
            name = String(min_length=5, max_length=10)
            name._load('Dum')
コード例 #3
0
    def test_max_length(self):
        """ Test maximum length validation for the string field"""

        with pytest.raises(ValidationError):
            name = String(max_length=5)
            name._load('Dummy Dummy')
コード例 #4
0
 def test_type_validation(self):
     """ Test type checking validation for the Field"""
     name = String(max_length=10)
     assert name._load(1) == '1'