Commit 36454cbd authored by Raphaël Hertzog's avatar Raphaël Hertzog

Merge branch 'mr-origin-72'

parents b410e4b5 4df364f4
...@@ -21,10 +21,12 @@ from django.test.utils import override_settings ...@@ -21,10 +21,12 @@ from django.test.utils import override_settings
from distro_tracker.core.models import ( from distro_tracker.core.models import (
ActionItem, ActionItem,
PackageData, PackageData,
PackageName,
SourcePackage, SourcePackage,
SourcePackageName SourcePackageName
) )
from distro_tracker.core.utils.packages import package_url 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 UpdateDebciStatusTask
from distro_tracker.test import TemplateTestsMixin, TestCase from distro_tracker.test import TemplateTestsMixin, TestCase
from distro_tracker.test.utils import set_mock_response from distro_tracker.test.utils import set_mock_response
...@@ -259,3 +261,115 @@ class DebciLinkTest(TestCase, TemplateTestsMixin): ...@@ -259,3 +261,115 @@ class DebciLinkTest(TestCase, TemplateTestsMixin):
response, response,
self.url self.url
) )
@override_settings(
INSTALLED_APPS=['django.contrib.staticfiles',
'distro_tracker.core',
'distro_tracker.html',
'distro_tracker.accounts',
'distro_tracker.debci_status',
'distro_tracker.vendor.kali'],
DISTRO_TRACKER_DEBCI_REPOSITORIES=['unstable', 'stable'],
DISTRO_TRACKER_DEBCI_URL='https://ci.debian.net',
DISTRO_TRACKER_DEVEL_REPOSITORIES=['unstable'])
class DebciTableFieldTest(TestCase):
"""
Tests that the debci field behaves as expected, with the proper content.
"""
def setUp(self):
self.package_name = SourcePackageName.objects.create(name='dummy')
self.url = 'https://ci.debian.net/packages/d/dummy'
self.package = SourcePackage.objects.create(
source_package_name=self.package_name,
version='1.0.0',
repository='unstable')
self.package_name2 = SourcePackageName.objects.create(name='package')
self.url2 = 'https://ci.debian.net/packages/p/package'
self.package2 = SourcePackage.objects.create(
source_package_name=self.package_name2,
version='1.0.0',
repository='unstable')
self.package_name3 = SourcePackageName.objects.create(name='other')
self.url3 = 'https://ci.debian.net/packages/o/other'
self.package3 = SourcePackage.objects.create(
source_package_name=self.package_name3,
version='1.0.0',
repository='unstable')
PackageData.objects.create(
package=self.package_name,
key='debci',
value=[{'result': {'status': 'fail'},
'repository': 'unstable',
'url': self.url}])
PackageData.objects.create(
package=self.package_name3,
key='debci',
value=[{'result': {'status': 'fail'},
'repository': 'unstable',
'url': self.url3},
{'result': {'status': 'pass'},
'repository': 'stable',
'url': self.url3}])
self.field = DebciTableField()
packages = PackageName.objects.filter(name=self.package_name)
for prefetch in self.field.prefetch_related_lookups:
packages = packages.prefetch_related(prefetch)
self.package = packages[0]
packages = PackageName.objects.filter(name=self.package_name3)
for prefetch in self.field.prefetch_related_lookups:
packages = packages.prefetch_related(prefetch)
self.package3 = packages[0]
def test_field_specific_properties(self):
"""
Tests field specific properties
"""
self.assertEqual(self.field.column_name, 'Tests')
self.assertEqual(self.field.slug, 'debci')
self.assertEqual(self.field.template_name, 'debci_status/debci.html')
self.assertEqual(len(self.field.prefetch_related_lookups), 1)
def test_package_with_debci_report(self):
"""
Tests field context content when debci data is present
"""
context = self.field.context(self.package)
self.assertTrue(context['statuses'])
expectedStatus = [{'repository': 'unstable',
'status': 'fail'}]
self.assertEqual(context['statuses'], expectedStatus)
def test_package_without_debci_report(self):
"""
Tests field context content when debci data is not present
"""
context = self.field.context(self.package2)
self.assertEqual(len(context['statuses']), 0)
def test_deterministic_order_in_context(self):
"""
Make sure the order in the context's statuses array is "stable,unstable"
"""
context = self.field.context(self.package3)
expectedStatus = [{'repository': 'stable',
'status': 'pass'},
{'repository': 'unstable',
'status': 'fail'}]
self.assertEqual(context['statuses'], expectedStatus)
def test_label_warning_for_mixed_results(self):
"""
Make sure the label is correct when some tests pass while others fail
"""
context = self.field.context(self.package3)
self.assertEqual(context['label_type'], 'warning')
...@@ -43,7 +43,8 @@ class DebciTableField(BaseTableField): ...@@ -43,7 +43,8 @@ class DebciTableField(BaseTableField):
try: try:
# build list of status hashes, for popover # build list of status hashes, for popover
ctx['statuses'] = [] ctx['statuses'] = []
for debci in package.debci[0].value: for debci in sorted(getattr(package, 'debci', [])[0].value,
key=lambda e: e['repository']):
status = debci['result']['status'] status = debci['result']['status']
repository = debci['repository'] repository = debci['repository']
ctx['statuses'].append({'repository': repository, ctx['statuses'].append({'repository': repository,
......
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