pulp_smash.tests.pulp3.utils

Location: Pulp SmashAPI Documentationpulp_smash.tests.pulp3.utils

Utility functions for Pulp 3 tests.

class pulp_smash.tests.pulp3.utils.JWTAuth(token, header_format='Bearer')

A class that enables JWT authentication with the Requests library.

For more information, see the Requests documentation on custom authentication.

pulp_smash.tests.pulp3.utils.delete_orphans(cfg=None)

Clean all content units present in pulp.

An orphaned artifact is an artifact that is not in any content units. An orphaned content unit is a content unit that is not in any repository version.

Parameters:cfg (pulp_smash.config.PulpSmashConfig) – Information about the Pulp host.
pulp_smash.tests.pulp3.utils.delete_repo_version(repo, version_href=None)

Delete a given repository version.

Parameters:
  • repo – A dict of information about the repository.
  • version_href – The repository version that should be deleted.
Returns:

A tuple. The tasks spawned by Pulp.

pulp_smash.tests.pulp3.utils.get_added_content(repo, version_href=None)

Read the added content of a given repository version.

Parameters:
  • repo – A dict of information about a repository.
  • version_href – The repository version to read. If none, read the latest repository version.
Returns:

A dict of information about the content added since the previous repository version.

pulp_smash.tests.pulp3.utils.get_artifact_paths(repo, version_href=None)

Return the paths of artifacts present in a given repository version.

Parameters:
  • repo – A dict of information about the repository.
  • version_href – The repository version to read.
Returns:

A set with the paths of units present in a given repository.

pulp_smash.tests.pulp3.utils.get_auth(cfg=None)

Return a random authentication object.

By default, pulp_smash.api.Client uses the same authentication method (HTTP BASIC) for every request. While this is a sane default, it doesn’t let tests exercise other authentication procedures. This function returns a random authentication object. To demonstrate how this object can be used, here’s an example showing how to create a user:

>>> from pulp_smash.api import Client
>>> from pulp_smash.config import get_config
>>> from pulp_smash.tests.pulp3.utils import get_auth
>>> from pulp_smash.tests.pulp3.constants import USER_PATH
>>> cfg = config.get_config()
>>> client = api.Client(cfg, api.json_handler)
>>> client.request_kwargs['auth'] = get_auth()
>>> client.post(USER_PATH, {
>>>     'username': 'superuser',
>>>     'password': 'admin',
>>>     'is_superuser': True
>>> })

The returned object can also be used directly with Requests. For more information, see the For more information, see the Requests Authentication documentation.

Parameters:cfg (pulp_smash.config.PulpSmashConfig) – Information about a Pulp app.
Returns:A random authentication object.
pulp_smash.tests.pulp3.utils.get_content(repo, version_href=None)

Read the content units of a given repository.

Parameters:
  • repo – A dict of information about the repository.
  • version_href – The repository version to read. If none, read the latest repository version.
Returns:

A dict of information about the content units present in a given repository version.

pulp_smash.tests.pulp3.utils.get_content_unit_paths(repo)

Return the relative path of content units present in a given repository.

Parameters:repo – A dict of information about the repository.
Returns:A list with the paths of units present in a given repository.
pulp_smash.tests.pulp3.utils.get_plugins(cfg=None)

Return the set of plugins installed on the Pulp application.

Pulp’s API endpoint for reporting plugins and their versions doesn’t work correctly at this time. Some hacks are implemented to discover which plugins are installed. As a result, not all plugins are returned.

Parameters:cfg (pulp_smash.config.PulpSmashConfig) – Information about the Pulp application under test.
Returns:A set of plugin names, e.g. {'pulpcore', 'pulp_file'}.
pulp_smash.tests.pulp3.utils.get_removed_content(repo, version_href=None)

Read the removed content of a given repository version.

Parameters:
  • repo – A dict of information about the repository.
  • version_href – The repository version to read. If none, read the latest repository version.
Returns:

A dict of information about the content removed since the previous repository version.

pulp_smash.tests.pulp3.utils.get_repo_versions(repo)

Return hrefs of repository versions.

Parameters:repo – A dict of information about the repository.
Returns:A sorted list with the hrefs of repository versions.
pulp_smash.tests.pulp3.utils.publish_repo(cfg, publisher, repo, version_href=None)

Publish a repository.

Parameters:
  • cfg (pulp_smash.config.PulpSmashConfig) – Information about the Pulp host.
  • publisher – A dict of information about the publisher of the repository to be published.
  • repo – A dict of information about the repository.
  • version_href – The repository version to be published.
Returns:

A publication. A dict of information about the just created publication.

pulp_smash.tests.pulp3.utils.require_pulp_3()

Skip tests if Pulp 3 isn’t under test.

pulp_smash.tests.pulp3.utils.require_pulp_plugins(required_plugins)

Skip tests if one or more plugins are missing.

Parameters:required_plugins – A set of plugin names, e.g. {'pulp-file'}.
pulp_smash.tests.pulp3.utils.sync_repo(cfg, remote, repo)

Sync a repository.

Parameters:
  • cfg (pulp_smash.config.PulpSmashConfig) – Information about the Pulp host.
  • remote – A dict of information about the remote of the repository to be synced.
  • repo – A dict of information about the repository.
Returns:

The server’s response. Call .json() on the response to get a call report.