Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the packages property when relevant #70

Merged
merged 1 commit into from
Oct 1, 2024
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
26 changes: 26 additions & 0 deletions anitya_schema/project_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,14 @@ def package_name(self):
"""Package name for the new mapping."""
return self.body["message"]["new"]

@property
def packages(self):
"""Fedora packages related to the change."""
if self.distro == "Fedora":
return [self.package_name]
else:
return []


class ProjectMapEdited(ProjectMessage):
"""
Expand Down Expand Up @@ -506,6 +514,15 @@ def package_name_prev(self):
"""Previous package name for the mapping."""
return self.body["message"]["prev"]

@property
def packages(self):
"""Fedora packages related to the change."""
if self.distro != "Fedora":
return []
pkgs = list(set([self.package_name_prev, self.package_name_new]))
pkgs.sort()
return pkgs


class ProjectMapDeleted(ProjectMessage):
"""
Expand Down Expand Up @@ -779,6 +796,15 @@ def stable_versions(self):
"""All stable versions on the project."""
return self.body["message"]["stable_versions"]

@property
def packages(self):
"""Fedora packages related to the change."""
return [
package["package_name"]
for package in self.body["message"]["packages"]
if package["distro"] == "Fedora"
]


class ProjectVersionDeleted(ProjectMessage):
"""
Expand Down
55 changes: 55 additions & 0 deletions anitya_schema/tests/test_project_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ def test_package_name(self):

assert self.message.package_name == "Dummy"

@pytest.mark.parametrize("distro,packages", [("Fedora", ["dummy"]), ("CentOS", [])])
def test_packages_fedora(self, distro, packages):
"""Assert that packages list is filled only when it's on Fedora"""
self.message.body = {"distro": {"name": distro}, "message": {"new": "dummy"}}

assert self.message.packages == packages


class TestProjectMapEdited:
"""Tests for anitya_schema.project_messages.ProjectMapEdited class."""
Expand Down Expand Up @@ -421,6 +428,26 @@ def test_package_name_prev(self):

assert self.message.package_name_prev == "Dummy"

@pytest.mark.parametrize(
"distro,packages", [("Fedora", ["dummy", "dummy_prev"]), ("CentOS", [])]
)
def test_packages_fedora(self, distro, packages):
"""Assert that packages list is filled only when it's on Fedora"""
self.message.body = {
"distro": {"name": distro},
"message": {"prev": "dummy_prev", "new": "dummy"},
}
assert self.message.packages == packages

@pytest.mark.parametrize("distro,packages", [("Fedora", ["dummy"]), ("CentOS", [])])
def test_packages_fedora_same_package(self, distro, packages):
"""Assert that packages list is filled only when it's on Fedora"""
self.message.body = {
"distro": {"name": distro},
"message": {"prev": "dummy", "new": "dummy"},
}
assert self.message.packages == packages


class TestProjectMapDeleted:
"""Tests for anitya_schema.project_messages.ProjectMapDeleted class."""
Expand Down Expand Up @@ -462,6 +489,14 @@ def test_distro(self):

assert self.message.distro == "Dummy"

@pytest.mark.skip("The package name is not part of the message")
@pytest.mark.parametrize("distro,packages", [("Fedora", ["dummy"]), ("CentOS", [])])
def test_packages_fedora(self, distro, packages):
"""Assert that packages list is filled only when it's on Fedora"""
self.message.body = {"distro": {"name": distro}, "message": {"old": "dummy"}}

assert self.message.packages == packages


class TestProjectVersionUpdated:
"""Tests for anitya_schema.project_messages.ProjectVersionUpdated class."""
Expand Down Expand Up @@ -657,6 +692,18 @@ def test_stable_versions(self):

assert self.message.stable_versions == ["1.0.0", "0.9.0"]

def test_packages_fedora(self):
"""Assert that packages list is filled only when it's on Fedora"""
self.message.body = {
"message": {
"packages": [
{"distro": "Fedora", "package_name": "package_fedora"},
{"distro": "CentOS", "package_name": "package_centos"},
]
}
}
assert self.message.packages == ["package_fedora"]


class TestProjectVersionDeleted:
"""Tests for anitya_schema.project_messages.ProjectVersionDeleted class."""
Expand Down Expand Up @@ -768,3 +815,11 @@ def test_versions(self):
self.message.body = {"message": {"versions": ["1.0.0"]}}

assert self.message.versions == ["1.0.0"]

@pytest.mark.skip("The package name is not part of the message")
@pytest.mark.parametrize("distro,packages", [("Fedora", ["dummy"]), ("CentOS", [])])
def test_packages_fedora(self, distro, packages):
"""Assert that packages list is filled only when it's on Fedora"""
self.message.body = {"message": {"distro": distro, "package": "dummy"}}

assert self.message.packages == packages