Exemplo n.º 1
0
    def test_run_search_errata(self, mock_search):
        """
        Test that when the --erratum-id argument isn't used, the default
        render_document_list output function is called
        """
        # Setup
        mock_out = mock.MagicMock()
        units = [{'a': 'a', 'metadata': 'm'}]
        mock_search.return_value = Response(200, units)

        user_input = {
            'repo-id': 'repo-1',
            'erratum-id': None,
            DisplayUnitAssociationsCommand.ASSOCIATION_FLAG.keyword: False,
        }

        # Test
        self.context.prompt.render_document_list = mock_out
        command = contents.SearchErrataCommand(self.context)
        command.errata(**user_input)

        # Verify
        expected = {
            'type_ids': [contents.TYPE_ERRATUM],
            'erratum-id': None,
            DisplayUnitAssociationsCommand.ASSOCIATION_FLAG.keyword: False,
        }
        mock_search.assert_called_once_with('repo-1', **expected)
        # Because there's only one type_id and contents.FIELDS_BY_TYPE[FIELDS_ERRATA] is
        # defined, the output function should be called with the metadata and FIELDS_ERRATA
        mock_out.assert_called_once_with(['m'], contents.FIELDS_ERRATA)
Exemplo n.º 2
0
    def test_run_search_errata_details(self, mock_search):
        """
        Test that when the --erratum-id argument is used, the custom output
        function write_erratum_detail is called instead of render_document_list
        """
        # Setup
        mock_out = mock.MagicMock()
        units = [{'a': 'a', 'metadata': 'm'}]
        mock_search.return_value = Response(200, units)

        user_input = {
            'repo-id': 'repo-1',
            'erratum-id': 'RHEA-0000:0000',
            DisplayUnitAssociationsCommand.ASSOCIATION_FLAG.keyword: False
        }

        # Test
        command = contents.SearchErrataCommand(self.context)
        command.write_erratum_detail = mock_out
        command.errata(**user_input)

        # Verify
        expected = {
            'type_ids': [contents.TYPE_ERRATUM],
            'filters': {'id': 'RHEA-0000:0000'},
        }
        mock_search.assert_called_once_with('repo-1', **expected)
        # Because there's only one type_id and contents.FIELDS_BY_TYPE[FIELDS_ERRATA] is
        # defined, the write_erratum_detail should be called with the metadata and FIELDS_ERRATA
        mock_out.assert_called_once_with(['m'], contents.FIELDS_ERRATA)
