Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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'])
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 18
0
 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")
Exemplo n.º 19
0
 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")
Exemplo n.º 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'}})
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 23
0
 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")
Exemplo n.º 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'}})
Exemplo n.º 25
0
 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")
Exemplo n.º 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")
Exemplo n.º 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'}})
Exemplo n.º 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))
Exemplo n.º 29
0
 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))
Exemplo n.º 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))