Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 8, 2024
1 parent 6ded1b3 commit a8fdda6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pubtools/_pulp/tasks/push/items/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def upload_repo(self):
Subclasses MAY override this to return a variable default destination.
Subclasses must set MULTI_UPLOAD_CONTEXT to True for this to be used.
"""
return "" # pragma: no cover
return "" # pragma: no cover

@classmethod
def for_item(cls, pushsource_item, **kwargs):
Expand Down
12 changes: 8 additions & 4 deletions pubtools/_pulp/tasks/push/items/erratum.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ def upload_repo(self):
# is formatted like RHXA-YYYY
name_match = self.ADVISORY_PATTERN.match(self.pushsource_item.name)
if not name_match:
LOG.error("Bad Advisory name: '%s' does not contain a reasonable year value.",
self.pushsource_item.name)
LOG.error(
"Bad Advisory name: '%s' does not contain a reasonable year value.",
self.pushsource_item.name,
)
raise ErratumPushItemException
year = int(name_match.group(1))
if not any([r[0] <= year <= r[1] for r in self.CONTENT_SPLIT_RANGES]):
LOG.warning("%s was not in a valid date range for repo content splitting, using the default.",
self.pushsource_item.name )
LOG.warning(
"%s was not in a valid date range for repo content splitting, using the default.",
self.pushsource_item.name,
)
year = "0000"
return "all-erratum-content-%s" % year

Expand Down
7 changes: 5 additions & 2 deletions pubtools/_pulp/tasks/push/phase/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ def run(self):
if item_type not in upload_context:
upload_context[item_type] = {}
if item.upload_repo not in upload_context[item_type]:
upload_context[item_type][item.upload_repo] = \
upload_context[item_type][item.upload_repo] = (
item.upload_context(self.pulp_client)
)
ctx = upload_context[item_type][item.upload_repo]
else:
if item_type not in upload_context:
upload_context[item_type] = item.upload_context(self.pulp_client)
upload_context[item_type] = item.upload_context(
self.pulp_client
)
ctx = upload_context[item_type]
uploading += 1
self.put_future_output(item.ensure_uploaded(ctx))
Expand Down
13 changes: 9 additions & 4 deletions tests/fake/test_fake_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ def test_state_persisted(tmpdir, data_path):
# It should already have a few repos since there is some default
# state.
repo_ids = sorted([repo.id for repo in client.search_repository()])
assert repo_ids == ["all-erratum-content-2019", "all-erratum-content-2020",
"all-iso-content", "all-rpm-content",
"all-rpm-content-54", "all-rpm-content-e8",
"redhat-maintenance"]
assert repo_ids == [
"all-erratum-content-2019",
"all-erratum-content-2020",
"all-iso-content",
"all-rpm-content",
"all-rpm-content-54",
"all-rpm-content-e8",
"redhat-maintenance",
]

# Now add a bit more state.
# We use modules here because that's one of the more complex types
Expand Down
19 changes: 10 additions & 9 deletions tests/push/test_pulperratumpushitem.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from pubtools.pulplib import ErratumUnit
from pushsource import ErratumPushItem

from pubtools._pulp.tasks.push.items import PulpErratumPushItem, State, ErratumPushItemException
from pubtools._pulp.tasks.push.items import (
PulpErratumPushItem,
State,
ErratumPushItemException,
)
import pytest


def test_erratum_publishes_all_repos():
item = PulpErratumPushItem(
# We're being asked to push an advisory to a few repos...
Expand Down Expand Up @@ -31,12 +36,11 @@ def test_erratum_publishes_all_repos():
# all-rpm-content is an exception given that those repos don't get published.
assert item.publish_pulp_repos == ["existing1", "existing2", "new1", "new2"]


def test_erratum_upload_repo_normal():
# Test upload_repo maps name to expected repo

item = PulpErratumPushItem(
pushsource_item=ErratumPushItem(name="RHSA-2019:1234")
)
item = PulpErratumPushItem(pushsource_item=ErratumPushItem(name="RHSA-2019:1234"))

assert item.upload_repo == "all-erratum-content-2019"

Expand All @@ -45,14 +49,11 @@ def test_erratum_upload_repo_default():
# Test upload_repo maps name to default repo when advisory year is outside
# the expected range

item = PulpErratumPushItem(
pushsource_item=ErratumPushItem(name="RHSA-1999:1234")
)
item = PulpErratumPushItem(pushsource_item=ErratumPushItem(name="RHSA-1999:1234"))

assert item.upload_repo == "all-erratum-content-0000"



def test_erratum_upload_repo_bad_format():
# Test upload_repo maps name to default repo when advisory year is outside
# the expected range
Expand All @@ -61,4 +62,4 @@ def test_erratum_upload_repo_bad_format():
item = PulpErratumPushItem(
pushsource_item=ErratumPushItem(name="RHSA-fail:1234")
)
item.upload_repo
item.upload_repo
6 changes: 4 additions & 2 deletions tests/push/test_push_prepush.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ def test_pre_push(
assert units

# RPMs are separated into different arc repos by checksum
expected_repo_mapping = {"test-srpm01": ["all-rpm-content-54"],
"walrus": ["all-rpm-content-e8"]}
expected_repo_mapping = {
"test-srpm01": ["all-rpm-content-54"],
"walrus": ["all-rpm-content-e8"],
}

for unit in units:
# The only type of content is RPMs, because that's all we support for
Expand Down

0 comments on commit a8fdda6

Please sign in to comment.