def test_valid_meta_xml_matches_schema(self):
        self.cs.set_config_details(TEST_CONFIG)
        xml = ConfigurationXmlConverter.meta_to_xml(self.cs.get_config_meta())

        try:
            ConfigurationSchemaChecker.check_xml_data_matches_schema(os.path.join(self.schema_dir, "meta.xsd"), xml)
        except:
            self.fail()
    def test_meta_xml_does_not_match_schema_raises(self):
        self.cs.set_config_details(TEST_CONFIG)
        xml = ConfigurationXmlConverter.meta_to_xml(self.cs.get_config_meta())

        # Keep it valid XML but don't match schema
        xml = xml.replace("synoptic>", "snyoptic>")

        self.assertRaises(ConfigurationInvalidUnderSchema, ConfigurationSchemaChecker.check_xml_data_matches_schema,
                          os.path.join(self.schema_dir, "meta.xsd"), xml)
    def save_config(self, configuration, is_component):
        """Saves the current configuration with the specified name.

        Args:
            configuration (Configuration): The actual configuration to save
            is_component (bool): Is it a component?
        """
        if is_component:
            path = os.path.abspath(FILEPATH_MANAGER.get_component_path(configuration.get_name()))
        else:
            path = os.path.abspath(FILEPATH_MANAGER.get_config_path(configuration.get_name()))

        if not os.path.isdir(path):
            # Create the directory
            os.makedirs(path)

        blocks_xml = ConfigurationXmlConverter.blocks_to_xml(configuration.blocks, configuration.macros)
        groups_xml = ConfigurationXmlConverter.groups_to_xml(configuration.groups)
        iocs_xml = ConfigurationXmlConverter.iocs_to_xml(configuration.iocs)
        meta_xml = ConfigurationXmlConverter.meta_to_xml(configuration.meta)
        try:
            components_xml = ConfigurationXmlConverter.components_to_xml(configuration.components)
        except:
            # Is a component, so no components
            components_xml = ConfigurationXmlConverter.components_to_xml(dict())

        # Save blocks
        with open(path + "/" + FILENAME_BLOCKS, "w") as f:
            f.write(blocks_xml)

        # Save groups
        with open(path + "/" + FILENAME_GROUPS, "w") as f:
            f.write(groups_xml)

        # Save IOCs
        with open(path + "/" + FILENAME_IOCS, "w") as f:
            f.write(iocs_xml)

        # Save components
        with open(path + "/" + FILENAME_COMPONENTS, "w") as f:
            f.write(components_xml)

        # Save meta
        with open(path + "/" + FILENAME_META, "w") as f:
            f.write(meta_xml)