示例#1
0
 def test_no_delimiter_error(self):
     """raise Error when no delimiter field added
     """
     val = DwcaValidator(yaml.load(self.yaml_delimited5))
     document = {'sex' : 'male | female '}
     with self.assertRaises(ValueError):
         val.validate(document)
示例#2
0
 def test_multiple_if_combi(self):
     """document satisfies if and non-if clauses
     """
     schema = yaml.load(self.yaml_ifcombi)
     document = {'basisOfRecord': 'PreservedSpecimen', 'collectionCode': ''}
     val = DwcaValidator(schema)
     self.assertTrue(val.validate(document))
 def test_default_ignore_empty_string(self):
     """empty string (converted to None values) should provide an error
     by default
     """
     val = DwcaValidator(yaml.load(self.yaml_string))
     document = {'abundance': ''}
     self.assertFalse(val.validate(document))
示例#4
0
 def test_multiple_if_pass(self):
     """document satisfies both if clauses at the same time
     """
     schema = yaml.load(self.yaml_ifif)
     document = {'age' : '21', 'lifestage':'adult'} #True
     val = DwcaValidator(schema)
     self.assertTrue(val.validate(document))
 def test_no_number_usage(self):
     """check the error statement providing info about datatype when coerce
     not possible
     """
     val = DwcaValidator(yaml.load(self.yaml_string))
     document = {'percentage': u'tien'}
     val.validate(document)
     self.assertIn('must be of number type', val.errors['percentage'])
示例#6
0
 def test_minmax_float(self):
     """test if the value has minimal value
     """
     val = DwcaValidator(yaml.load(self.yaml_value))
     document = {'percentage' : 9.}
     self.assertFalse(val.validate(document))
     document = {'percentage' : 2.1}
     self.assertFalse(val.validate(document))
示例#7
0
 def test_length(self):
     """test if the string has proper minimal length
     """
     val = DwcaValidator(yaml.load(self.yaml_length))
     document = {'verbatimCoordinateSystem' : '31UDS'}
     self.assertTrue(val.validate(document))
     document = {'verbatimCoordinateSystem' : '3'}
     self.assertFalse(val.validate(document))
示例#8
0
 def test_number(self):
     """test if a field is a number
     """
     val = DwcaValidator(yaml.load(self.yaml_dtypes))
     document = {'percentage': 2.2}
     self.assertTrue(val.validate(document))
     document = {'percentage': 2}
     self.assertTrue(val.validate(document))
示例#9
0
 def test_numberformat_right(self):
     val = DwcaValidator(yaml.load(self.yaml_numberformat1))
     document = {'size' : '1110.14372'} # True
     self.assertTrue(val.validate(document))
     document = {'size' : '.14372'} # True
     self.assertTrue(val.validate(document))
     document = {'size' : '0.1437'} # False
     self.assertFalse(val.validate(document))
示例#10
0
 def test_min_int_coerce(self):
     """test if the value has minimal value
     """
     val = DwcaValidator(yaml.load(self.yaml_value))
     document = {'code' : '6'}
     self.assertTrue(val.validate(document))
     document = {'code' : '2'}
     self.assertFalse(val.validate(document))
示例#11
0
 def test_maxlength(self):
     """test if the string has proper maximal length
     """
     val = DwcaValidator(yaml.load(self.yaml_length))
     document = {'coordinateSystem' : '31U'}
     self.assertTrue(val.validate(document))
     document = {'coordinateSystem' : '31UDS76C'}
     self.assertFalse(val.validate(document))
示例#12
0
 def test_minmax_int(self):
     """test if the value has minimal value
     """
     val = DwcaValidator(yaml.load(self.yaml_value))
     document = {'individualCount' : 9}
     self.assertFalse(val.validate(document))
     document = {'individualCount' : 2}
     self.assertFalse(val.validate(document))
示例#13
0
 def test_numberformat_integer(self):
     val = DwcaValidator(yaml.load(self.yaml_numberformat3))
     document = {'size' : '1234.'} # True
     self.assertTrue(val.validate(document))
     document = {'size' : '1234.55555'} # True
     self.assertTrue(val.validate(document))
     document = {'size' : '1234'} # True
     self.assertTrue(val.validate(document))
示例#14
0
 def test_allowed_list(self):
     """test if the value is one of the allowed values
     """
     val = DwcaValidator(yaml.load(self.yaml_allow))
     document = {'rightsHolder' : 'INBO'}
     self.assertTrue(val.validate(document))
     document = {'rightsHolder' : 'ILVO'}
     self.assertFalse(val.validate(document))
示例#15
0
 def test_euqals_float(self):
     """test if the float value equals the given value
     """
     val = DwcaValidator(yaml.load(self.yaml_length))
     # here not type test needed in schema, value given as float
     document = {'precision' : 200.00}
     self.assertTrue(val.validate(document))
     document = {'precision' : 200.001}
     self.assertFalse(val.validate(document))
示例#16
0
 def test_euqals_int(self):
     """test if the integer value equals the given value
     """
     val = DwcaValidator(yaml.load(self.yaml_length))
     # here not type test needed in schema, value given as integer
     document = {'individualCount' : 1.000}
     self.assertTrue(val.validate(document))
     document = {'individualCount' : 2}
     self.assertFalse(val.validate(document))
