Ejemplo n.º 1
0
 def test_decoding(self):
     schema, _locations = xmlschema.fetch_schema_locations(
         xml_file, locations)
     xs = schema_class(schema, locations=_locations)
     errors = []
     chunks = []
     for obj in xs.iter_decode(xml_file):
         if isinstance(obj, (xmlschema.XMLSchemaDecodeError,
                             xmlschema.XMLSchemaValidationError)):
             errors.append(obj)
         else:
             chunks.append(obj)
     if len(errors) != expected_errors:
         raise ValueError("n.%d errors expected, found %d: %s" %
                          (expected_errors, len(errors), '\n++++++\n'.join(
                              [str(e) for e in errors[:3]])))
     if not chunks:
         raise ValueError("No decoded object returned!!")
     elif len(chunks) > 1:
         raise ValueError(
             "Too many ({}) decoded objects returned: {}".format(
                 len(chunks), chunks))
     elif not isinstance(chunks[0], dict):
         raise ValueError(
             "Decoded object is not a dictionary: {}".format(chunks))
     else:
         self.assertTrue(
             True, "Successfully test decoding for {}".format(xml_file))
Ejemplo n.º 2
0
 def test_fetch_schema_locations(self):
     locations = fetch_schema_locations(self.col_xml_file)
     self.check_url(locations[0], self.col_xsd_file)
     self.assertEqual(locations[1][0][0],
                      'http://example.com/ns/collection')
     self.check_url(locations[1][0][1], self.col_xsd_file)
     self.check_url(fetch_schema(self.vh_xml_file), self.vh_xsd_file)
Ejemplo n.º 3
0
 def test_fetch_schema_locations(self):
     locations = fetch_schema_locations(self.col_xml_file)
     self.assertEqual(locations,
                      (FILE_SCHEME.format(self.col_schema_file), [
                          ('http://example.com/ns/collection',
                           FILE_SCHEME.format(self.col_schema_file))
                      ]))
     self.assertEqual(fetch_schema(self.vh_xml_file),
                      FILE_SCHEME.format(self.vh_schema_file))
Ejemplo n.º 4
0
        def setUpClass(cls):
            if debug_mode:
                print("\n##\n## Testing schema %s in debug mode.\n##" % rel_path)
                pdb.set_trace()

            # Builds schema instance using 'lax' validation mode to accepts also schemas with not crashing errors.
            source, _locations = xmlschema.fetch_schema_locations(xml_file, locations)
            cls.schema = schema_class(source, validation='lax', locations=_locations, defuse=defuse)

            cls.errors = []
            cls.chunks = []
            cls.longMessage = True
        def setUpClass(cls):
            # Builds schema instance using 'lax' validation mode to accepts also schemas with not crashing errors.
            cls.schema_class = schema_class
            source, _locations = xmlschema.fetch_schema_locations(xml_file, locations)
            cls.schema = schema_class(source, validation='lax', locations=_locations, defuse=defuse)
            if check_with_lxml and lxml_etree is not None:
                cls.lxml_schema = lxml_etree.parse(source)

            cls.errors = []
            cls.chunks = []
            cls.longMessage = True

            if debug_mode:
                print("\n##\n## Testing %r validation in debug mode.\n##" % xml_file)
                pdb.set_trace()
Ejemplo n.º 6
0
 def test_validation(self):
     schema, _locations = xmlschema.fetch_schema_locations(
         xml_file, locations)
     xs = schema_class(schema, locations=_locations)
     errors = [str(e) for e in xs.iter_errors(xml_file)]
     if len(errors) != expected_errors:
         raise ValueError(
             "n.%d errors expected, found %d: %s" %
             (expected_errors, len(errors), '\n++++++\n'.join(errors[:3])))
     if expected_errors == 0:
         self.assertTrue(
             True, "Successfully validated {} with schema {}".format(
                 xml_file, schema))
     else:
         self.assertTrue(
             True,
             "Validation of {} under the schema {} with n.{} errors".format(
                 xml_file, schema, expected_errors))
Ejemplo n.º 7
0
 def test_fetch_schema_locations(self):
     locations = fetch_schema_locations(self.col_xml_file)
     self.check_url(locations[0], self.col_xsd_file)
     self.assertEqual(locations[1][0][0], 'http://example.com/ns/collection')
     self.check_url(locations[1][0][1], self.col_xsd_file)
     self.check_url(fetch_schema(self.vh_xml_file), self.vh_xsd_file)