On Sat, Aug 30, 2014 at 5:29 AM, Raphael Hertzog <hert...@debian.org> wrote: > On Fri, 29 Aug 2014, Andrew Starr-Bochicchio wrote: >> > It should probably be a method of PackageName so that we get the short >> > description for free in any other context... for example in the mail >> > bot when we confirm the subscription or something like that. >> >> Makes sense. I think I've addressed all the other issues as well. > > Hum, not really, it still makes direct queries instead of relying on > attributes of the (Source|Binary)PackageName object:
I suspect that I'm becoming more annoying than helpful at this point... Let's hope the third time's the charm. Thanks! -- Andrew Starr-Bochicchio Ubuntu Developer <https://launchpad.net/~andrewsomething> Debian Developer <http://qa.debian.org/developer.php?login=asb> PGP/GPG Key ID: D53FDCB1
From e9515f0fca46cc13376463c6f4ebd4da35cd1898 Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio <a.star...@gmail.com> Date: Fri, 29 Aug 2014 13:05:03 -0700 Subject: [PATCH] Add the short description under the source package name. The current PTS only uses the short description if there is a binary package that has the same name as the source package. If not, it just displays "Source package" I have decided to fall back to the short description for the first binary package instead. --- distro_tracker/core/models.py | 23 ++++++++++ distro_tracker/core/templates/core/package.html | 1 + distro_tracker/core/tests/tests_models.py | 29 +++++++++++++ distro_tracker/core/tests/tests_views.py | 56 ++++++++++++++++++++++++- 4 files changed, 107 insertions(+), 2 deletions(-) diff --git a/distro_tracker/core/models.py b/distro_tracker/core/models.py index 2a16944..a9c669f 100644 --- a/distro_tracker/core/models.py +++ b/distro_tracker/core/models.py @@ -450,6 +450,29 @@ class SourcePackageName(PackageName): } return Repository.objects.filter(**kwargs).distinct() + def short_description(self): + """ + Returns the most recent short description for a source package. If there + is a binary package whose name matches the source package, its + description will be used. If not, the short description for the first + binary package will be used. + """ + desc = None + + try: + binary_packages = self.main_version.binarypackage_set.all() + + for pkg in binary_packages: + if desc is None: + desc = pkg.short_description + if pkg.binary_package_name.name == self.name: + desc = pkg.short_description + break + except AttributeError: + desc = '' + + return desc + def get_web_package(package_name): """ diff --git a/distro_tracker/core/templates/core/package.html b/distro_tracker/core/templates/core/package.html index c17f90f..3402eb8 100644 --- a/distro_tracker/core/templates/core/package.html +++ b/distro_tracker/core/templates/core/package.html @@ -16,6 +16,7 @@ </div> <div class="span6 col col-lg-6 text-center"> <h1>{{ package }}</h1> + <h4>{{ package.short_description }}</h4> </div> <div class="span3 col col-lg-3"> {% include 'core/package-search-form.html' %} diff --git a/distro_tracker/core/tests/tests_models.py b/distro_tracker/core/tests/tests_models.py index da7df4e..50f8e52 100644 --- a/distro_tracker/core/tests/tests_models.py +++ b/distro_tracker/core/tests/tests_models.py @@ -1615,3 +1615,32 @@ class TeamTests(TestCase): self.assertTrue(membership.is_muted(self.package_name)) # The other package isn't self.assertFalse(membership.is_muted(package)) + + +class SourcePackageNameTests(TestCase): + """ + Tests for the :class:`distro_tracker.core.models.SourcePackageName` model. + """ + def setUp(self): + self.package = SourcePackageName.objects.create(name='dummy-package') + self.binary_package = BinaryPackageName.objects.create( + name='binary-package') + self.pseudo_package = \ + PseudoPackageName.objects.create(name='pseudo-pkg') + src_pkg = SourcePackage.objects.create( + source_package_name=self.package, version='1.0.0') + bin_pkg = BinaryPackage.objects.create( + binary_package_name=self.binary_package, + source_package=src_pkg, + short_description='a useful package') + src_pkg.binary_packages = [self.binary_package] + src_pkg.save() + bin_pkg.save() + + def test_get_short_description_for_source_pkg(self): + self.assertEqual(self.package.short_description(), 'a useful package') + + def test_get_short_description_with_no_binary_pkgs(self): + pkg = SourcePackageName.objects.create(name='some-package') + + self.assertEqual(pkg.short_description(), '') diff --git a/distro_tracker/core/tests/tests_views.py b/distro_tracker/core/tests/tests_views.py index ba57849..be0283f 100644 --- a/distro_tracker/core/tests/tests_views.py +++ b/distro_tracker/core/tests/tests_views.py @@ -16,9 +16,9 @@ Tests for the Distro Tracker core views. from __future__ import unicode_literals from distro_tracker.test import TestCase from django.test.utils import override_settings -from distro_tracker.core.models import PackageName, BinaryPackageName +from distro_tracker.core.models import BinaryPackage, BinaryPackageName from distro_tracker.core.models import SourcePackageName, SourcePackage -from distro_tracker.core.models import PseudoPackageName +from distro_tracker.core.models import PackageName, PseudoPackageName from distro_tracker.core.models import ActionItem, ActionItemType import json @@ -40,8 +40,13 @@ class PackageViewTest(TestCase): PseudoPackageName.objects.create(name='pseudo-pkg') src_pkg = SourcePackage.objects.create( source_package_name=self.package, version='1.0.0') + bin_pkg = BinaryPackage.objects.create( + binary_package_name=self.binary_package, + source_package=src_pkg, + short_description='a useful package') src_pkg.binary_packages = [self.binary_package] src_pkg.save() + bin_pkg.save() def get_package_url(self, package_name): """ @@ -164,6 +169,53 @@ class PackageViewTest(TestCase): response = self.client.get(url, follow=True) self.assertEqual(404, response.status_code) + def test_short_desc_on_page_when_different(self): + """ + Tests that the short description is displayed. + """ + url = self.get_package_url(self.package.name) + response = self.client.get(url) + response_content = response.content.decode('utf-8') + + self.assertIn('a useful package', response_content) + + def test_short_desc_on_page_when_same(self): + """ + Tests that the short description is displayed when the source package + and binary package have the same name. + """ + package = SourcePackageName.objects.get_or_create( + name='another-package') + src_pkg = SourcePackage.objects.get_or_create( + source_package_name=package[0], version='2.0.0') + binary_package = BinaryPackageName.objects.get_or_create( + name='another-package') + bin_pkg = BinaryPackage.objects.get_or_create( + binary_package_name=binary_package[0], + source_package=src_pkg[0], + short_description='another useful package') + src_pkg[0].binary_packages = [binary_package[0]] + src_pkg[0].save() + bin_pkg[0].save() + + url = self.get_package_url(package[0].name) + response = self.client.get(url) + response_content = response.content.decode('utf-8') + + self.assertIn('another useful package', response_content) + + def test_short_desc_for_pseudopackage(self): + """ + Makes sure it doesn't break on pseudo packages. + """ + package = PseudoPackageName.objects.get_or_create( + name='another-package') + url = self.get_package_url(self.package) + response = self.client.get(url) + response_content = response.content.decode('utf-8') + + self.assertIn('', response_content) + class PackageSearchViewTest(TestCase): def setUp(self): -- 1.9.1