Commit 9b95a552 authored by Sebastien Delafond's avatar Sebastien Delafond Committed by Raphaël Hertzog

debci: add package table listing packages with failed tests

This adds an extra table on team pages listing all packages with failed
tests (as reported by debci), and is used by default for both Debian
and Kali.
parent 486a23bf
......@@ -18,10 +18,18 @@ from unittest import mock
from django.test.utils import modify_settings, override_settings
from distro_tracker.core.models import ActionItem, PackageName
from distro_tracker.core.models import (
ActionItem,
ActionItemType,
PackageData,
PackageName
)
from distro_tracker.core.utils.packages import package_url
from distro_tracker.debci_status.tracker_package_tables import DebciTableField
from distro_tracker.debci_status.tracker_tasks import UpdateDebciStatusTask
from distro_tracker.debci_status.tracker_tasks import (
TagPackagesWithDebciFailures,
UpdateDebciStatusTask
)
from distro_tracker.test import TemplateTestsMixin, TestCase
from distro_tracker.test.utils import set_mock_response
......@@ -340,3 +348,66 @@ class DebciTableFieldTest(TestCase):
"""Make sure the label is correct when all test pass."""
context = self.field.context(self.package4)
self.assertEqual(context['label_type'], 'success')
class TagPackagesWithDebciFailuresTest(TestCase):
"""
Tests for the
:class:`distro_tracker.debci_status.tracker_tasks.TagPackagesWithDebciFailures`
task.
"""
def setUp(self):
self.tag = 'tag:debci-failures'
self.package_with_failed_tests = PackageName.objects.create(
name='dummy')
self.ai_type = ActionItemType.objects.create(
type_name='debci-failed-tests')
self.action_item = ActionItem.objects.create(
package=self.package_with_failed_tests,
item_type=self.ai_type
)
self.package_without_failed_tests = PackageName.objects.create(
name='package')
def run_task(self):
"""
Runs the debci tag packages task.
"""
task = TagPackagesWithDebciFailures()
task.execute()
def test_update_debci_failures_tag_task(self):
"""
Tests the default behavior of TagPackagesWithDebciFailures task
"""
self.run_task()
tagdata = self.package_with_failed_tests.data.get(key=self.tag)
self.assertDoesExist(tagdata)
with self.assertRaises(PackageData.DoesNotExist):
self.package_without_failed_tests.data.get(key=self.tag)
def test_task_remove_tag_from_package_with_failed_tests(self):
"""
Tests the removing of 'tag:package_with_failed_tests'
"""
self.run_task()
self.package_with_failed_tests.action_items.all().delete()
self.run_task()
with self.assertRaises(PackageData.DoesNotExist):
self.package_without_failed_tests.data.get(key=self.tag)
def test_task_keep_tag_for_package_that_still_has_failures(self):
"""
Tests that 'tag:new-upstream-version' remains when a package still
has test failures
"""
self.run_task()
self.run_task()
# check that the task kept the tag
tagdata = self.package_with_failed_tests.data.get(key=self.tag)
self.assertDoesExist(tagdata)
......@@ -27,6 +27,7 @@ from distro_tracker.core.models import (
SourcePackageName
)
from distro_tracker.core.tasks import BaseTask
from distro_tracker.core.tasks.mixins import PackageTagging
from distro_tracker.core.tasks.schedulers import IntervalScheduler
from distro_tracker.core.utils.http import get_resource_text
......@@ -182,3 +183,28 @@ class UpdateDebciStatusTask(BaseTask):
PackageData.objects.bulk_create(infos)
ActionItem.objects.delete_obsolete_items(
[self.debci_action_item_type], packages)
class TagPackagesWithDebciFailures(BaseTask, PackageTagging):
"""
Performs an update of 'debci-failures' tag for packages.
"""
class Scheduler(IntervalScheduler):
interval = 3600
TAG_NAME = 'tag:debci-failures'
TAG_DISPLAY_NAME = 'debci failures'
TAG_COLOR_TYPE = 'danger'
TAG_DESCRIPTION = 'The package has test failures'
TAG_TABLE_TITLE = 'Packages with test failures'
def packages_to_tag(self):
try:
action_type = ActionItemType.objects.get(
type_name='debci-failed-tests')
except ActionItemType.DoesNotExist:
return []
items = action_type.action_items.all().prefetch_related('package')
return [item.package for item in items]
......@@ -577,4 +577,7 @@ def get_tables_for_team_page(team, limit):
tag='tag:new-upstream-version'),
create_table(
slug='general', scope=team, limit=limit, tag='tag:bugs'),
create_table(
slug='general', scope=team, limit=limit,
tag='tag:debci-failures')
]
......@@ -14,6 +14,7 @@ Kali specific rules
import os.path
import re
from distro_tracker.core.package_tables import create_table
from distro_tracker.debci_status.tracker_package_tables import DebciTableField
from distro_tracker.mail import mail_news
......@@ -61,3 +62,20 @@ def get_table_fields(table):
the team's packages table
"""
return table.default_fields + [DebciTableField]
def get_tables_for_team_page(team, limit):
"""
The function must return a list of :class:`BasePackageTable` objects
to be displayed in the main page of teams.
:param team: The team for which the tables must be added.
:type package: :class:`Team <distro_tracker.core.models.Team>`
:param int limit: The number of packages to be displayed in the tables
"""
return [
create_table(slug='general', scope=team, limit=limit),
create_table(
slug='general', scope=team, limit=limit,
tag='tag:debci-failures')
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment