コード例 #1
0
    def __build_operation_from_file(self, project, operation_file):
        """
        Create Operation entity from metadata file.
        """
        reader = XMLReader(operation_file)
        operation_dict = reader.read_metadata()
        operation_entity = manager_of_class(model.Operation).new_instance()

        return operation_entity.from_dict(operation_dict, dao, self.user_id, project.gid)
コード例 #2
0
 def test_write_metadata(self):
     """
     Test that an XML file is created and correct data is written in it.
     """
     self.assertFalse(os.path.exists(self.result_path))
     self.meta_writer.write(self.result_path)
     self.assertTrue(os.path.exists(self.result_path))
     reader = XMLReader(self.result_path)
     meta_data = reader.read_metadata()
     for key, value in MetaDataReadXMLTest.EXPECTED_DICTIONARY.iteritems():
         found_value = meta_data[key]
         self.assertEqual(value, found_value)
コード例 #3
0
 def test_write_metadata(self):
     """
     Test that an XML file is created and correct data is written in it.
     """
     assert not os.path.exists(self.result_path)
     self.meta_writer.write(self.result_path)
     assert os.path.exists(self.result_path)
     reader = XMLReader(self.result_path)
     meta_data = reader.read_metadata()
     for key, value in TestMetaDataReadXML.EXPECTED_DICTIONARY.iteritems():
         found_value = meta_data[key]
         assert value == found_value
コード例 #4
0
 def setUp(self):
     """
     Sets up necessary files for the tests.
     """
     self.file_path = os.path.join(os.path.dirname(__file__), 
                                   self.TO_BE_READ_FILE)
     self.meta_reader = XMLReader(self.file_path)
コード例 #5
0
    def __populate_project(self, project_path):
        """
        Create and store a Project entity.
        """
        self.logger.debug("Creating project from path: %s" % project_path)
        project_cfg_file = os.path.join(project_path, FilesHelper.TVB_PROJECT_FILE)

        reader = XMLReader(project_cfg_file)
        project_dict = reader.read_metadata()
        project_entity = manager_of_class(model.Project).new_instance()
        project_entity = project_entity.from_dict(project_dict, self.user_id)

        try:
            self.logger.debug("Storing imported project")
            return dao.store_entity(project_entity)
        except IntegrityError, excep:
            self.logger.exception(excep)
            error_msg = ("Could not import project: %s with gid: %s. There is already a "
                         "project with the same name or gid.") % (project_entity.name, project_entity.gid)
            raise ProjectImportException(error_msg)
コード例 #6
0
class MetaDataReadXMLTest(unittest.TestCase):
    """
    Tests for tvb.core.entities.file.metadatahandler.XMLReader class.
    """   
    TO_BE_READ_FILE = "test_read.xml"
    #Values expected to be read from file
    EXPECTED_DICTIONARY = {'status': model.STATUS_FINISHED,
                           'gid': '497b3d59-b3c1-11e1-b2e4-68a86d1bd4fa',
                           'method_name': 'launch',
                           'user_group': 'cff_74',
                           'fk_from_algo': json.dumps({'classname': 'CFF_Importer', 'identifier': None,
                                                       'module': 'tvb.adapters.uploaders.cff_importer'})
                           }
        
    def setUp(self):
        """
        Sets up necessary files for the tests.
        """
        self.file_path = os.path.join(os.path.dirname(__file__), 
                                      self.TO_BE_READ_FILE)
        self.meta_reader = XMLReader(self.file_path)
    
    def test_read_metadata(self):
        """
        Test that content return by read_metadata matches the
        actual content of the XML.
        """
        meta_data = self.meta_reader.read_metadata()
        self.assertTrue(isinstance(meta_data, GenericMetaData))
        for key, value in self.EXPECTED_DICTIONARY.iteritems():
            found_value = meta_data[key]
            self.assertEqual(value, found_value)
        
    def test_read_gid(self):
        """
        Test that value returned by read_only_element matches the actual value from the XML file.
        """
        read_value = self.meta_reader.read_only_element('gid')
        self.assertTrue(isinstance(read_value, str))
        self.assertEqual(read_value, self.EXPECTED_DICTIONARY['gid'])