Exemple #1
0
 def setup_method(self):
     self.valid_msg1 = 'Is Valid 1'
     self.valid_msg2 = 'Is Valid 2'
     self.invalid_mg1 = 'Invalid 1'
     data = {
         'name': {
             'name1': 'abcabc',
             'name2': 'abc-abc',
             'name3': 'abc-abc'
         }
     }
     vmap = {
         'name': {
             'name1':
             Catch(
                 StrShouldContains('-',
                                   exc=CustomException(self.invalid_mg1),
                                   valid_msg=self.valid_msg1)),
             'name2':
             StrShouldContains('-', valid_msg=self.valid_msg2),
             'name3': [
                 StrShouldContains('-', valid_msg=self.valid_msg1),
                 StrShouldContains('-', valid_msg=self.valid_msg2)
             ]
         }
     }
     self.result_map = Validator(vmap).validate(data)
 def test_validate_absent_field_custom_exc(self):
     data = {'name_diff': 'abcabc'}
     vmap = {
         'name': CanNotBeAEmptyStr(required_exc=CustomException('Test'))
     }
     validator = Validator(vmap)
     with pytest.raises(CustomException):
         validator.validate(data)
 def test_validate_invalid_custom_exc(self):
     data = {'name': 'abc123'}
     vmap = {
         'name': ShouldContainsOnlyChars(exc=CustomException('Testing'))
     }
     validator = Validator(vmap)
     with pytest.raises(CustomException):
         validator.validate(data)
 def test_validate_absent_field_custom_exc(self):
     data = {'name_diff': 'abcabc'}
     vmap = {
         'name':
         ShouldContainsOnlyChars(required_exc=CustomException('Test'))
     }
     validator = Validator(vmap)
     with pytest.raises(CustomException):
         validator.validate(data)
 def test_validate_invalid_catch(self):
     exc_msg = 'Testing'
     data = {'name': 'abc'}
     vmap = {'name': Catch(ShouldBeInt(exc=CustomException(exc_msg)))}
     validator = Validator(vmap)
     result_map = validator.validate(data)
     assert 'name' in result_map.keys()
     assert result_map['name'].field_name == 'name'
     assert result_map['name'].valid is False
     assert result_map['name'].msg == exc_msg
Exemple #6
0
 def test_validate_invalid_custom_exc(self):
     data = {
         'name': 'abcabc'
     }
     vmap = {
         'name': MinLengthStr(10, exc=CustomException('Testing'))
     }
     validator = Validator(vmap)
     with pytest.raises(CustomException):
         validator.validate(data)
 def test_validate_absent_field_cacth(self):
     exc_msg = 'Testing'
     data = {'name_diff': ''}
     vmap = {
         'name': Catch(CanNotBeNone(required_exc=CustomException(exc_msg)))
     }
     validator = Validator(vmap)
     result_map = validator.validate(data)
     assert 'name' in result_map.keys()
     assert result_map['name'].field_name == 'name'
     assert result_map['name'].valid is False
     assert result_map['name'].msg == exc_msg
 def test_validate_invalid_custom_exc(self):
     data = {'num': 'abc'}
     vmap = {'num': ShouldBeInt(exc=CustomException('Testing'))}
     validator = Validator(vmap)
     with pytest.raises(CustomException):
         validator.validate(data)
 def test_validate_invalid_custom_exc(self):
     data = {'name': ''}
     vmap = {'name': CanNotBeAEmptyStr(exc=CustomException('Testing'))}
     validator = Validator(vmap)
     with pytest.raises(CustomException):
         validator.validate(data)