Merge lp:~mabac/svammel/bug-829525 into lp:svammel

Proposed by Mattias Backman
Status: Merged
Approved by: James Westby
Approved revision: 106
Merged at revision: 105
Proposed branch: lp:~mabac/svammel/bug-829525
Merge into: lp:svammel
Diff against target: 233 lines (+74/-53)
2 files modified
bug_reporting.py (+40/-38)
tests/test_fail_filer.py (+34/-15)
To merge this branch: bzr merge lp:~mabac/svammel/bug-829525
Reviewer Review Type Date Requested Status
James Westby (community) Approve
Review via email: mp+72708@code.launchpad.net

Description of the change

Hi,

This branch fixes the problem caused by trying to target a series before setting a milestone. Fixed and tested by doko.

It also adds setting bug status.

Thanks,

Mattias

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Hi,

Is it feasible to have a test that shows the problem with setting the milestone
after the series?

Also a test that the status is set as desired would be good.

Thanks,

James

review: Approve
Revision history for this message
Mattias Backman (mabac) wrote :

On Wed, Aug 24, 2011 at 5:11 PM, James Westby <email address hidden> wrote:
> Review: Approve
> Hi,
>
> Is it feasible to have a test that shows the problem with setting the milestone
> after the series?
>
> Also a test that the status is set as desired would be good.

Yes, that should be no problem. I can work on both those comment tomorrow.

>
> Thanks,
>
> James
>
> --
> https://code.launchpad.net/~mabac/svammel/bug-829525/+merge/72708
> You are the owner of lp:~mabac/svammel/bug-829525.
>

lp:~mabac/svammel/bug-829525 updated
106. By Mattias Backman

Add save tests for setting status. Test that milestone is set before nominating series.

Revision history for this message
Mattias Backman (mabac) wrote :

