Ejemplo n.º 1
0
class MetaDataWriteXMLTest(unittest.TestCase):
    """
    Tests for XMLWriter.
    """
    WRITABLE_METADATA = MetaDataReadXMLTest.EXPECTED_DICTIONARY

    def setUp(self):
        """
        Sets up necessary files for the tests.
        """
        meta_data_entity = GenericMetaData(self.WRITABLE_METADATA)
        self.meta_writer = XMLWriter(meta_data_entity)
        self.result_path = os.path.join(os.path.dirname(__file__),
                                        "Operation.xml")

    def tearDown(self):
        """
        Remove created XML file.
        """
        unittest.TestCase.tearDown(self)
        os.remove(self.result_path)

    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)
class MetaDataWriteXMLTest(unittest.TestCase):  
    """
    Tests for XMLWriter.
    """ 
    WRITABLE_METADATA = MetaDataReadXMLTest.EXPECTED_DICTIONARY
    
    def setUp(self):
        """
        Sets up necessary files for the tests.
        """
        meta_data_entity = GenericMetaData(self.WRITABLE_METADATA)
        self.meta_writer = XMLWriter(meta_data_entity)
        self.result_path = os.path.join(os.path.dirname(__file__), "Operation.xml")
      
    def tearDown(self):
        """
        Remove created XML file.
        """
        unittest.TestCase.tearDown(self)
        os.remove(self.result_path)
        
    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)
Ejemplo n.º 3
0
 def setup_method(self):
     """
     Sets up necessary files for the tests.
     """
     meta_data_entity = GenericMetaData(self.WRITABLE_METADATA)
     self.meta_writer = XMLWriter(meta_data_entity)
     self.result_path = os.path.join(os.path.dirname(__file__), "Operation.xml")
Ejemplo n.º 4
0
class TestMetaDataWriteXML():
    """
    Tests for XMLWriter.
    """ 
    WRITABLE_METADATA = TestMetaDataReadXML.EXPECTED_DICTIONARY
    
    def setup_method(self):
        """
        Sets up necessary files for the tests.
        """
        meta_data_entity = GenericMetaData(self.WRITABLE_METADATA)
        self.meta_writer = XMLWriter(meta_data_entity)
        self.result_path = os.path.join(os.path.dirname(__file__), "Operation.xml")
      
    def teardown_method(self):
        """
        Remove created XML file.
        """
        os.remove(self.result_path)
        
    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.items():
            found_value = meta_data[key]
            assert value == found_value
class TestMetaDataWriteXML():
    """
    Tests for XMLWriter.
    """ 
    WRITABLE_METADATA = TestMetaDataReadXML.EXPECTED_DICTIONARY
    
    def setup_method(self):
        """
        Sets up necessary files for the tests.
        """
        meta_data_entity = GenericMetaData(self.WRITABLE_METADATA)
        self.meta_writer = XMLWriter(meta_data_entity)
        self.result_path = os.path.join(os.path.dirname(__file__), "Operation.xml")
      
    def teardown_method(self):
        """
        Remove created XML file.
        """
        os.remove(self.result_path)
        
    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
Ejemplo n.º 6
0
 def write_image_metadata(self, figure):
     """
     Writes figure meta-data into XML file
     """
     _, dict_data = figure.to_dict()
     meta_entity = GenericMetaData(dict_data)
     XMLWriter(meta_entity).write(self._compute_image_metadata_file(figure))
Ejemplo n.º 7
0
    def update_operation_metadata(self,
                                  project_name,
                                  new_group_name,
                                  operation_id,
                                  is_group=False):
        """
        Update operation meta data.
        :param is_group: when FALSE, use parameter 'new_group_name' for direct assignment on operation.user_group
        when TRUE, update  operation.operation_group.name = parameter 'new_group_name'
        """
        op_path = self.get_operation_meta_file_path(project_name, operation_id)
        if not os.path.exists(op_path):
            self.logger.warning(
                "Trying to update an operation-meta file which does not exist."
                " It could happen in a group where partial entities have errors!"
            )
            return
        op_meta_data = XMLReader(op_path).read_metadata()

        if is_group:
            group_meta_str = op_meta_data[
                DataTypeMetaData.KEY_FK_OPERATION_GROUP]
            group_meta = json.loads(group_meta_str)
            group_meta[
                DataTypeMetaData.KEY_OPERATION_GROUP_NAME] = new_group_name
            op_meta_data[DataTypeMetaData.KEY_FK_OPERATION_GROUP] = json.dumps(
                group_meta)
        else:
            op_meta_data[DataTypeMetaData.KEY_OPERATION_TAG] = new_group_name
        XMLWriter(op_meta_data).write(op_path)
 def setUp(self):
     """
     Sets up necessary files for the tests.
     """
     meta_data_entity = GenericMetaData(self.WRITABLE_METADATA)
     self.meta_writer = XMLWriter(meta_data_entity)
     self.result_path = os.path.join(os.path.dirname(__file__), "Operation.xml")
Ejemplo n.º 9
0
 def write_operation_metadata(self, operation):
     """
     :param operation: DB stored operation instance.
     """
     project_name = operation.project.name
     op_path = self.get_operation_meta_file_path(project_name, operation.id)
     _, equivalent_dict = operation.to_dict()
     meta_entity = GenericMetaData(equivalent_dict)
     XMLWriter(meta_entity).write(op_path)
     os.chmod(op_path, TvbProfile.current.ACCESS_MODE_TVB_FILES)
Ejemplo n.º 10
0
def _rewrite_img_meta(pth, op_id):
    figure_dict = XMLReader(pth).read_metadata()
    figure_dict['file_path'] = op_id + '-' + figure_dict['file_path']
    XMLWriter(figure_dict).write(pth)
Ejemplo n.º 11
0
 def write_project_metadata_from_dict(self, project_path, meta_dictionary):
     project_cfg_file = os.path.join(project_path, self.TVB_PROJECT_FILE)
     meta_entity = GenericMetaData(meta_dictionary)
     XMLWriter(meta_entity).write(project_cfg_file)
     os.chmod(project_path, TvbProfile.current.ACCESS_MODE_TVB_FILES)