示例#17
0
 def test_wrong_json_type(self):
     document = {'size' : 'large',
                 'perimeter': """
                                 {"top": 3, "centre": 5, "bottom": 6
                                 """}
     schema = {'perimeter':{'type':'json'}}
     val = DwcaValidator(schema)
     val.allow_unknown = True
     self.assertFalse(val.validate(document))
 def test_float_usage_coerce_fail(self):
     """if failing this, the coerce addition failed to work
     """
     val = DwcaValidator(yaml.load(self.yaml_string))
     document = {'decimalLatitude' : '51.55'}
     val.validate(document)
     self.assertNotEqual(val.errors,
                         {'decimalLatitude': 'must be of float type'},
                         msg="addition of coerce to pre-interpret datatype float is failing")
 def test_int_usage_coerce_fail(self):
     """if failing this, the coerce addition failed to work
     """
     val = DwcaValidator(yaml.load(self.yaml_string))
     document = {'individualCount': u'1'}
     val.validate(document)
     self.assertNotEqual(val.errors,
                         {'individualCount': 'must be of integer type'},
                         msg="addition of coerce to pre-interpret datatype integer is failing")
示例#20
0
 def test_delimiter_wrong_delimiter(self):
     """splitting is just not occuring, so warning will be on
     unallowed value
     """
     val = DwcaValidator(yaml.load(self.yaml_delimited1))
     document = {'sex' : 'male ; female'} # False, due to wrong endname
     self.assertFalse(val.validate(document))
     self.assertEqual(val.errors,
                      {'sex': {0: 'unallowed value male ; female'}})
示例#21
0
    def test_daterange_out(self):
        # outside the range
        val = DwcaValidator(yaml.load(self.yaml_string_date1))
        document = {'moment': '17000101'}  # False
        self.assertFalse(val.validate(document))

        val = DwcaValidator(yaml.load(self.yaml_string_date1))
        document = {'moment': '20150831'}  # False
        self.assertFalse(val.validate(document))
示例#22
0
    def test_required(self):
        """test if a field (key) is present
        """
        val = DwcaValidator(yaml.load(self.yaml_required))
        document = {'moment' : '2016-12-11'}
        self.assertTrue(val.validate(document))

        document = {'sex' : '2016-12-11'}
        self.assertFalse(val.validate(document))
 def test_empty_string(self):
     """conversion empty string to None in document
     """
     val = DwcaValidator(yaml.load(self.yaml_string))
     document = {'abundance': ''}
     val.validate(document)
     self.assertEqual(val.document,
                 {'abundance': None},
                 msg="pre-conversion of empty strings to None not supported")
示例#24
0
 def test_multiple_if_combi_nonpass(self):
     """document satisfies if and non-if clauses
     """
     schema = yaml.load(self.yaml_ifcombi)
     document = {'basisOfRecord': 'HumanObservation', 'collectionCode': ''}
     val = DwcaValidator(schema)
     val.validate(document)
     self.assertEqual(val.errors,
                      {'basisOfRecord': {'if': 'unallowed value HumanObservation'}})
 def test_bool_usage_coerce_fail(self):
     """if failing this, the coerce addition failed to work
     """
     val = DwcaValidator(yaml.load(self.yaml_string))
     document = {'abundance': u'true'}
     val.validate(document)
     self.assertNotEqual(val.errors,
                         {'abundance': 'must be of boolean type'},
                         msg="addition of coerce to pre-interpret datatype boolean is failing")
示例#26
0
 def test_max_int_string(self):
     """test if the value has maximal value with string input
     """
     val = DwcaValidator(yaml.load(self.yaml_string))
     document = {'code' : 'vijf'} # provide error on type mismatch
     val.validate(document)
     self.assertEqual(val.errors,
                 {'code': 'max validation ignores string type, add type validation'},
                 msg="alert on datatype mismatch for min evaluation fails")
示例#27
0
 def test_multiple_if_error(self):
     """term trespasses both if clauses at the same time
     """
     schema = yaml.load(self.yaml_ifif)
     document = {'age' : '21', 'lifestage':'juvenile'} #True
     val = DwcaValidator(schema)
     val.validate(document)
     self.assertEqual(val.errors,
                      {'lifestage': {'if_0': 'unallowed value juvenile',
                                     'if_1': 'max length is 6'}})
示例#28
0
 def test_json_type(self):
     yaml_string = """
                     perimeter:
                         type: json
                     """
     schema = yaml.load(yaml_string)
     document = {'perimeter': """
                                 {"top": 3, "centre": 5, "bottom": 6}
                                 """}
     val = DwcaValidator(schema)
     self.assertTrue(val.validate(document))
 def test_nested_coerce_of_rules(self):
     """type statements can NOT be inside the *of rules
     cfr. https://github.com/nicolaiarocci/cerberus/issues/230
     """
     schema  ="""
             decimalLatitude:
                 oneof :
                     - allowed : [10]
                     - min : 3.
                       type : 'float'
              """
     val = DwcaValidator(yaml.load(schema))
     document = {'decimalLatitude': '4'}
     self.assertFalse(val.validate(document))
示例#30
0
 def test_dateformat_single(self):
     val = DwcaValidator(yaml.load(self.yaml_string_date3))
     document = {'moment': '1997-01'}  # True
     self.assertTrue(val.validate(document))