Exemplo n.º 1
0
    def test_template_conversion_from_str(self):

        for arcgis_root in ARCGIS_ROOTS:
            for arcgis_node in ARCGIS_NODES:

                data = arcgis_node.join(("<", "></", ">"))
                data = arcgis_root.join(("<", ">{0}</", ">")).format(data)

                self.assert_parser_conversion(FgdcParser(), get_metadata_parser(data), "dict-based template")
                self.assert_parser_conversion(IsoParser(), get_metadata_parser(data), "dict-based template")

        self.assert_parser_conversion(
            ArcGISParser(), get_metadata_parser(FGDC_ROOT.join(("<", "></", ">"))), "str-based template"
        )
        self.assert_parser_conversion(
            IsoParser(), get_metadata_parser(FGDC_ROOT.join(("<", "></", ">"))), "str-based template"
        )

        for iso_root in ISO_ROOTS:
            self.assert_parser_conversion(
                ArcGISParser(), get_metadata_parser(iso_root.join(("<", "></", ">"))), "str-based template"
            )
            self.assert_parser_conversion(
                FgdcParser(), get_metadata_parser(iso_root.join(("<", "></", ">"))), "str-based template"
            )
Exemplo n.º 2
0
    def test_template_conversion_bad_roots(self):

        bad_root_format = "Bad root test failed for {0} with {1}"

        for bad_root in (None, u"", StringIO(u""), {}, '<?xml version="1.0" encoding="UTF-8"?>\n'):
            with self.assertRaises(NoContent, msg=bad_root_format.format("get_parsed_content", bad_root)):
                get_parsed_content(bad_root)
            with self.assertRaises(NoContent, msg=bad_root_format.format("get_parsed_content", bad_root)):
                get_metadata_parser(bad_root)

            if bad_root is not None:
                with self.assertRaises(NoContent, msg=bad_root_format.format("ArcGISParser", bad_root)):
                    ArcGISParser(bad_root)
                with self.assertRaises(NoContent, msg=bad_root_format.format("FgdcParser", bad_root)):
                    FgdcParser(bad_root)
                with self.assertRaises(NoContent, msg=bad_root_format.format("IsoParser", bad_root)):
                    IsoParser(bad_root)

        for bad_root in (u"NOT XML", u"<badRoot/>", u"<badRoot>invalid</badRoot>"):
            with self.assertRaises(InvalidContent, msg=bad_root_format.format("get_parsed_content", bad_root)):
                get_parsed_content(bad_root)
            with self.assertRaises(InvalidContent, msg=bad_root_format.format("get_parsed_content", bad_root)):
                get_metadata_parser(bad_root)
            with self.assertRaises(InvalidContent, msg=bad_root_format.format("ArcGISParser", bad_root)):
                ArcGISParser(bad_root)
            with self.assertRaises(InvalidContent, msg=bad_root_format.format("FgdcParser", bad_root)):
                FgdcParser(bad_root)
            with self.assertRaises(InvalidContent, msg=bad_root_format.format("IsoParser", bad_root)):
                IsoParser(bad_root)

        with self.assertRaises(InvalidContent, msg=bad_root_format.format("get_parsed_content", bad_root)):
            IsoParser(FGDC_ROOT.join(("<", "></", ">")))

        for iso_root in ISO_ROOTS:
            with self.assertRaises(InvalidContent, msg=bad_root_format.format("get_parsed_content", bad_root)):
                ArcGISParser(iso_root.join(("<", "></", ">")))
            with self.assertRaises(InvalidContent, msg=bad_root_format.format("get_parsed_content", bad_root)):
                FgdcParser(iso_root.join(("<", "></", ">")))

        for arcgis_root in ARCGIS_ROOTS:

            with self.assertRaises(InvalidContent, msg=bad_root_format.format("get_parsed_content", bad_root)):
                IsoParser(arcgis_root.join(("<", "></", ">")))

            if arcgis_root != FGDC_ROOT:
                with self.assertRaises(InvalidContent, msg=bad_root_format.format("get_parsed_content", bad_root)):
                    FgdcParser(arcgis_root.join(("<", "></", ">")))