diff --git a/anitya_schema/project_messages.py b/anitya_schema/project_messages.py index 7c95da1..0344b24 100644 --- a/anitya_schema/project_messages.py +++ b/anitya_schema/project_messages.py @@ -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): """ @@ -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): """ @@ -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): """ diff --git a/anitya_schema/tests/test_project_messages.py b/anitya_schema/tests/test_project_messages.py index bc0d537..750c599 100644 --- a/anitya_schema/tests/test_project_messages.py +++ b/anitya_schema/tests/test_project_messages.py @@ -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.""" @@ -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.""" @@ -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.""" @@ -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.""" @@ -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