Ejemplo n.º 1
0
def test_invalid_yaml_galaxy_file(galaxy_yml):
    expected = to_native(
        b"Failed to parse the galaxy.yml at '%s' with the following error:" %
        galaxy_yml)

    with pytest.raises(AnsibleError, match=expected):
        collection._get_galaxy_yml(galaxy_yml)
Ejemplo n.º 2
0
def test_warning_extra_keys(galaxy_yml, monkeypatch):
    display_mock = MagicMock()
    monkeypatch.setattr(Display, 'warning', display_mock)

    collection._get_galaxy_yml(galaxy_yml)

    assert display_mock.call_count == 1
    assert display_mock.call_args[0][0] == "Found unknown keys in collection galaxy.yml at '%s': invalid"\
        % to_text(galaxy_yml)
Ejemplo n.º 3
0
def test_defaults_galaxy_yml(galaxy_yml):
    actual = collection._get_galaxy_yml(galaxy_yml)

    assert sorted(list(actual.keys())) == [
        'authors',
        'dependencies',
        'description',
        'documentation',
        'homepage',
        'issues',
        'license_file',
        'license_ids',
        'name',
        'namespace',
        'readme',
        'repository',
        'tags',
        'version',
    ]

    assert actual['namespace'] == 'namespace'
    assert actual['name'] == 'collection'
    assert actual['authors'] == ['Jordan']
    assert actual['version'] == '0.1.0'
    assert actual['readme'] == 'README.md'
    assert actual['description'] is None
    assert actual['repository'] is None
    assert actual['documentation'] is None
    assert actual['homepage'] is None
    assert actual['issues'] is None
    assert actual['tags'] == []
    assert actual['dependencies'] == {}
    assert actual['license_ids'] == []
Ejemplo n.º 4
0
def test_galaxy_yml_list_value(galaxy_yml):
    actual = collection._get_galaxy_yml(galaxy_yml)
    assert actual['license_ids'] == ['MIT']
Ejemplo n.º 5
0
def test_missing_required_galaxy_key(galaxy_yml):
    expected = "The collection galaxy.yml at '%s' is missing the following mandatory keys: authors, name, " \
               "readme, version" % to_native(galaxy_yml)

    with pytest.raises(AnsibleError, match=expected):
        collection._get_galaxy_yml(galaxy_yml)
Ejemplo n.º 6
0
#!/usr/bin/env python
# Copyright (c) 2020 Matt Martz <*****@*****.**>
# GNU General Public License v3.0+
#     (see https://www.gnu.org/licenses/gpl-3.0.txt)

import json
import os

from ansible.galaxy.collection import _build_files_manifest
from ansible.galaxy.collection import _build_manifest
from ansible.galaxy.collection import _get_galaxy_yml
from ansible.module_utils._text import to_bytes

galaxy = _get_galaxy_yml('galaxy.yml')
b_here = to_bytes(os.path.abspath('.'))

with open('MANIFEST.json', 'w+') as f:
    json.dump(
        _build_manifest(**galaxy),
        f,
        indent=4,
        sort_keys=True,
    )

with open('FILES.json', 'w+') as f:
    json.dump(
        _build_files_manifest(
            b_here,
            galaxy['namespace'],
            galaxy['name'],
            galaxy['build_ignore'],