Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix usage of `errata` source when the an Errata Tool URL includes a path
component.

### Changed
- On `ErratumPushItem`, the `type` attribute will now be automatically converted
from legacy values found in the wild such as "RHBA", "RHSA". Values are
now also validated.

## [2.6.0] - 2021-05-27

### Added
Expand Down
1 change: 1 addition & 0 deletions src/pushsource/_impl/model/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def int2str(value):
return value


in_ = attr.validators.in_
instance_of = attr.validators.instance_of
instance_of_str = instance_of(six.string_types)
optional = attr.validators.optional
Expand Down
17 changes: 16 additions & 1 deletion src/pushsource/_impl/model/erratum.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .base import PushItem
from .. import compat_attr as attr
from .conv import (
in_,
int2str,
md5str,
sha1str,
Expand Down Expand Up @@ -201,6 +202,15 @@ def _from_data(cls, data):
)


def errata_type_converter(value):
# For 'type' field, ancient versions of Errata Tool produced values
# like RHBA, RHEA, RHSA, so these can be found in the wild; but all
# other sources (including our own model) prefer strings like "bugfix".
# We'll convert up from legacy values automatically.
typemap = {"RHBA": "bugfix", "RHEA": "enhancement", "RHSA": "security"}
return typemap.get(value, value)


@attr.s()
class ErratumPushItem(PushItem):
"""A :class:`~pushsource.PushItem` representing a single erratum (also known as "advisory").
Expand All @@ -210,7 +220,12 @@ class ErratumPushItem(PushItem):
examples).
"""

type = attr.ib(type=str, default="bugfix", validator=instance_of_str)
type = attr.ib(
type=str,
default="bugfix",
validator=in_(["bugfix", "security", "enhancement"]),
converter=errata_type_converter,
)
"""'bugfix', 'security' or 'enhancement'."""

release = attr.ib(
Expand Down
26 changes: 26 additions & 0 deletions tests/model/test_errata_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from pushsource import ErratumPushItem


@pytest.mark.parametrize(
"in_type,out_type",
[
("RHBA", "bugfix"),
("RHEA", "enhancement"),
("RHSA", "security"),
("bugfix", "bugfix"),
("enhancement", "enhancement"),
("security", "security"),
],
)
def test_type_converted(in_type, out_type):
"""ErratumPushItem converts values of 'type' field to one of the expected."""
item = ErratumPushItem(name="TEST-123", type=in_type)
assert item.type == out_type


def test_type_enforced():
"""ErratumPushItem complains on invalid values for 'type'"""
with pytest.raises(ValueError):
ErratumPushItem(name="TEST-123", type="oops-bad-type")