Esempio n. 1
0
 def convert(self, file_name):
     temp_dir = './temp_Dir'
     file_operations = FileOperations()
     file_operations.unzip_csar(file_name, temp_dir)
     entry_file_name = file_operations.read_tosca_meta_file(temp_dir)
     node_list, node_keys = self.get_nodes(entry_file_name, temp_dir)
     yaml, content = file_operations.read_file(Path(temp_dir, entry_file_name))
     updated_content = self.operation_connectTo(content, node_keys, node_list)
     updated_content = self.operaton_encryption(updated_content,node_keys)
     file_operations.write_file(yaml, updated_content, (Path(temp_dir, entry_file_name)))
     modified = file_operations.zip_csar(file_name, temp_dir)
     return modified
class FileParser(unittest.TestCase):
    def setUp(self):
        self.data_pipeline_parser = ModifyConnectionType()
        self.file_operations = FileOperations()
        self.data_encryption = DataEncryption()
        self.verify_connection_type = ValidateConnectionType()
        self.temp_dir = './temp_Dir'

    def test_encryption_decryption_password_mismatch(
            self, file_name='DPP_Testing.csar'):
        self.file_operations.unzip_csar(file_name, self.temp_dir)
        entry_file_name = self.file_operations.read_tosca_meta_file(
            self.temp_dir)
        node_list, node_keys = self.data_pipeline_parser.get_nodes(
            entry_file_name, self.temp_dir)
        yaml, content = self.file_operations.read_file(
            Path(self.temp_dir, entry_file_name))
        encrypt_decrypt_nodes = self.data_encryption.get_encrypt_decrypt_nodes(
            content, node_keys)
        shutil.rmtree(self.temp_dir)
        self.assertTrue(len(encrypt_decrypt_nodes) > 0)

    def test_duplicate_connections(self, file_name='DPP_Testing.csar'):
        self.file_operations.unzip_csar(file_name, self.temp_dir)
        entry_file_name = self.file_operations.read_tosca_meta_file(
            self.temp_dir)
        node_list, node_keys = self.data_pipeline_parser.get_nodes(
            entry_file_name, self.temp_dir)
        yaml, content = self.file_operations.read_file(
            Path(self.temp_dir, entry_file_name))

        self.verify_connection_type.get_host_connection_nodes(
            content, node_list)
        self.verify_connection_type.get_nodelist_to_edit(node_list)
        updated_content, duplicate_node_relationships = self.verify_connection_type.delete_duplicate_connection_node(
            content)
        shutil.rmtree(self.temp_dir)
        self.assertTrue(len(duplicate_node_relationships) > 0)

    def test_wrong_connections(self, file_name='DPP_Testing.csar'):
        self.file_operations.unzip_csar(file_name, self.temp_dir)
        entry_file_name = self.file_operations.read_tosca_meta_file(
            self.temp_dir)
        node_list, node_keys = self.data_pipeline_parser.get_nodes(
            entry_file_name, self.temp_dir)
        yaml, content = self.file_operations.read_file(
            Path(self.temp_dir, entry_file_name))
        self.verify_connection_type.get_host_connection_nodes(
            content, node_list)
        self.verify_connection_type.get_nodelist_to_edit(node_list)
        updated_content, duplicate_node_relationships = self.verify_connection_type.delete_duplicate_connection_node(
            content)
        updated_content = self.verify_connection_type.make_changes_remote_nodes(
            updated_content)
        updated_content = self.verify_connection_type.make_changes_local_nodes(
            updated_content)
        shutil.rmtree(self.temp_dir)
        self.assertTrue(
            (len(self.verify_connection_type.remote_nodes_to_change) +
             len(self.verify_connection_type.local_nodes_to_change)) > 0)