Beispiel #1
0
def test_changelog_release_plugin_cache(  # pylint: disable=redefined-outer-name
        collection_changelog):  # noqa: F811
    collection_changelog.set_galaxy({
        'version': '1.0.0',
    })
    collection_changelog.config.title = 'My Amazing Collection'
    collection_changelog.set_config(collection_changelog.config)
    collection_changelog.add_fragment_line(
        '1.0.0.yml', 'release_summary', 'This is the first proper release.')
    collection_changelog.add_plugin(
        'module', 'test_module.py',
        create_plugin(
            DOCUMENTATION={
                'name': 'test_module',
                'short_description': 'A test module',
                'version_added': '1.0.0',
                'description': ['This is a test module.'],
                'author': ['Someone'],
                'options': {},
            },
            EXAMPLES='',
            RETURN={},
        ))
    collection_changelog.add_plugin(
        'module',
        '__init__.py',
        create_plugin(
            DOCUMENTATION={
                'name': 'bad_module',
                'short_description': 'Bad module',
                'description':
                ['This should be ignored, not found as a module!.'],
                'author': ['badguy'],
                'options': {},
            },
            EXAMPLES='# Some examples\n',
            RETURN={},
        ),
        subdirs=['cloud'])
    collection_changelog.add_plugin('module',
                                    'old_module.py',
                                    create_plugin(
                                        DOCUMENTATION={
                                            'name':
                                            'old_module',
                                            'short_description':
                                            'An old module',
                                            'description':
                                            ['This is an old module.'],
                                            'author': ['Elder'],
                                            'options': {},
                                        },
                                        EXAMPLES='# Some examples\n',
                                        RETURN={},
                                    ),
                                    subdirs=['cloud', 'sky'])
    collection_changelog.add_plugin('module',
                                    'bad_module2',
                                    create_plugin(
                                        DOCUMENTATION={
                                            'name':
                                            'bad_module2',
                                            'short_description':
                                            'An bad module',
                                            'description':
                                            ['Shold not be found either.'],
                                            'author': ['Elder'],
                                            'options': {},
                                        },
                                        EXAMPLES='# Some examples\n',
                                        RETURN={},
                                    ),
                                    subdirs=['cloud', 'sky'])
    collection_changelog.add_plugin(
        'callback', 'test_callback.py',
        create_plugin(
            DOCUMENTATION={
                'name': 'test_callback',
                'short_description': 'A not so old callback',
                'version_added': '0.5.0',
                'description':
                ['This is a relatively new callback added before.'],
                'author': ['Someone else'],
                'options': {},
            },
            EXAMPLES='# Some examples\n',
            RETURN={},
        ))
    collection_changelog.add_plugin(
        'callback',
        'test_callback2.py',
        create_plugin(
            DOCUMENTATION={
                'name': 'test_callback2',
                'short_description': 'This one should not be found.',
                'version_added': '2.9',
                'description':
                ['This is a relatively new callback added before.'],
                'author': ['Someone else'],
                'options': {},
            },
            EXAMPLES='# Some examples\n',
            RETURN={},
        ),
        subdirs=['dont', 'find', 'me'])

    assert collection_changelog.run_tool('release',
                                         ['-v', '--date', '2020-01-02']) == 0

    diff = collection_changelog.diff()
    assert diff.added_dirs == []
    assert diff.added_files == [
        'changelogs/.plugin-cache.yaml',
        'changelogs/CHANGELOG.rst',
        'changelogs/changelog.yaml',
    ]
    assert diff.removed_dirs == []
    assert diff.removed_files == ['changelogs/fragments/1.0.0.yml']
    assert diff.changed_files == []

    plugin_cache = diff.parse_yaml('changelogs/.plugin-cache.yaml')
    assert plugin_cache['version'] == '1.0.0'

    # Plugin cache: modules
    assert sorted(
        plugin_cache['plugins']['module']) == ['old_module', 'test_module']
    assert plugin_cache['plugins']['module']['old_module'][
        'name'] == 'old_module'
    assert plugin_cache['plugins']['module']['old_module'][
        'namespace'] == 'cloud.sky'
    assert plugin_cache['plugins']['module']['old_module'][
        'description'] == 'An old module'
    assert plugin_cache['plugins']['module']['old_module'][
        'version_added'] is None
    assert plugin_cache['plugins']['module']['test_module'][
        'name'] == 'test_module'
    assert plugin_cache['plugins']['module']['test_module']['namespace'] == ''
    assert plugin_cache['plugins']['module']['test_module'][
        'description'] == 'A test module'
    assert plugin_cache['plugins']['module']['test_module'][
        'version_added'] == '1.0.0'

    # Plugin cache: callbacks
    assert sorted(plugin_cache['plugins']['callback']) == ['test_callback']
    assert plugin_cache['plugins']['callback']['test_callback'][
        'name'] == 'test_callback'
    assert plugin_cache['plugins']['callback']['test_callback']['description'] == \
        'A not so old callback'
    assert plugin_cache['plugins']['callback']['test_callback'][
        'version_added'] == '0.5.0'
    assert 'namespace' not in plugin_cache['plugins']['callback'][
        'test_callback']

    # Changelog
    changelog = diff.parse_yaml('changelogs/changelog.yaml')
    assert changelog['ancestor'] is None
    assert sorted(changelog['releases']) == ['1.0.0']
    assert changelog['releases']['1.0.0']['release_date'] == '2020-01-02'
    assert changelog['releases']['1.0.0']['changes'] == {
        'release_summary': 'This is the first proper release.'
    }
    assert changelog['releases']['1.0.0']['fragments'] == ['1.0.0.yml']
    assert len(changelog['releases']['1.0.0']['modules']) == 1
    assert changelog['releases']['1.0.0']['modules'][0][
        'name'] == 'test_module'
    assert changelog['releases']['1.0.0']['modules'][0]['namespace'] == ''
    assert changelog['releases']['1.0.0']['modules'][0][
        'description'] == 'A test module'
    assert 'version_added' not in changelog['releases']['1.0.0']['modules'][0]

    assert diff.file_contents['changelogs/CHANGELOG.rst'].decode('utf-8') == (
        r'''===================================
My Amazing Collection Release Notes
===================================

.. contents:: Topics


v1.0.0
======

Release Summary
---------------

This is the first proper release.

New Modules
-----------

- test_module - A test module
''')
Beispiel #2
0
def test_changelog_release_ansible_plugin_cache(  # pylint: disable=redefined-outer-name
        ansible_changelog):  # noqa: F811
    ansible_config_contents = r'''
---
release_tag_re: '(v(?:[\d.ab\-]|rc)+)'
pre_release_tag_re: '(?P<pre_release>(?:[ab]|rc)+\d*)$'
notesdir: fragments
prelude_section_name: release_summary
new_plugins_after_name: removed_features
sections:
- ['major_changes', 'Major Changes']
- ['minor_changes', 'Minor Changes']
- ['deprecated_features', 'Deprecated Features']
- ['removed_features', 'Removed Features (previously deprecated)']
- ['bugfixes', 'Bugfixes']
- ['known_issues', 'Known Issues']
'''
    ansible_changelog.set_config_raw(ansible_config_contents.encode('utf-8'))
    ansible_changelog.set_plugin_cache(
        '2.8', {
            'lookup': {
                'baz': {
                    'name': 'baz',
                    'description': 'Has already been here',
                    'namespace': None,
                    'version_added': None,
                },
                'boom': {
                    'name': 'boom',
                    'description': 'Something older',
                    'namespace': None,
                    'version_added': '2.8',
                },
            },
        })
    ansible_changelog.add_fragment_line('2.9.yml', 'release_summary',
                                        'This is the first proper release.')
    ansible_changelog.add_plugin(
        'module', 'test_module.py',
        create_plugin(
            DOCUMENTATION={
                'name': 'test_module',
                'short_description': 'A test module',
                'version_added': '2.9',
                'description': ['This is a test module.'],
                'author': ['Someone'],
                'options': {},
            },
            EXAMPLES='',
            RETURN={},
        ))
    ansible_changelog.add_plugin(
        'module',
        '__init__.py',
        create_plugin(
            DOCUMENTATION={
                'name': 'bad_module',
                'short_description': 'Bad module',
                'description':
                ['This should be ignored, not found as a module!.'],
                'author': ['badguy'],
                'options': {},
            },
            EXAMPLES='# Some examples\n',
            RETURN={},
        ),
        subdirs=['cloud'])
    ansible_changelog.add_plugin('module',
                                 'old_module.py',
                                 create_plugin(
                                     DOCUMENTATION={
                                         'name': 'old_module',
                                         'short_description': 'An old module',
                                         'description':
                                         ['This is an old module.'],
                                         'author': ['Elder'],
                                         'options': {},
                                     },
                                     EXAMPLES='# Some examples\n',
                                     RETURN={},
                                 ),
                                 subdirs=['cloud', 'sky'])
    ansible_changelog.add_plugin('module',
                                 'bad_module2',
                                 create_plugin(
                                     DOCUMENTATION={
                                         'name':
                                         'bad_module2',
                                         'short_description':
                                         'An bad module',
                                         'description':
                                         ['Shold not be found either.'],
                                         'author': ['Elder'],
                                         'options': {},
                                     },
                                     EXAMPLES='# Some examples\n',
                                     RETURN={},
                                 ),
                                 subdirs=['cloud', 'sky'])
    ansible_changelog.add_plugin(
        'callback', 'test_callback.py',
        create_plugin(
            DOCUMENTATION={
                'name': 'test_callback',
                'short_description': 'A not so old callback',
                'version_added': '2.8',
                'description':
                ['This is a relatively new callback added before.'],
                'author': ['Someone else'],
                'options': {},
            },
            EXAMPLES='# Some examples\n',
            RETURN={},
        ))
    ansible_changelog.add_plugin(
        'callback',
        'test_callback2.py',
        create_plugin(
            DOCUMENTATION={
                'name': 'test_callback2',
                'short_description': 'This one should not be found.',
                'version_added': '2.9',
                'description':
                ['This is a relatively new callback added before.'],
                'author': ['Someone else'],
                'options': {},
            },
            EXAMPLES='# Some examples\n',
            RETURN={},
        ),
        subdirs=['dont', 'find', 'me'])

    assert ansible_changelog.run_tool('release', [
        '-v', '--date', '2020-01-02', '--version', '2.9', '--codename', 'meow'
    ]) == 0

    diff = ansible_changelog.diff()
    assert diff.added_dirs == []
    assert diff.added_files == [
        'changelogs/.changes.yaml',
        'changelogs/CHANGELOG-v2.9.rst',
    ]
    assert diff.removed_dirs == []
    assert diff.removed_files == []
    assert diff.changed_files == [
        'changelogs/.plugin-cache.yaml',
    ]

    plugin_cache = diff.parse_yaml('changelogs/.plugin-cache.yaml')
    assert plugin_cache['version'] == '2.9'

    # Plugin cache: modules
    assert sorted(
        plugin_cache['plugins']['module']) == ['old_module', 'test_module']
    assert plugin_cache['plugins']['module']['old_module'][
        'name'] == 'old_module'
    assert plugin_cache['plugins']['module']['old_module'][
        'namespace'] == 'cloud.sky'
    assert plugin_cache['plugins']['module']['old_module'][
        'description'] == 'An old module'
    assert plugin_cache['plugins']['module']['old_module'][
        'version_added'] is None
    assert plugin_cache['plugins']['module']['test_module'][
        'name'] == 'test_module'
    assert plugin_cache['plugins']['module']['test_module']['namespace'] == ''
    assert plugin_cache['plugins']['module']['test_module'][
        'description'] == 'A test module'
    assert plugin_cache['plugins']['module']['test_module'][
        'version_added'] == '2.9'

    # Plugin cache: callbacks
    assert sorted(plugin_cache['plugins']['callback']) == ['test_callback']
    assert plugin_cache['plugins']['callback']['test_callback'][
        'name'] == 'test_callback'
    assert plugin_cache['plugins']['callback']['test_callback']['description'] == \
        'A not so old callback'
    assert plugin_cache['plugins']['callback']['test_callback'][
        'version_added'] == '2.8'
    assert 'namespace' not in plugin_cache['plugins']['callback'][
        'test_callback']

    # Changelog
    changelog = diff.parse_yaml('changelogs/.changes.yaml')
    assert changelog['ancestor'] is None
    assert sorted(changelog['releases']) == ['2.9']
    assert changelog['releases']['2.9']['release_date'] == '2020-01-02'
    assert changelog['releases']['2.9']['fragments'] == ['2.9.yml']
    assert changelog['releases']['2.9']['modules'] == ['test_module']

    assert diff.file_contents['changelogs/CHANGELOG-v2.9.rst'].decode(
        'utf-8') == (r'''================================
Ansible 2.9 "meow" Release Notes
================================

.. contents:: Topics


v2.9
====

Release Summary
---------------

This is the first proper release.

New Modules
-----------

- test_module - A test module
''')
Beispiel #3
0
def test_changelog_release_plugin_cache(collection_changelog):
    collection_changelog.set_galaxy({
        'version': '1.0.0',
    })
    collection_changelog.set_config(collection_changelog.config)
    collection_changelog.add_fragment_line(
        '1.0.0.yml', 'release_summary', 'This is the first proper release.')
    collection_changelog.add_plugin(
        'module', 'test_module.py',
        create_plugin(
            DOCUMENTATION={
                'name': 'test_module',
                'short_description': 'A test module',
                'version_added': '1.0.0',
                'description': ['This is a test module.'],
                'author': ['Someone'],
                'options': {},
            },
            EXAMPLES='',
            RETURN={},
        ))
    collection_changelog.add_plugin('module',
                                    'old_module.py',
                                    create_plugin(
                                        DOCUMENTATION={
                                            'name':
                                            'old_module',
                                            'short_description':
                                            'An old module',
                                            'description':
                                            ['This is an old module.'],
                                            'author': ['Elder'],
                                            'options': {},
                                        },
                                        EXAMPLES='# Some examples\n',
                                        RETURN={},
                                    ),
                                    subdirs=['cloud', 'sky'])

    assert collection_changelog.run_tool('release',
                                         ['-v', '--date', '2020-01-02']) == 0

    diff = collection_changelog.diff()
    assert diff.added_dirs == []
    assert diff.added_files == [
        'changelogs/.plugin-cache.yaml', 'changelogs/CHANGELOG.rst',
        'changelogs/changelog.yaml'
    ]
    assert diff.removed_dirs == []
    assert diff.removed_files == ['changelogs/fragments/1.0.0.yml']
    assert diff.changed_files == []

    plugin_cache = diff.parse_yaml('changelogs/.plugin-cache.yaml')
    assert plugin_cache['version'] == '1.0.0'

    # Plugin cache: modules
    assert sorted(
        plugin_cache['plugins']['module']) == ['old_module', 'test_module']
    assert plugin_cache['plugins']['module']['old_module'][
        'name'] == 'old_module'
    assert plugin_cache['plugins']['module']['old_module'][
        'namespace'] == 'cloud.sky'
    assert plugin_cache['plugins']['module']['old_module'][
        'description'] == 'An old module'
    assert plugin_cache['plugins']['module']['old_module'][
        'version_added'] is None
    assert plugin_cache['plugins']['module']['test_module'][
        'name'] == 'test_module'
    assert plugin_cache['plugins']['module']['test_module']['namespace'] == ''
    assert plugin_cache['plugins']['module']['test_module'][
        'description'] == 'A test module'
    assert plugin_cache['plugins']['module']['test_module'][
        'version_added'] == '1.0.0'

    # Changelog
    changelog = diff.parse_yaml('changelogs/changelog.yaml')
    assert changelog['ancestor'] is None
    assert sorted(changelog['releases']) == ['1.0.0']
    assert changelog['releases']['1.0.0']['release_date'] == '2020-01-02'
    assert changelog['releases']['1.0.0']['changes'] == {
        'release_summary': 'This is the first proper release.'
    }
    assert changelog['releases']['1.0.0']['fragments'] == ['1.0.0.yml']
    assert len(changelog['releases']['1.0.0']['modules']) == 1
    assert changelog['releases']['1.0.0']['modules'][0][
        'name'] == 'test_module'
    assert changelog['releases']['1.0.0']['modules'][0]['namespace'] == ''
    assert changelog['releases']['1.0.0']['modules'][0][
        'description'] == 'A test module'
    assert 'version_added' not in changelog['releases']['1.0.0']['modules'][0]