コード例 #1
0
ファイル: field.py プロジェクト: vertical-knowledge/ripozo
 def test_field_translate_none(self):
     f = Field('f', required=True)
     self.assertRaises(ValidationException,
                       f.translate,
                       None,
                       validate=True)
     resp = f.translate(None, validate=False)
     self.assertIsNone(resp)
コード例 #2
0
 def test_validate_required_success(self):
     """
     Tests when the object is required and it is there
     """
     f = Field('f', required=True)
     resp = validate_required(f, 1)
     self.assertEqual(resp, 1)
コード例 #3
0
 def test_validate_regex(self):
     """Success case for validate_regex"""
     regex = re.compile(r'[a-z]*something[a-z]*')
     f = Field('f')
     obj = 'dfgfgfsomethingdfgfgfs'
     resp = validate_regex(f, obj, regex)
     self.assertEqual(resp, obj)
コード例 #4
0
 def test_validate_regex_multiple_matches(self):
     """Tests that the validation succeeds if there is more than one match"""
     regex = re.compile(r'something')
     f = Field('f')
     obj = 'somethingsomethingsomething'
     resp = validate_regex(f, obj, regex)
     self.assertEqual(resp, obj)
コード例 #5
0
 def test_validate_required_skipped(self):
     """
     Tests when the item is None and the validation is skipped
     because skip_required is True
     """
     f = Field('f', required=True)
     resp = validate_required(f, None, skip_required=True)
     self.assertEqual(resp, None)
コード例 #6
0
 def test_validate_required_non_required_field(self):
     """
     Tests the the field is validated if the field
     is not required and the object is None
     """
     f = Field('f', required=False)
     resp = validate_required(f, None, skip_required=False)
     self.assertEqual(resp, None)
コード例 #7
0
    def test_basic_validation_none_object(self, validate_type):
        """Check that validate_type is not called when object is None"""
        f = Field('f')
        basic_validation(f, None)
        self.assertFalse(validate_type.called)

        # Also ensure that it is called
        basic_validation(f, object())
        self.assertTrue(validate_type.called)
コード例 #8
0
 def test_validate_size_too_large(self):
     f = Field('blah')
     obj = 10
     self.assertRaises(ValidationException,
                       validate_size,
                       f,
                       obj,
                       obj,
                       maximum=9)
コード例 #9
0
 def test_validate_size_too_small(self):
     f = Field('blah')
     obj = 10
     self.assertRaises(ValidationException,
                       validate_size,
                       f,
                       obj,
                       obj,
                       minimum=11)
コード例 #10
0
ファイル: common.py プロジェクト: vaughnderson-su2/ripozo
    def __init__(self, name, indv_field=None, minimum=None, maximum=None, **kwargs):
        """

        :param unicode name: The name of the field.
        :param BaseField indv_field: The field to use when
            translating and validating individual items
            in the list.
        """
        self.indv_field = indv_field or Field('list')
        super(ListField, self).__init__(name, **kwargs)
        self.minimum = minimum
        self.maximum = maximum
コード例 #11
0
ファイル: field.py プロジェクト: ezramorris/ripozo
 def test_field_translate(self):
     f = Field('f')
     obj = object()
     resp = f.translate(obj)
     self.assertIs(obj, resp)
コード例 #12
0
 def test_validate_size(self):
     """Success case for validate size"""
     f = Field('blah')
     obj = 10
     resp = validate_size(f, obj, obj, minimum=10, maximum=10)
     self.assertEqual(resp, obj)
コード例 #13
0
 def test_validate_type_failure(self):
     """Failure case for validate_type"""
     f = Field('f')
     obj = 'blah'
     self.assertRaises(ValidationException, validate_type, f, int, obj)
コード例 #14
0
 def test_validate_type(self):
     """Success case for validate_type"""
     f = Field('f')
     obj = object()
     resp = validate_type(f, object, obj)
     self.assertIs(resp, obj)
コード例 #15
0
 def test_validate_required_failure(self):
     """Tests that it fails when the object is None"""
     f = Field('f', required=True)
     self.assertRaises(ValidationException, validate_required, f, None)
コード例 #16
0
ファイル: field.py プロジェクト: vertical-knowledge/ripozo
 def test_field_translate(self):
     f = Field('f')
     obj = object()
     resp = f.translate(obj)
     self.assertIs(obj, resp)
コード例 #17
0
 def test_validate_regex_failure(self):
     """Failure case for validate_regex"""
     regex = re.compile(r'something')
     f = Field('f')
     obj = 'notthatsome'
     self.assertRaises(ValidationException, validate_regex, f, obj, regex)
コード例 #18
0
 def test_basic_validation_required_failure(self):
     """Ensure failure when object is None and required"""
     f = Field('f', required=True)
     self.assertRaises(ValidationException, basic_validation, f, None)
コード例 #19
0
ファイル: field.py プロジェクト: ezramorris/ripozo
 def test_field_translate_none(self):
     f = Field('f', required=True)
     self.assertRaises(ValidationException, f.translate, None, validate=True)
     resp = f.translate(None, validate=False)
     self.assertIsNone(resp)
コード例 #20
0
 def test_basic_validation_skip_required(self):
     """Tests when skip_required is True and the object is None"""
     f = Field('f', required=True)
     resp = basic_validation(f, None, skip_required=True)
     self.assertIsNone(resp)
コード例 #21
0
 def test_basic_validation(self):
     """Success case for basic_validation"""
     f = Field('f', required=True)
     obj = object()
     resp = basic_validation(f, obj, skip_required=False)
     self.assertIs(resp, obj)