Exemplo n.º 3
0
def initialize(context):
    structure.ensure_repo_structure(context.cli)
    upload_manager = _upload_manager(context)

    repo_section = structure.repo_section(context.cli)
    repo_section.add_command(repo_create_update.RpmRepoCreateCommand(context))
    repo_section.add_command(repo_create_update.RpmRepoUpdateCommand(context))
    repo_section.add_command(cudl.DeleteRepositoryCommand(context))
    repo_section.add_command(repo_list.RpmRepoListCommand(context))
    repo_section.add_command(
        RepoSearchCommand(context, constants.REPO_NOTE_RPM))

    copy_section = structure.repo_copy_section(context.cli)
    copy_section.add_command(copy_commands.RpmCopyCommand(context))
    copy_section.add_command(copy_commands.ErrataCopyCommand(context))
    copy_section.add_command(copy_commands.DistributionCopyCommand(context))
    copy_section.add_command(copy_commands.PackageGroupCopyCommand(context))
    copy_section.add_command(copy_commands.PackageCategoryCopyCommand(context))
    copy_section.add_command(
        copy_commands.PackageEnvironmentCopyCommand(context))
    copy_section.add_command(copy_commands.AllCopyCommand(context))
    copy_section.add_command(copy_commands.SrpmCopyCommand(context))
    copy_section.add_command(copy_commands.YumRepoMetadataFileCommand(context))
    copy_section.add_command(copy_commands.DrpmCopyCommand(context))

    # Disabled as per 950690. We'll likely be able to add these back once the new
    # yum importer is finished and DRPMs are properly handled.
    # copy_section.add_command(copy_commands.DrpmCopyCommand(context))

    remove_section = structure.repo_remove_section(context.cli)
    remove_section.add_command(remove.RpmRemoveCommand(context))
    remove_section.add_command(remove.SrpmRemoveCommand(context))
    remove_section.add_command(remove.DrpmRemoveCommand(context))
    remove_section.add_command(remove.ErrataRemoveCommand(context))
    remove_section.add_command(remove.PackageGroupRemoveCommand(context))
    remove_section.add_command(remove.PackageCategoryRemoveCommand(context))
    remove_section.add_command(remove.PackageEnvironmentRemoveCommand(context))
    remove_section.add_command(remove.DistributionRemoveCommand(context))
    remove_section.add_command(remove.YumMetadataFileRemoveCommand(context))

    contents_section = structure.repo_contents_section(context.cli)
    contents_section.add_command(contents.SearchRpmsCommand(context))
    contents_section.add_command(contents.SearchDrpmsCommand(context))
    contents_section.add_command(contents.SearchSrpmsCommand(context))
    contents_section.add_command(contents.SearchPackageGroupsCommand(context))
    contents_section.add_command(
        contents.SearchPackageCategoriesCommand(context))
    contents_section.add_command(
        contents.SearchPackageEnvironmentsCommand(context))
    contents_section.add_command(contents.SearchDistributionsCommand(context))
    contents_section.add_command(contents.SearchErrataCommand(context))
    contents_section.add_command(
        contents.SearchYumMetadataFileCommand(context))

    # Add the group section, all its subsections, and commands
    group_export_section = structure.repo_group_export_section(context.cli)
    renderer = PublishStepStatusRenderer(context)
    group_export_section.add_command(
        export.RpmGroupExportCommand(context, renderer))
    group_export_section.add_command(
        export.GroupExportStatusCommand(context, renderer))

    uploads_section = structure.repo_uploads_section(context.cli)
    uploads_section.add_command(
        package.CreateRpmCommand(context, upload_manager))
    uploads_section.add_command(
        package.CreateSrpmCommand(context, upload_manager))
    uploads_section.add_command(
        errata.CreateErratumCommand(context, upload_manager))
    uploads_section.add_command(
        package_group.CreatePackageGroupCommand(context, upload_manager))
    uploads_section.add_command(
        category.CreatePackageCategoryCommand(context, upload_manager))
    uploads_section.add_command(
        comps.CreateCompsCommand(context, upload_manager))
    uploads_section.add_command(
        environment.CreatePackageEnvironmentCommand(context, upload_manager))
    uploads_section.add_command(upload.ResumeCommand(context, upload_manager))
    uploads_section.add_command(upload.CancelCommand(context, upload_manager))
    uploads_section.add_command(upload.ListCommand(context, upload_manager))

    sync_section = structure.repo_sync_section(context.cli)
    renderer = status.RpmStatusRenderer(context)
    sync_section.add_command(
        sync_publish.RunSyncRepositoryCommand(context, renderer))
    sync_section.add_command(sync_publish.SyncStatusCommand(context, renderer))

    publish_section = structure.repo_publish_section(context.cli)
    renderer = PublishStepStatusRenderer(context)
    distributor_id = ids.TYPE_ID_DISTRIBUTOR_YUM
    publish_section.add_command(
        sync_publish.RunPublishRepositoryCommand(context, renderer,
                                                 distributor_id))
    publish_section.add_command(
        sync_publish.PublishStatusCommand(context, renderer))

    repo_export_section = structure.repo_export_section(context.cli)
    renderer = PublishStepStatusRenderer(context)
    repo_export_section.add_command(export.RpmExportCommand(context, renderer))
    repo_export_section.add_command(
        sync_publish.PublishStatusCommand(context,
                                          renderer,
                                          description=DESC_EXPORT_STATUS))

    sync_schedules_section = structure.repo_sync_schedules_section(context.cli)
    sync_schedules_section.add_command(
        sync_schedules.RpmCreateScheduleCommand(context))
    sync_schedules_section.add_command(
        sync_schedules.RpmUpdateScheduleCommand(context))
    sync_schedules_section.add_command(
        sync_schedules.RpmDeleteScheduleCommand(context))
    sync_schedules_section.add_command(
        sync_schedules.RpmListScheduleCommand(context))

    sync_schedules_section.add_command(
        sync_schedules.RpmNextRunCommand(context))
