← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jcsackett/launchpad/tags-portlet-708693 into lp:launchpad

 

j.c.sackett has proposed merging lp:~jcsackett/launchpad/tags-portlet-708693 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #708693 LocationError: 'tags_cloud_data' on project bugs' page
  https://bugs.launchpad.net/bugs/708693

For more details, see:
https://code.launchpad.net/~jcsackett/launchpad/tags-portlet-708693/+merge/48029

Summary
=======

Certain projectgroups are encountering a LocationError for tags_cloud_data on +bugtarget-portlet-tags-content. The tags_cloud_data property is always available for the view when it uses that template, though it sometimes returns no data; the actual problem is in a list comprehension that gets a TypeError for certain combinations of tags vs no tags. This branch casts one set of tags used in the property to list before further operations, removing the type error.

Proposed Fix
============

Cast storm resultsets to list in the tags_cloud_data method so that we're only working with lists, rather than a combination of lists and resultsets.

Implementation
==============

lib/lp/bugs/browser/bugtarget.py
--------------------------------


Cast self.context.official_bug_tags to list, so that it plays well with other lists in subsequent list comprehensions.
  
lib/lp/bugs/browser/tests/test_bugtarget_tags.py  
lib/lp/testing/factory.py
-------------------------

Create simple tests for the tag_cloud_data property. makeBug in factory was updated to allow tags to be passed in when making the bug.

Tests
=====

bin/test -m lp.bugs.browser.tests.test_bugtarget_tags

Demo & QA
=========

https://bugs.launchpad.net/mysql/+bugtarget-portlet-tags-content

Lint
====

make lint output:

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:  
lib/lp/bugs/browser/bugtarget.py  
lib/lp/bugs/browser/tests/test_bugtarget_tags.py  
lib/lp/testing/factory.py
-- 
https://code.launchpad.net/~jcsackett/launchpad/tags-portlet-708693/+merge/48029
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jcsackett/launchpad/tags-portlet-708693 into lp:launchpad.
=== modified file 'lib/lp/bugs/browser/bugtarget.py'
--- lib/lp/bugs/browser/bugtarget.py	2011-01-11 11:51:27 +0000
+++ lib/lp/bugs/browser/bugtarget.py	2011-01-31 18:17:49 +0000
@@ -1352,7 +1352,7 @@
     @property
     def tags_cloud_data(self):
         """The data for rendering a tags cloud"""
-        official_tags = self.context.official_bug_tags
+        official_tags = list(self.context.official_bug_tags)
         tags = self.getUsedBugTagsWithURLs()
         other_tags = [tag for tag in tags if tag['tag'] not in official_tags]
         popular_tags = [tag['tag'] for tag in sorted(

=== added file 'lib/lp/bugs/browser/tests/test_bugtarget_tags.py'
--- lib/lp/bugs/browser/tests/test_bugtarget_tags.py	1970-01-01 00:00:00 +0000
+++ lib/lp/bugs/browser/tests/test_bugtarget_tags.py	2011-01-31 18:17:49 +0000
@@ -0,0 +1,39 @@
+# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+__metaclass__ = type
+
+from canonical.testing.layers import DatabaseFunctionalLayer
+from lp.testing import (
+    TestCaseWithFactory,
+    )
+from lp.bugs.publisher import BugsLayer
+from lp.testing.views import create_view
+
+
+class TestBugTargetTags(TestCaseWithFactory):
+
+    layer = DatabaseFunctionalLayer
+
+    def setUp(self):
+        super(TestBugTargetTags, self).setUp()
+        self.project = self.factory.makeProject()
+        self.target_product = self.factory.makeProduct(project=self.project)
+
+    def test_no_tags(self):
+        self.factory.makeBug(product=self.target_product)
+        view = create_view(
+            self.project,
+            name="+bugtarget-portlet-tags-content",
+            layer=BugsLayer)
+        self.assertEqual([], [tag['tag'] for tag in view.tags_cloud_data])
+
+    def test_tags(self):
+        self.factory.makeBug(product=self.target_product, tags=['foo'])
+        view = create_view(
+            self.project,
+            name="+bugtarget-portlet-tags-content",
+            layer=BugsLayer)
+        self.assertEqual(
+            [u'foo'],
+            [tag['tag'] for tag in view.tags_cloud_data])

=== modified file 'lib/lp/testing/factory.py'
--- lib/lp/testing/factory.py	2011-01-27 23:13:20 +0000
+++ lib/lp/testing/factory.py	2011-01-31 18:17:49 +0000
@@ -1393,7 +1393,8 @@
     def makeBug(self, product=None, owner=None, bug_watch_url=None,
                 private=False, date_closed=None, title=None,
                 date_created=None, description=None, comment=None,
-                status=None, distribution=None, milestone=None, series=None):
+                status=None, distribution=None, milestone=None, series=None,
+                tags=None):
         """Create and return a new, arbitrary Bug.
 
         The bug returned uses default values where possible. See
@@ -1412,6 +1413,7 @@
         :param series: If set, the series.product must match the product
             parameter, or the series.distribution must match the distribution
             parameter, or the those parameters must be None.
+        :param tags: If set, the tags to be added with the bug.
 
         At least one of the parameters distribution and product must be
         None, otherwise, an assertion error will be raised.
@@ -1437,7 +1439,7 @@
         create_bug_params = CreateBugParams(
             owner, title, comment=comment, private=private,
             datecreated=date_created, description=description,
-            status=status)
+            status=status, tags=tags)
         create_bug_params.setBugTarget(
             product=product, distribution=distribution)
         bug = getUtility(IBugSet).createBug(create_bug_params)