Esempio n. 1
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)
Esempio n. 2
0
 def test_decoding(self):
     schema = xmlschema.fetch_schema(xml_file)
     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))
Esempio 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))
Esempio n. 4
0
 def test_validation(self):
     schema = xmlschema.fetch_schema(xml_file)
     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))
Esempio n. 5
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)