Merge lp:~jani/lpad/misc into lp:lpad

Proposed by Jani Monoses
Status: Needs review
Proposed branch: lp:~jani/lpad/misc
Merge into: lp:lpad
Diff against target: 329 lines (+200/-54)
4 files modified
bug.go (+19/-0)
bug_test.go (+25/-0)
distro.go (+54/-54)
distro_test.go (+102/-0)
To merge this branch: bzr merge lp:~jani/lpad/misc
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Pending
Review via email: mp+90773@code.launchpad.net

Description of the change

Reenable functions, add corresponding tests. Add commenting for Bug, link Bug

to Bugtask

https://codereview.appspot.com/5552049/

To post a comment you must log in.
Revision history for this message
Jani Monoses (jani) wrote :

Reviewers: mp+90773_code.launchpad.net,

Message:
Please take a look.

Description:
to Bugtask

https://code.launchpad.net/~jani/lpad/misc/+merge/90773

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/5552049/

Affected files:
   M bug.go
   M bug_test.go
   M distro.go
   M distro_test.go

Unmerged revisions

57. By Jani Monoses

Get bugtask list and build list for distros and distroseries

56. By Jani Monoses

Support for adding comments to bugs and getting bug of bugtask

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bug.go'
2--- bug.go 2011-11-17 05:56:25 +0000
3+++ bug.go 2012-01-30 19:45:39 +0000
4@@ -130,6 +130,16 @@
5 return err
6 }
7
8+// AddComment adds a comment to this bug.
9+func (bug *Bug) AddComment(comment string) error {
10+ params := Params{
11+ "ws.op": "newMessage",
12+ "content": comment,
13+ }
14+ _, err := bug.Post(params)
15+ return err
16+}
17+
18 // A BugTask represents the association of a bug with a project
19 // or source package, and the related information.
20 type BugTask struct {
21@@ -165,6 +175,15 @@
22 StFixReleased BugStatus = "Fix Released"
23 )
24
25+// Bug returns the bug this task is associated with.
26+func (task *BugTask) Bug() (*Bug, error) {
27+ v, err := task.Link("bug_link").Get(nil)
28+ if err != nil {
29+ return nil, err
30+ }
31+ return &Bug{v}, nil
32+}
33+
34 // Status returns the current status for the bug task. See
35 // the Status type for supported values.
36 func (task *BugTask) Status() BugStatus {
37
38=== modified file 'bug_test.go'
39--- bug_test.go 2011-11-17 14:56:24 +0000
40+++ bug_test.go 2012-01-30 19:45:39 +0000
41@@ -39,6 +39,7 @@
42 m := M{
43 "assignee_link": testServer.URL + "/assignee_link",
44 "milestone_link": testServer.URL + "/milestone_link",
45+ "bug_link": testServer.URL + "/bug_link",
46 "status": "New",
47 "importance": "High",
48 }
49@@ -53,6 +54,7 @@
50
51 testServer.PrepareResponse(200, jsonType, `{"display_name": "Joe"}`)
52 testServer.PrepareResponse(200, jsonType, `{"name": "mymiles"}`)
53+ testServer.PrepareResponse(200, jsonType, `{"title": "Bugtitle"}`)
54
55 assignee, err := task.Assignee()
56 c.Assert(err, IsNil)
57@@ -62,6 +64,10 @@
58 c.Assert(err, IsNil)
59 c.Assert(milestone.Name(), Equals, "mymiles")
60
61+ bug, err := task.Bug()
62+ c.Assert(err, IsNil)
63+ c.Assert(bug.Title(), Equals, "Bugtitle")
64+
65 req := testServer.WaitRequest()
66 c.Assert(req.Method, Equals, "GET")
67 c.Assert(req.URL.Path, Equals, "/assignee_link")
68@@ -70,6 +76,10 @@
69 c.Assert(req.Method, Equals, "GET")
70 c.Assert(req.URL.Path, Equals, "/milestone_link")
71
72+ req = testServer.WaitRequest()
73+ c.Assert(req.Method, Equals, "GET")
74+ c.Assert(req.URL.Path, Equals, "/bug_link")
75+
76 milestone = &lpad.Milestone{lpad.NewValue(nil, "", "/new_milestone_link", nil)}
77 assignee = &lpad.Person{lpad.NewValue(nil, "", "/new_assignee_link", nil)}
78
79@@ -176,6 +186,21 @@
80 c.Assert(req.Form["branch"], Equals, []string{branch.AbsLoc()})
81 }
82
83+func (s *ModelS) TestBugAddComment(c *C) {
84+ testServer.PrepareResponse(200, jsonType, `{}`)
85+ bug := &lpad.Bug{lpad.NewValue(nil, "", testServer.URL+"/bugs/123456", nil)}
86+
87+ comment := "Me too!"
88+ err := bug.AddComment(comment)
89+ c.Assert(err, IsNil)
90+
91+ req := testServer.WaitRequest()
92+ c.Assert(req.Method, Equals, "POST")
93+ c.Assert(req.URL.Path, Equals, "/bugs/123456")
94+ c.Assert(req.Form["ws.op"], Equals, []string{"newMessage"})
95+ c.Assert(req.Form["content"], Equals, []string{comment})
96+}
97+
98 func (s *ModelS) TestBugTasks(c *C) {
99 data := `{
100 "total_size": 2,
101
102=== modified file 'distro.go'
103--- distro.go 2012-01-17 02:09:33 +0000
104+++ distro.go 2012-01-30 19:45:39 +0000
105@@ -269,60 +269,60 @@
106
107 // TODO: These have no tests.
108 //
109-//type TagMatching string
110-//
111-//const (
112-// MatchAny TagMatching = "Any"
113-// MatchAll TagMatching = "All"
114-//)
115-//
116-//// SearchTasks returns the list of bug tasks associated with this
117-//// distribution that match the given criteria.
118-//func (d *Distro) SearchTasks(tags string, matching TagMatching) (*BugTaskList, error) {
119-// params := Params{
120-// "ws.op": "searchTasks",
121-// "tags": tags,
122-// "tags_combinator": string(matching),
123-// }
124-// v, err := d.Location("").Get(params)
125-// if err != nil {
126-// return nil, err
127-// }
128-// return &BugTaskList{v}, nil
129-//}
130-//
131-//// SearchTasks returns the list of bug tasks associated with this
132-//// distribution series that match the given criteria.
133-//func (d *DistroSeries) SearchTasks(tags string, matching TagMatching) (*BugTaskList, error) {
134-// params := Params{
135-// "ws.op": "searchTasks",
136-// "tags": tags,
137-// "tags_combinator": string(match),
138-// }
139-// v, err := d.Location("").Get(params)
140-// if err != nil {
141-// return nil, err
142-// }
143-// return &BugTaskList{v}, nil
144-//}
145-//
146-//// Builds returns a list of all the Build objects for this distribution
147-//// series for the source packages matching the given criteria.
148-//func (d *DistroSeries) Builds(buildState BuildState, pocket Pocket, sourceName string) (*BuildList, error) {
149-// params := Params{
150-// "ws.op": "getBuildRecords",
151-// "build_state": string(buildState),
152-// "source_name": sourceName,
153-// }
154-// if pocket != PocketAny {
155-// params["pocket"] = string(pocket)
156-// }
157-// v, err := d.Location("").Get(params)
158-// if err != nil {
159-// return nil, err
160-// }
161-// return &BuildList{v}, nil
162-//}
163+type TagMatching string
164+
165+const (
166+ MatchAny TagMatching = "Any"
167+ MatchAll TagMatching = "All"
168+)
169+
170+// SearchTasks returns the list of bug tasks associated with this
171+// distribution that match the given criteria.
172+func (d *Distro) SearchTasks(tags string, matching TagMatching) (*BugTaskList, error) {
173+ params := Params{
174+ "ws.op": "searchTasks",
175+ "tags": tags,
176+ "tags_combinator": string(matching),
177+ }
178+ v, err := d.Location("").Get(params)
179+ if err != nil {
180+ return nil, err
181+ }
182+ return &BugTaskList{v}, nil
183+}
184+
185+// SearchTasks returns the list of bug tasks associated with this
186+// distribution series that match the given criteria.
187+func (d *DistroSeries) SearchTasks(tags string, matching TagMatching) (*BugTaskList, error) {
188+ params := Params{
189+ "ws.op": "searchTasks",
190+ "tags": tags,
191+ "tags_combinator": string(matching),
192+ }
193+ v, err := d.Location("").Get(params)
194+ if err != nil {
195+ return nil, err
196+ }
197+ return &BugTaskList{v}, nil
198+}
199+
200+// Builds returns a list of all the Build objects for this distribution
201+// series for the source packages matching the given criteria.
202+func (d *DistroSeries) Builds(buildState BuildState, pocket Pocket, sourceName string) (*BuildList, error) {
203+ params := Params{
204+ "ws.op": "getBuildRecords",
205+ "build_state": string(buildState),
206+ "source_name": sourceName,
207+ }
208+ if pocket != PocketAny {
209+ params["pocket"] = string(pocket)
210+ }
211+ v, err := d.Location("").Get(params)
212+ if err != nil {
213+ return nil, err
214+ }
215+ return &BuildList{v}, nil
216+}
217
218 // DistroSourcePackage returns the DistroSourcePackage with the given name.
219 func (d *Distro) DistroSourcePackage(name string) (*DistroSourcePackage, error) {
220
221=== modified file 'distro_test.go'
222--- distro_test.go 2012-01-17 02:09:33 +0000
223+++ distro_test.go 2012-01-30 19:45:39 +0000
224@@ -191,3 +191,105 @@
225 c.Assert(req.Form["ws.op"], Equals, []string{"getBranchTips"})
226 c.Assert(req.Form["since"], Equals, []string{"2011-09-21T01:16:26Z"})
227 }
228+
229+func (s *ModelS) TestDistroSearchTasks(c *C) {
230+ data := `{
231+ "total_size": 2,
232+ "start": 0,
233+ "entries": [{
234+ "self_link": "http://self0",
235+ "status": "New"
236+ }, {
237+ "self_link": "http://self1",
238+ "status": "Unknown"
239+ }]
240+ }`
241+
242+ testServer.PrepareResponse(200, jsonType, data)
243+ distro := lpad.Distro{lpad.NewValue(nil, testServer.URL, testServer.URL+"/distro", nil)}
244+ tasks, err := distro.SearchTasks("ftbfs", lpad.MatchAny)
245+ c.Assert(err, IsNil)
246+ c.Assert(tasks.TotalSize(), Equals, 2)
247+
248+ status := []lpad.BugStatus{}
249+ tasks.For(func(task *lpad.BugTask) error {
250+ status = append(status, task.Status())
251+ return nil
252+ })
253+ c.Assert(status, Equals, []lpad.BugStatus{lpad.StNew, lpad.StUnknown})
254+
255+ req := testServer.WaitRequest()
256+ c.Assert(req.Method, Equals, "GET")
257+ c.Assert(req.URL.Path, Equals, "/distro")
258+ c.Assert(req.Form["ws.op"], Equals, []string{"searchTasks"})
259+ c.Assert(req.Form["tags"], Equals, []string{"ftbfs"})
260+ c.Assert(req.Form["tags_combinator"], Equals, []string{"Any"})
261+}
262+
263+func (s *ModelS) TestDistroSeriesSearchTasks(c *C) {
264+ data := `{
265+ "total_size": 2,
266+ "start": 0,
267+ "entries": [{
268+ "self_link": "http://self0",
269+ "status": "New"
270+ }, {
271+ "self_link": "http://self1",
272+ "status": "Unknown"
273+ }]
274+ }`
275+
276+ testServer.PrepareResponse(200, jsonType, data)
277+ distroseries := lpad.DistroSeries{lpad.NewValue(nil, testServer.URL, testServer.URL+"/distroseries", nil)}
278+ tasks, err := distroseries.SearchTasks("ftbfs", lpad.MatchAny)
279+ c.Assert(err, IsNil)
280+ c.Assert(tasks.TotalSize(), Equals, 2)
281+
282+ status := []lpad.BugStatus{}
283+ tasks.For(func(task *lpad.BugTask) error {
284+ status = append(status, task.Status())
285+ return nil
286+ })
287+ c.Assert(status, Equals, []lpad.BugStatus{lpad.StNew, lpad.StUnknown})
288+
289+ req := testServer.WaitRequest()
290+ c.Assert(req.Method, Equals, "GET")
291+ c.Assert(req.URL.Path, Equals, "/distroseries")
292+ c.Assert(req.Form["ws.op"], Equals, []string{"searchTasks"})
293+ c.Assert(req.Form["tags"], Equals, []string{"ftbfs"})
294+ c.Assert(req.Form["tags_combinator"], Equals, []string{"Any"})
295+}
296+
297+func (s *ModelS) TestDistroSeriesBuilds(c *C) {
298+ data := `{
299+ "total_size": 2,
300+ "start": 0,
301+ "entries": [{
302+ "self_link": "http://self0",
303+ "buildstate": "Failed to build"
304+ }, {
305+ "self_link": "http://self1",
306+ "buildstate": "Failed to build"
307+ }]
308+ }`
309+
310+ testServer.PrepareResponse(200, jsonType, data)
311+ distroseries := lpad.DistroSeries{lpad.NewValue(nil, testServer.URL, testServer.URL+"/distroseries", nil)}
312+ builds, err := distroseries.Builds(lpad.BSFailedToBuild, lpad.PocketRelease, "woobar")
313+ c.Assert(err, IsNil)
314+ c.Assert(builds.TotalSize(), Equals, 2)
315+
316+ states := []lpad.BuildState{}
317+ builds.For(func(build *lpad.Build) error {
318+ states = append(states, build.State())
319+ return nil
320+ })
321+ c.Assert(states, Equals, []lpad.BuildState{lpad.BSFailedToBuild, lpad.BSFailedToBuild})
322+
323+ req := testServer.WaitRequest()
324+ c.Assert(req.Method, Equals, "GET")
325+ c.Assert(req.URL.Path, Equals, "/distroseries")
326+ c.Assert(req.Form["ws.op"], Equals, []string{"getBuildRecords"})
327+ c.Assert(req.Form["build_state"], Equals, []string{"Failed to build"})
328+ c.Assert(req.Form["pocket"], Equals, []string{"Release"})
329+}

Subscribers

People subscribed via source and target branches