1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
package lpad_test
import (
. "launchpad.net/gocheck"
"launchpad.net/lpad"
"net/http"
)
var _ = Suite(&SessionS{})
var _ = Suite(&SessionI{})
type SessionS struct {
HTTPSuite
}
type SessionI struct {
SuiteI
}
type dummyAuth struct {
loginBaseURL string
loginErr error
signReq *http.Request
signErr error
}
func (a *dummyAuth) Login(baseURL string) error {
a.loginBaseURL = baseURL
return a.loginErr
}
func (a *dummyAuth) Sign(r *http.Request) error {
a.signReq = r
return a.signErr
}
func (s *SessionS) TestLogin(c *C) {
testServer.PrepareResponse(200, jsonType, `{"ok": true}`)
auth := &dummyAuth{}
root, err := lpad.Login(lpad.APIBase(testServer.URL), auth)
c.Assert(err, IsNil)
c.Assert(auth.loginBaseURL, Equals, testServer.URL)
c.Assert(root.BaseLoc(), Equals, testServer.URL)
c.Assert(root.AbsLoc(), Equals, testServer.URL)
c.Assert(len(root.Map()), Equals, 0)
_, err = root.Get(nil)
c.Assert(err, IsNil)
c.Assert(root.Map()["ok"], Equals, true)
c.Assert(auth.signReq, NotNil)
c.Assert(auth.signReq.URL.String(), Equals, testServer.URL)
req := testServer.WaitRequest()
c.Assert(req.Method, Equals, "GET")
c.Assert(req.URL.Path, Equals, "/")
}
var lpadAuth = &lpad.OAuth{
Token: "SfVJpl7pJgSLJX9cm0wj",
TokenSecret: "CXJGg1t5gTdjDqtFG0HNBFQn8WLWq8QQ3B2sHh9NmgLxQ6kGl9m123gQLZpDF8HFxQzk8HV78c9sGHQb",
}
func (s *SessionI) TestLogin(c *C) {
root, err := lpad.Login(lpad.Production, lpadAuth)
me, err := root.Me()
c.Assert(err, IsNil)
c.Assert(me.DisplayName(), Equals, "Lpad Test User")
}
|