def test_get_repositories(self):
        """
        Test the get_repositories() method.
        """
        self.context.server.repo = repo_mock()
        list_command = repo_list.ISORepoListCommand(self.context)
        query_params = {}

        iso_repos = list_command.get_repositories(query_params)

        # Let's inspect the repos to make sure they have all the correct properties
        # There should be two ISO repos (cdn and iso). zoo was an RPM repo
        self.assertEqual(len(iso_repos), 2)

        # The first repo should be test_iso_repo, unaltered
        self.assertEqual(iso_repos[0], TEST_REPOS[0])

        # The second repo should be cdn, but the SSL certificates should have been removed
        expected_cdn = deepcopy(TEST_REPOS[1])
        expected_cdn['importers'][0]['config']['feed_ssl_configured'] = 'True'
        expected_cdn['importers'][0]['config'].pop(
            importer_constants.KEY_SSL_CLIENT_CERT)
        expected_cdn['importers'][0]['config'].pop(
            importer_constants.KEY_SSL_CLIENT_KEY)
        expected_cdn['importers'][0]['config'].pop(
            importer_constants.KEY_SSL_CA_CERT)
        expected_cdn['distributors'][0]['config'].pop(
            constants.CONFIG_SSL_AUTH_CA_CERT)
        expected_cdn['distributors'][0]['config']['repo_protected'] = 'True'
        self.assertEqual(iso_repos[1], expected_cdn)
    def test___init__(self, list_repo_init):
        """
        Test the __init__() method.
        """
        list_command = repo_list.ISORepoListCommand(self.context)

        list_repo_init.assert_called_once_with(
            list_command, self.context, repos_title=_('ISO Repositories'))
        self.assertEqual(list_command.all_repos_cache, None)
    def test_get_other_repositories(self):
        """
        Test the get_other_repositories() method.
        """
        self.context.server.repo = repo_mock()
        list_command = repo_list.ISORepoListCommand(self.context)
        query_params = {}

        other_repos = list_command.get_other_repositories(query_params)

        # The only "other repo" is the third test one, the "zoo" RPM repo
        self.assertEqual(other_repos, [TEST_REPOS[2]])
    def test__all_repos(self):
        """
        Test the _all_repos() method.
        """
        self.context.server.repo = repo_mock()
        list_command = repo_list.ISORepoListCommand(self.context)
        query_params = {}

        all_repos = list_command._all_repos(query_params)

        # The mock should have been called, and all_repos should just be our TEST_REPOS
        self.context.server.repo.repositories.assert_call_once_with(
            query_params)
        self.assertEqual(all_repos, TEST_REPOS)

        # The cache should be filled now
        self.assertEqual(list_command.all_repos_cache, TEST_REPOS)

        # Calling it again should not increase the mock's call count since the cache should be used
        list_command._all_repos(query_params)
        self.assertEqual(self.context.server.repo.repositories.call_count, 1)
Example #5
0
def add_repo_section(context, parent_section):
    """
    Add the repo section and all of its children to the parent section.

    :param context: ClientContext containing the CLI instance being configured
    :type  context: pulp.client.extensions.core.ClientContext
    :param parent_section: The parent CLI section that we wish to add the repo subsection to.
    :type  parent_section: pulp.client.extensions.extensions.PulpCliSection
    """
    repo_section = parent_section.create_subsection(SECTION_REPO, DESC_REPO)

    add_publish_section(context, repo_section)
    add_sync_section(context, repo_section)
    add_uploads_section(context, repo_section)

    repo_section.add_command(create_update.ISORepoCreateCommand(context))
    repo_section.add_command(create_update.ISORepoUpdateCommand(context))
    repo_section.add_command(cudl.DeleteRepositoryCommand(context))
    repo_section.add_command(repo_list.ISORepoListCommand(context))
    repo_section.add_command(association.IsoCopyCommand(context))
    repo_section.add_command(association.IsoRemoveCommand(context))
    repo_section.add_command(contents.ISOSearchCommand(context, name='isos'))