def test_wrong_tosca_version(self, get_workdir_path, csar_unpacked):
     blueprint_path = csar_unpacked / 'CSAR-wrong-tosca-version'
     with pytest.raises(TypeError):
         blueprint2CSAR.to_CSAR(blueprint_name='some_blueprint',
                                blueprint_dir=blueprint_path,
                                entry_definitions=Path('service.yaml'),
                                workdir=get_workdir_path)
 def test_meta_no_entry_definitions(self, get_workdir_path, csar_unpacked):
     blueprint_path = csar_unpacked / 'CSAR-no-entry-def'
     with pytest.raises(FileNotFoundError):
         blueprint2CSAR.to_CSAR(blueprint_name='some_blueprint',
                                blueprint_dir=blueprint_path,
                                entry_definitions=Path('service.yaml'),
                                workdir=get_workdir_path)
 def test_no_meta_multiple_yaml(self, get_workdir_path, csar_unpacked):
     blueprint_path = csar_unpacked / 'CSAR-no-meta-multiple-yaml'
     with pytest.raises(blueprint2CSAR.MultipleDefinitionsFoundException):
         blueprint2CSAR.to_CSAR(blueprint_name='some_blueprint',
                                blueprint_dir=blueprint_path,
                                no_meta=True,
                                workdir=get_workdir_path)
 def test_no_other_definition(self, get_workdir_path, csar_unpacked):
     blueprint_path = csar_unpacked / 'CSAR-no-other-def-2'
     with pytest.raises(FileNotFoundError):
         blueprint2CSAR.to_CSAR(blueprint_name='some_blueprint',
                                blueprint_dir=blueprint_path,
                                entry_definitions=Path('service.yaml'),
                                other_definitions=[Path('other_def.yaml')],
                                workdir=get_workdir_path)
 def test_other_definitions_success(self, get_workdir_path, csar_unpacked):
     blueprint_path = csar_unpacked / 'CSAR-multiple-other-def'
     workdir = get_workdir_path
     name = 'some_blueprint'
     output = workdir / f'CSAR-{name}'
     blueprint2CSAR.to_CSAR(blueprint_name=name,
                            blueprint_dir=blueprint_path,
                            entry_definitions=Path('service.yaml'),
                            other_definitions=[Path('service1.yaml'), Path('service2.yaml')],
                            workdir=workdir,
                            output=output)
    def test_no_meta_no_meta_success(self, get_workdir_path, csar_unpacked):
        blueprint_path = csar_unpacked / 'CSAR-no-meta'
        workdir = get_workdir_path
        name = 'some_blueprint'
        output = workdir / f'CSAR-{name}'

        blueprint2CSAR.to_CSAR(blueprint_name=name,
                               blueprint_dir=blueprint_path,
                               no_meta=True,
                               workdir=workdir,
                               output=output)
    def test_metafile_no_meta(self, get_workdir_path, csar_unpacked):
        blueprint_path = csar_unpacked / 'CSAR-no-meta-ok'
        workdir = get_workdir_path
        name = 'some_blueprint'
        output = workdir / f'CSAR-{name}'
        output_with_zip = Path(f'{output}.zip')

        blueprint2CSAR.to_CSAR(blueprint_name=name,
                               blueprint_dir=blueprint_path,
                               entry_definitions=Path('service.yaml'),
                               workdir=workdir,
                               output=output)

        assert output_with_zip.exists()
    def test_success(self, get_workdir_path: Path, csar_unpacked):
        workdir = get_workdir_path
        name = 'some_blueprint'
        output = workdir / f'CSAR-{name}'
        output_with_zip = Path(f'{output}.zip')
        unpacked = workdir / 'my_csar_unpacked'
        blueprint_path = csar_unpacked / 'CSAR-ok'
        blueprint2CSAR.to_CSAR(blueprint_name=name,
                               blueprint_dir=blueprint_path,
                               entry_definitions=Path('service.yaml'),
                               workdir=workdir,
                               output=output)
        assert output_with_zip.exists()

        shutil.unpack_archive(str(output_with_zip.absolute()), extract_dir=str(unpacked.absolute()))

        assert (unpacked / 'TOSCA-Metadata').is_dir()
        metadata_path = unpacked / 'TOSCA-Metadata' / 'TOSCA.meta'
        assert metadata_path.exists()
        metadata = yaml.load(metadata_path.open('r'), Loader=yaml.SafeLoader)
        assert isinstance(metadata, dict)
        assert all(key in metadata.keys() for key in ['TOSCA-Meta-File-Version', 'CSAR-Version',
                                                      'Created-By', 'Entry-Definitions',
                                                      'CSAR-name', 'CSAR-timestamp'])