~ubuntu-branches/ubuntu/saucy/juju-core/saucy-proposed

« back to all changes in this revision

Viewing changes to src/launchpad.net/lpad/bug_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package lpad_test
 
2
 
 
3
import (
 
4
        . "launchpad.net/gocheck"
 
5
        "launchpad.net/lpad"
 
6
)
 
7
 
 
8
func (s *ModelS) TestBug(c *C) {
 
9
        m := M{
 
10
                "id":               123456.0,
 
11
                "title":            "Title",
 
12
                "description":      "Description",
 
13
                "tags":             []interface{}{"a", "b", "c"},
 
14
                "private":          true,
 
15
                "security_related": true,
 
16
                "web_link":         "http://page",
 
17
        }
 
18
        bug := &lpad.Bug{lpad.NewValue(nil, "", "", m)}
 
19
        c.Assert(bug.Id(), Equals, 123456)
 
20
        c.Assert(bug.Title(), Equals, "Title")
 
21
        c.Assert(bug.Description(), Equals, "Description")
 
22
        c.Assert(bug.Tags(), DeepEquals, []string{"a", "b", "c"})
 
23
        c.Assert(bug.Private(), Equals, true)
 
24
        c.Assert(bug.SecurityRelated(), Equals, true)
 
25
        c.Assert(bug.WebPage(), Equals, "http://page")
 
26
        bug.SetTitle("New title")
 
27
        bug.SetDescription("New description")
 
28
        bug.SetTags([]string{"new", "tags"})
 
29
        bug.SetPrivate(false)
 
30
        bug.SetSecurityRelated(false)
 
31
        c.Assert(bug.Title(), Equals, "New title")
 
32
        c.Assert(bug.Description(), Equals, "New description")
 
33
        c.Assert(bug.Tags(), DeepEquals, []string{"new", "tags"})
 
34
        c.Assert(bug.Private(), Equals, false)
 
35
        c.Assert(bug.SecurityRelated(), Equals, false)
 
36
}
 
37
 
 
38
func (s *ModelS) TestBugTask(c *C) {
 
39
        m := M{
 
40
                "assignee_link":  testServer.URL + "/assignee_link",
 
41
                "milestone_link": testServer.URL + "/milestone_link",
 
42
                "status":         "New",
 
43
                "importance":     "High",
 
44
        }
 
45
        task := &lpad.BugTask{lpad.NewValue(nil, "", "", m)}
 
46
 
 
47
        c.Assert(task.Status(), Equals, lpad.StNew)
 
48
        c.Assert(task.Importance(), Equals, lpad.ImHigh)
 
49
        task.SetStatus(lpad.StInProgress)
 
50
        task.SetImportance(lpad.ImCritical)
 
51
        c.Assert(task.Status(), Equals, lpad.StInProgress)
 
52
        c.Assert(task.Importance(), Equals, lpad.ImCritical)
 
53
 
 
54
        testServer.PrepareResponse(200, jsonType, `{"display_name": "Joe"}`)
 
55
        testServer.PrepareResponse(200, jsonType, `{"name": "mymiles"}`)
 
56
 
 
57
        assignee, err := task.Assignee()
 
58
        c.Assert(err, IsNil)
 
59
        c.Assert(assignee.DisplayName(), Equals, "Joe")
 
60
 
 
61
        milestone, err := task.Milestone()
 
62
        c.Assert(err, IsNil)
 
63
        c.Assert(milestone.Name(), Equals, "mymiles")
 
64
 
 
65
        req := testServer.WaitRequest()
 
66
        c.Assert(req.Method, Equals, "GET")
 
67
        c.Assert(req.URL.Path, Equals, "/assignee_link")
 
68
 
 
69
        req = testServer.WaitRequest()
 
70
        c.Assert(req.Method, Equals, "GET")
 
71
        c.Assert(req.URL.Path, Equals, "/milestone_link")
 
72
 
 
73
        milestone = &lpad.Milestone{lpad.NewValue(nil, "", "/new_milestone_link", nil)}
 
74
        assignee = &lpad.Person{lpad.NewValue(nil, "", "/new_assignee_link", nil)}
 
75
 
 
76
        task.SetMilestone(milestone)
 
77
        task.SetAssignee(assignee)
 
78
 
 
79
        c.Assert(task.StringField("milestone_link"), Equals, "/new_milestone_link")
 
80
        c.Assert(task.StringField("assignee_link"), Equals, "/new_assignee_link")
 
81
}
 
82
 
 
83
func (s *ModelS) TestRootBug(c *C) {
 
84
        data := `{
 
85
                "id": 123456,
 
86
                "title": "Title",
 
87
                "description": "Description",
 
88
                "private": true,
 
89
                "security_related": true,
 
90
                "tags": "a b c"
 
91
        }`
 
92
        testServer.PrepareResponse(200, jsonType, data)
 
93
        root := &lpad.Root{lpad.NewValue(nil, testServer.URL, "", nil)}
 
94
        bug, err := root.Bug(123456)
 
95
        c.Assert(err, IsNil)
 
96
        c.Assert(bug.Title(), Equals, "Title")
 
97
 
 
98
        req := testServer.WaitRequest()
 
99
        c.Assert(req.Method, Equals, "GET")
 
100
        c.Assert(req.URL.Path, Equals, "/bugs/123456")
 
101
}
 
