예제 #1
0
 def collection(cls, collection_name: str, version: str,
                changelog_data: t.Optional[t.Any] = None) -> 'ChangelogData':
     paths = PathsConfig.force_collection('')
     collection_details = CollectionDetails(paths)
     collection_details.namespace, collection_details.name = collection_name.split('.', 1)
     collection_details.version = version
     collection_details.flatmap = False  # TODO!
     config = ChangelogConfig.default(paths, collection_details)
     return cls(paths,
                config,
                ChangesData(config, '', changelog_data),
                flatmap=True)  # TODO!
예제 #2
0
def test_collection_details(tmp_path):
    paths = PathsConfig.force_ansible(str(tmp_path))
    details = CollectionDetails(paths)
    with pytest.raises(Exception) as exc:
        details.get_namespace()
    assert str(
        exc.value
    ) == 'Internal error: cannot get collection details for non-collection'
    with pytest.raises(Exception) as exc:
        details.get_name()
    assert str(
        exc.value
    ) == 'Internal error: cannot get collection details for non-collection'
    with pytest.raises(Exception) as exc:
        details.get_version()
    assert str(
        exc.value
    ) == 'Internal error: cannot get collection details for non-collection'
    with pytest.raises(Exception) as exc:
        details.get_flatmap()
    assert str(
        exc.value
    ) == 'Internal error: cannot get collection details for non-collection'

    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    with pytest.raises(ChangelogError) as exc:
        details.get_namespace()
    assert 'Cannot find galaxy.yml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_name()
    assert 'Cannot find galaxy.yml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_version()
    assert 'Cannot find galaxy.yml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_flatmap()
    assert 'Cannot find galaxy.yml' in str(exc.value)

    galaxy_path = tmp_path / 'galaxy.yml'
    galaxy_path.write_text('---\na: b\n')
    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    with pytest.raises(ChangelogError) as exc:
        details.get_namespace()
    assert 'Cannot find "namespace" field in galaxy.yaml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_name()
    assert 'Cannot find "name" field in galaxy.yaml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_version()
    assert 'Cannot find "version" field in galaxy.yaml' in str(exc.value)
    assert details.get_flatmap() is None

    galaxy_path = tmp_path / 'galaxy.yml'
    galaxy_path.write_text('---\nnamespace: 1\nname: 2\nversion: 3\ntype: 4')
    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    with pytest.raises(ChangelogError) as exc:
        details.get_namespace()
    assert 'Cannot find "namespace" field in galaxy.yaml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_name()
    assert 'Cannot find "name" field in galaxy.yaml' in str(exc.value)
    with pytest.raises(ChangelogError) as exc:
        details.get_version()
    assert 'Cannot find "version" field in galaxy.yaml' in str(exc.value)
    assert details.get_flatmap() is False

    galaxy_path = tmp_path / 'galaxy.yml'
    galaxy_path.write_text(
        '---\nnamespace: a\nname: b\nversion: c\ntype: flatmap')
    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    assert details.get_namespace() == 'a'
    assert details.get_name() == 'b'
    assert details.get_version() == 'c'
    assert details.get_flatmap() is True

    galaxy_path = tmp_path / 'galaxy.yml'
    galaxy_path.write_text('---\ntype: other')
    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    assert details.get_flatmap() is False

    galaxy_path = tmp_path / 'galaxy.yml'
    galaxy_path.write_text(
        '---\nnamespace: a\nname: b\nversion: c\ntype: flatmap')
    paths = PathsConfig.force_collection(str(tmp_path))
    details = CollectionDetails(paths)
    details.namespace = 'test'
    details.name = 'asdf'
    details.version = '1.0.0'
    details.flatmap = False
    assert details.get_namespace() == 'test'
    assert details.get_name() == 'asdf'
    assert details.get_version() == '1.0.0'
    assert details.get_flatmap() is False