Merge lp:~jcsackett/launchpad/no-releases-for-projectmilestone into lp:launchpad

Proposed by j.c.sackett on 2012-12-11
Status: Merged
Approved by: j.c.sackett on 2012-12-11
Approved revision: no longer in the source branch.
Merged at revision: 16364
Proposed branch: lp:~jcsackett/launchpad/no-releases-for-projectmilestone
Merge into: lp:launchpad
Diff against target: 39 lines (+23/-1)
2 files modified
lib/lp/registry/browser/milestone.py (+1/-1)
lib/lp/registry/browser/tests/test_milestonetag.py (+22/-0)
To merge this branch: bzr merge lp:~jcsackett/launchpad/no-releases-for-projectmilestone
Reviewer Review Type Date Requested Status
Richard Harding (community) 2012-12-11 Approve on 2012-12-11
Review via email: mp+139221@code.launchpad.net

Commit Message

Fixes milestone views to handle projectmilestonetags, which don't have a product_release attr.

Description of the Change

Summary
=======
ProjectMilestoneTags do not have a product_release attr, but the view assumes
the context will always have this if they are of type IMilestoneData. This
leads to an OOPS.

The view should simply set the release data to None if the attribute doesn't
exist, and shouldn't assume the attribute does exist.

Preimp
======
None.

Implementation
==============
The assignment of `self.release = context.product_release` has been replaced
with an assignment to the result of getattr on the context, defaulting to None
if the atter doesn't exist.

Tests
=====
bin/test -vvct test_projectgroup_milestone

QA
==
Load the url in the OOPS; it should load.

LoC
===
Part of private projects.

Lint
====

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/registry/browser/milestone.py
  lib/lp/registry/browser/tests/test_milestonetag.py

To post a comment you must log in.
Richard Harding (rharding) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/milestone.py'
2--- lib/lp/registry/browser/milestone.py 2012-10-19 03:01:32 +0000
3+++ lib/lp/registry/browser/milestone.py 2012-12-11 15:09:23 +0000
4@@ -377,7 +377,7 @@
5 super(MilestoneView, self).__init__(context, request)
6 if IMilestoneData.providedBy(context):
7 self.milestone = context
8- self.release = context.product_release
9+ self.release = getattr(context, "product_release", None)
10 else:
11 self.milestone = context.milestone
12 self.release = context
13
14=== added file 'lib/lp/registry/browser/tests/test_milestonetag.py'
15--- lib/lp/registry/browser/tests/test_milestonetag.py 1970-01-01 00:00:00 +0000
16+++ lib/lp/registry/browser/tests/test_milestonetag.py 2012-12-11 15:09:23 +0000
17@@ -0,0 +1,22 @@
18+# Copyright 2012 Canonical Ltd. This software is licensed under the
19+# GNU Affero General Public License version 3 (see the file LICENSE).
20+
21+"""Test projectmilestone tag views."""
22+
23+__metaclass__ = type
24+
25+from lp.services.webapp import canonical_url
26+from lp.testing import TestCaseWithFactory
27+from lp.testing.layers import DatabaseFunctionalLayer
28+
29+
30+class TestProjectMilestoneTagView(TestCaseWithFactory):
31+
32+ layer = DatabaseFunctionalLayer
33+
34+ def test_projectgroup_milestone(self):
35+ # The projectgroup milestone tag page loads without errors.
36+ group = self.factory.makeProject()
37+ url = canonical_url(group) + "/+tags/fab/+index"
38+ browser = self.getUserBrowser(url=url)
39+ self.assertTrue('fab' in browser.contents)