102
 
 
103
func (s *ModelS) TestRootCreateBug(c *C) {
 
104
        data := `{
 
105
                "id": 123456,
 
106
                "title": "Title",
 
107
                "description": "Description",
 
108
                "private": true,
 
109
                "security_related": true,
 
110
                "tags": "a b c"
 
111
        }`
 
112
        testServer.PrepareResponse(200, jsonType, data)
 
113
        root := &lpad.Root{lpad.NewValue(nil, testServer.URL, "", nil)}
 
114
        stub := &lpad.BugStub{
 
115
                Title:           "Title",
 
116
                Description:     "Description.",
 
117
                Private:         true,
 
118
                SecurityRelated: true,
 
119
                Tags:            []string{"a", "b", "c"},
 
120
                Target:          lpad.NewValue(nil, "", "http://target", nil),
 
121
        }
 
122
        bug, err := root.CreateBug(stub)
 
123
        c.Assert(err, IsNil)
 
124
        c.Assert(bug.Title(), Equals, "Title")
 
125
 
 
126
        req := testServer.WaitRequest()
 
127
        c.Assert(req.Method, Equals, "POST")
 
128
        c.Assert(req.URL.Path, Equals, "/bugs")
 
129
        c.Assert(req.Form["ws.op"], DeepEquals, []string{"createBug"})
 
130
        c.Assert(req.Form["title"], DeepEquals, []string{"Title"})
 
131
        c.Assert(req.Form["description"], DeepEquals, []string{"Description."})
 
132
        c.Assert(req.Form["private"], DeepEquals, []string{"true"})
 
133
        c.Assert(req.Form["security_related"], DeepEquals, []string{"true"})
 
134
        c.Assert(req.Form["tags"], DeepEquals, []string{"a b c"})
 
135
        c.Assert(req.Form["target"], DeepEquals, []string{"http://target"})
 
136
}
 
137
 
 
138
func (s *ModelS) TestRootCreateBugNoTags(c *C) {
 
139
        // Launchpad blows up if an empty tags value is provided. :-(
 
140
        data := `{
 
141
                "id": 123456,
 
142
                "title": "Title"
 
143
        }`
 
144
        testServer.PrepareResponse(200, jsonType, data)
 
145
        root := &lpad.Root{lpad.NewValue(nil, testServer.URL, "", nil)}
 
146
        stub := &lpad.BugStub{
 
147
                Title:       "Title",
 
148
                Description: "Description.",
 
149
                Target:      lpad.NewValue(nil, "", "http://target", nil),
 
150
        }
 
151
        bug, err := root.CreateBug(stub)
 
152
        c.Assert(err, IsNil)
 
153
        c.Assert(bug.Title(), Equals, "Title")
 
154
 
 
155
        req := testServer.WaitRequest()
 
156
        c.Assert(req.Method, Equals, "POST")
 
157
        c.Assert(req.URL.Path, Equals, "/bugs")
 
158
        c.Assert(req.Form["ws.op"], DeepEquals, []string{"createBug"})
 
159
 
 
160
        _, ok := req.Form["tags"]
 
161
        c.Assert(ok, Equals, false)
 
162
}
 
163
 
 
164
func (s *ModelS) TestBugLinkBranch(c *C) {
 
165
        testServer.PrepareResponse(200, jsonType, `{}`)
 
166
        bug := &lpad.Bug{lpad.NewValue(nil, "", testServer.URL+"/bugs/123456", nil)}
 
167
        branch := &lpad.Branch{lpad.NewValue(nil, testServer.URL, testServer.URL+"~joe/ensemble/some-branch", nil)}
 
168
 
 
169
        err := bug.LinkBranch(branch)
 
170
        c.Assert(err, IsNil)
 
171
 
 
172
        req := testServer.WaitRequest()
 
173
        c.Assert(req.Method, Equals, "POST")
 
174
        c.Assert(req.URL.Path, Equals, "/bugs/123456")
 
175
        c.Assert(req.Form["ws.op"], DeepEquals, []string{"linkBranch"})
 
176
        c.Assert(req.Form["branch"], DeepEquals, []string{branch.AbsLoc()})
 
177
}
 
178
 
 
179
func (s *ModelS) TestBugTasks(c *C) {
 
180
        data := `{
 
181
                "total_size": 2,
 
182
                "start": 0,
 
183
                "entries": [{
 
184
                        "self_link": "http://self0",
 
185
                        "status": "New"
 
186
                }, {
 
187
                        "self_link": "http://self1",
 
188
                        "status": "Unknown"
 
189
                }]
 
190
        }`
 
191
        testServer.PrepareResponse(200, jsonType, data)
 
192
        m := M{"bug_tasks_collection_link": testServer.URL + "/col_link"}
 
193
        bug := &lpad.Bug{lpad.NewValue(nil, testServer.URL, "", m)}
 
194
        list, err := bug.Tasks()
 
195
        c.Assert(err, IsNil)
 
196
        c.Assert(list.TotalSize(), Equals, 2)
 
197
 
 
198
        status := []lpad.BugStatus{}
 
199
        list.For(func(task *lpad.BugTask) error {
 
200
                status = append(status, task.Status())
 
201
                return nil
 
202
        })
 
203
        c.Assert(status, DeepEquals, []lpad.BugStatus{lpad.StNew, lpad.StUnknown})
 
204
 
 
205
        req := testServer.WaitRequest()
 
206
        c.Assert(req.Method, Equals, "GET")
 
207
        c.Assert(req.URL.Path, Equals, "/col_link")
 
208
}