Exemplo n.º 4
0
    def test_write_erratum_detail(self):
        errata_list = [
            {
                'issued': '2012-01-27 16:08:08',
                'references': [
                    {
                        'href': 'www.example.com',
                        'type': 'enhancement',
                        'id': 'example_reference',
                        'title': 'Example Reference'
                    }
                ],
                '_content_type_id': 'erratum',
                'id': 'RHEA-2012:0003',
                'from': '*****@*****.**',
                'severity': '',
                'title': 'Bird_Erratum',
                '_ns': 'units_erratum',
                'version': '1',
                'reboot_suggested': False,
                'type': 'security',
                'pkglist': [
                    {
                        'packages': [
                            {
                                'src': 'http://www.fedoraproject.org',
                                'name': 'crow',
                                'sum': None,
                                'filename': 'crow-0.8-1.el9.noarch.rpm',
                                'epoch': 1,
                                'version': '0.8',
                                'release': '1.el9',
                                'arch': 'noarch'
                            }
                        ],
                        'name': '1',
                        'short': ''
                    },
                    {
                        'packages': [
                            {
                                'src': 'http://www.fedoraproject.org',
                                'name': 'crow',
                                'sum': None,
                                'filename': 'crow-0.9-1.el10.noarch.rpm',
                                'epoch': 1,
                                'version': '0.9',
                                'release': '1.el10',
                                'arch': 'noarch'
                            }
                        ],
                        'name': '1',
                        'short': ''
                    }
                ],
                'status': 'stable',
                'updated': '',
                'description': 'Bird_Erratum',
                '_last_updated': 1402514111,
                'pushcount': '',
                '_storage_path': None,
                'rights': '',
                'solution': '',
                'release': '1',
                '_id': '0058de26-29e6-4ba8-b230-7e1a3e261894'
            }
        ]
        self.context.prompt = mock.MagicMock(spec=PulpPrompt)
        command = contents.SearchErrataCommand(self.context)

        # Test that the formatter handles an errata list and calls write
        command.write_erratum_detail(errata_list)
        self.assertEqual(1, self.context.prompt.write.call_count)

        # subclass str so we can use our own equality test. This lets us just
        # check for the substring we are interested in.
        class AnyStringWith(str):
            def __eq__(self, other):
                return self in other

        # Test that both packages are printed (RHBZ #1171278)
        self.context.prompt.write.\
            assert_called_once_with(AnyStringWith("crow-1:0.8-1.el9.noarch"), skip_wrap=True)
        self.context.prompt.write.\
            assert_called_once_with(AnyStringWith("crow-1:0.9-1.el10.noarch"), skip_wrap=True)
        # Test correct rendering if metadata missing https://pulp.plan.io/issues/1881
        self.context.prompt.write.\
            assert_called_once_with(AnyStringWith("Summary:           None"), skip_wrap=True)
Exemplo n.º 5
0
 def test_structure(self):
     command = contents.SearchErrataCommand(self.context)
     self.assertTrue(isinstance(command, contents.BaseSearchCommand))
     self.assertEqual(command.context, self.context)
     self.assertEqual(command.name, 'errata')
     self.assertEqual(command.description, contents.DESC_ERRATA)