Skip to content

Commit

Permalink
Fix get*_content methods for repositories with no versions
Browse files Browse the repository at this point in the history
If a repository has no versions, then _latest_version_href will be null,
in which case, there will not be a valid content href to look up.
  • Loading branch information
dralley authored and rochacbruno committed Aug 31, 2018
1 parent 84eca9f commit 52561d9
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions pulp_smash/pulp3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ def get_content(repo, version_href=None):
:returns: A list of information about the content units present in a given
repository version.
"""
version_href = version_href or repo['_latest_version_href']

if version_href is None:
version_href = repo['_latest_version_href']
# Repository has no latest version, and therefore no content.
return []

client = api.Client(config.get_config(), api.page_handler)
return client.get(urljoin(version_href, 'content/'))

Expand All @@ -137,8 +141,12 @@ def get_added_content(repo, version_href=None):
:returns: A list of information about the content added since the previous
repository version.
"""
version_href = version_href or repo['_latest_version_href']

if version_href is None:
version_href = repo['_latest_version_href']
# Repository has no latest version, and therefore no content.
return []

client = api.Client(config.get_config(), api.page_handler)
return client.get(urljoin(version_href, 'added_content/'))

Expand All @@ -152,8 +160,12 @@ def get_removed_content(repo, version_href=None):
:returns: A list of information about the content removed since the
previous repository version.
"""
version_href = version_href or repo['_latest_version_href']

if version_href is None:
version_href = repo['_latest_version_href']
# Repository has no latest version, and therefore no content.
return []

client = api.Client(config.get_config(), api.page_handler)
return client.get(urljoin(version_href, 'removed_content/'))

Expand All @@ -169,8 +181,11 @@ def get_content_summary(repo, version_href=None):
latest repository version.
:returns: The "content_summary" of the repo version.
"""
version_href = version_href or repo['_latest_version_href']

if version_href is None:
version_href = repo['_latest_version_href']
# Repository has no latest version, and therefore no content.
return {}

client = api.Client(config.get_config(), api.page_handler)
return client.get(version_href)['content_summary']
Expand Down Expand Up @@ -226,8 +241,12 @@ def delete_version(repo, version_href=None):
deleted.
:returns: A tuple. The tasks spawned by Pulp.
"""
version_href = version_href or repo['_latest_version_href']

if version_href is None:
version_href = repo['_latest_version_href']
# Repository has no latest version.
raise ValueError('No version exists to be deleted.')

cfg = config.get_config()
client = api.Client(cfg, api.json_handler)
call_report = client.delete(version_href)
Expand Down

0 comments on commit 52561d9

Please sign in to comment.