Added tests for status and one for checking that milestone is set before the series nomination if both series and milestone is requested.

Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bug_reporting.py'
2--- bug_reporting.py 2011-04-20 14:43:31 +0000
3+++ bug_reporting.py 2011-09-01 13:52:24 +0000
4@@ -37,7 +37,7 @@
5
6
7 def file_bug_by_url(target_url, description, title, tags, lp, importance=None,
8- milestone_name=None, series_name=None):
9+ milestone_name=None, series_name=None, status='Confirmed'):
10 """ File a bug on the bug target specified by target_url.
11
12 Returns the newly created bug or None if no bug was filed.
13@@ -54,7 +54,24 @@
14 try:
15 target = lp.distributions['ubuntu']
16 logger.debug("Series and milestone target is %s." % target)
17- ms_bugtask = None
18+
19+ ms_bugtask = bug.bug_tasks[0]
20+
21+ if milestone_name is not None:
22+ milestone = target.getMilestone(name=milestone_name)
23+ logger.debug("Target milestone is %s." % milestone)
24+ if milestone is None:
25+ raise AttributeError(
26+ "Milestone '%s' not valid for target '%s'." % \
27+ (milestone_name, target.name))
28+ set_bugtask_milestone(ms_bugtask, milestone)
29+
30+ if status is not None:
31+ set_bugtask_status(ms_bugtask, status)
32+
33+ if importance is not None:
34+ set_bugtask_importance(ms_bugtask, importance)
35+
36 if series_name is not None:
37 series = target.getSeries(name_or_version=series_name)
38 logger.debug("Adding nomination for series %s." % series)
39@@ -71,36 +88,12 @@
40 if nomination is not None and nomination.canApprove():
41 logger.debug("Approving nomination %s." % nomination)
42 nomination.approve()
43- for candidate_bugtask in bug.bug_tasks:
44- if candidate_bugtask.target == series:
45- ms_bugtask = candidate_bugtask
46- if ms_bugtask is None:
47- raise Exception(
48- "A bug task to set milestone was not found, " \
49- "please report this bug on the svammel project.")
50-
51 elif continue_on_error():
52 logger.warning("Cannot approve nomination %s.", nomination)
53 else:
54 raise AttributeError(
55 "Unable to approve nomination %s." % nomination)
56
57- if milestone_name is not None:
58- milestone = target.getMilestone(name=milestone_name)
59- logger.debug("Target milestone is %s." % milestone)
60- if milestone is None:
61- raise AttributeError(
62- "Milestone '%s' not valid for target '%s'." % \
63- (milestone_name, target.name))
64-
65- if ms_bugtask is None:
66- # If series nomination is done the bug_task
67- # has already been found.
68- ms_bugtask = bug.bug_tasks[0]
69- set_bugtask_milestone(ms_bugtask, milestone)
70-
71- if importance is not None:
72- set_bug_importance(bug, importance)
73 except Exception, e:
74 if continue_on_error():
75 logger.error("Error '%s' but will proceed.", e)
76@@ -116,18 +109,27 @@
77 return bug
78
79
80-def set_bug_importance(bug, importance):
81- """Sets importance of all bug_tasks belonging to a bug."""
82- try:
83- for bug_task in bug.bug_tasks:
84- logger.debug("Setting importance %s for %s" % \
85- (importance, bug_task.title))
86- bug_task.importance = importance
87- bug_task.lp_save()
88- except:
89- if continue_on_error():
90- logger.error("Unable to set bug importance to '%s' but " \
91- "will proceed." % importance)
92+def set_bugtask_importance(bug_task, importance):
93+ """Sets importance of bug_task."""
94+ try:
95+ bug_task.importance = importance
96+ bug_task.lp_save()
97+ except:
98+ if continue_on_error():
99+ logger.error("Unable to set bug_task importance to '%s' but " \
100+ "will proceed." % importance)
101+ else:
102+ raise
103+
104+def set_bugtask_status(bug_task, status):
105+ """Sets importance of bug_task."""
106+ try:
107+ bug_task.status = status
108+ bug_task.lp_save()
109+ except:
110+ if continue_on_error():
111+ logger.error("Unable to set bug_task status to '%s' but " \
112+ "will proceed." % status)
113 else:
114 raise
115
116
117=== modified file 'tests/test_fail_filer.py'
118--- tests/test_fail_filer.py 2011-04-20 07:21:03 +0000
119+++ tests/test_fail_filer.py 2011-09-01 13:52:24 +0000
120@@ -40,7 +40,8 @@
121 import bug_reporting
122 from bug_reporting import (
123 bug_already_filed_by_url,
124- set_bug_importance,
125+ set_bugtask_importance,
126+ set_bugtask_status,
127 set_bugtask_milestone,
128 close_bug,
129 file_bug_by_url,
130@@ -584,6 +585,10 @@
131 def add_bug_task(self, bug_task):
132 self.bug_tasks.append(bug_task)
133
134+ def addNomination(self, target=None):
135+ assert self.bug_tasks[0].milestone is not None, (
136+ "Must set milestone before nominating series.")
137+
138 class MockTarget:
139 class MockSeries:
140 def __init__(self):
141@@ -599,7 +604,7 @@
142 def getMilestone(self, name):
143 return TestFileBug.MockMilestone(name)
144
145- def getSeries(self, name):
146+ def getSeries(self, name_or_version=None):
147 return self.MockSeries()
148
149 class MockBugTask:
150@@ -611,6 +616,7 @@
151 self.target = TestFileBug.MockTarget()
152 self.title = ''
153 self.status = ''
154+ self.milestone = None
155
156 def lp_save(self):
157 if self.will_fail_on_save:
158@@ -633,21 +639,20 @@
159
160 def test_close_bug_if_setting_importance_fails(self):
161
162- def raise_func(bug, importance):
163- self.saved_bug = bug
164+ def raise_func(bugtask, importance):
165+ self.saved_bugtask = bugtask
166 raise self.TestFailError('Setting importance failed.')
167
168 self.useFixture(MockSomethingFixture(
169- bug_reporting, 'set_bug_importance', raise_func))
170+ bug_reporting, 'set_bugtask_importance', raise_func))
171 try:
172- self.saved_bug = None
173+ self.saved_bugtask = None
174 bug = file_bug_by_url('http://dummy', 'description', 'title', [],
175 self.MockLaunchpad([]), importance='Low')
176 self.fail('Error in test case, file_bug_by_url should have '\
177 'raised an error.')
178 except self.TestFailError:
179- for bug_task in self.saved_bug.bug_tasks:
180- self.assertEquals(BUG_INVALID_STATUS, bug_task.status)
181+ self.assertEquals(BUG_INVALID_STATUS, self.saved_bugtask.status)
182
183 def test_close_bug_if_setting_milestone_fails(self):
184
185@@ -675,21 +680,29 @@
186 def test_set_importance_saves(self):
187 bug = self.MockBug()
188 bug_task = self.MockBugTask(False)
189- bug.add_bug_task(bug_task)
190- set_bug_importance(bug, 'High')
191+ set_bugtask_importance(bug_task, 'High')
192 self.assertEquals(True, bug_task.has_saved)
193
194 def test_set_importance_can_ignore_errors(self):
195 set_ignore_errors(True)
196+ bugtask = self.MockBugTask(True)
197+ set_bugtask_importance(bugtask, 'High')
198+
199+ def test_set_status_saves(self):
200 bug = self.MockBug()
201- bug.add_bug_task(self.MockBugTask(True))
202- set_bug_importance(bug, 'High')
203+ bug_task = self.MockBugTask(False)
204+ set_bugtask_status(bug_task, 'Confirmed')
205+ self.assertEquals(True, bug_task.has_saved)
206+
207+ def test_set_status_can_ignore_errors(self):
208+ set_ignore_errors(True)
209+ bugtask = self.MockBugTask(True)
210+ set_bugtask_status(bugtask, 'Confirmed')
211
212 def test_set_importance_raises(self):
213 set_ignore_errors(False)
214- bug = self.MockBug()
215- bug.add_bug_task(self.MockBugTask(True))
216- self.assertRaises(Exception, set_bug_importance, bug, 'High')
217+ bugtask = self.MockBugTask(True)
218+ self.assertRaises(Exception, set_bugtask_importance, bugtask, 'High')
219
220 def test_set_milestone_saves(self):
221 bug_task = self.MockBugTask(False)
222@@ -716,6 +729,12 @@
223 bug_task = self.MockBugTask(True)
224 self.assertRaises(Exception, set_bugtask_milestone, bug_task, None)
225
226+ def test_set_milestone_before_series(self):
227+ failure = self.assertRaises(AttributeError, file_bug_by_url,
228+ 'http://dummy', 'description', 'title', [],
229+ self.MockLaunchpad([]), milestone_name='ms',
230+ series_name='series')
231+ self.assertEqual(str(failure), 'Unable to approve nomination None.')
232
233 class TestConfigInit(TestCaseWithFixtures):
234

Subscribers

People subscribed via source and target branches