-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot_test.go
70 lines (53 loc) · 1.3 KB
/
bot_test.go
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
package djangobot
import (
"testing"
)
func TestLogin(t *testing.T) {
// Before running this test, make sure to set your username and password below.
username := ""
password := ""
if username == "" && password == "" {
t.Log("Cannot execute test. Please supply username and password.")
return
}
// Disqus
bot := With("https://disqus.com/profile/login/").
ForHost("disqus.com").
SetUsername(username).
SetPassword(password)
if bot.Error != nil {
panic(bot.Error)
}
_, err := bot.LoadCookies().
Set("next", "https://disqus.com/"). // Set the next parameter
X("csrfmiddlewaretoken", bot.Cookie("csrftoken").Value).
X("username", bot.Username).
X("password", bot.Password).
Login()
if err != nil {
panic(err)
}
sessionid := bot.Cookie("sessionid").Value
if sessionid == "" {
t.Error("Authentication failed.")
return
}
t.Log("Authenticated with session id: ", sessionid)
// Add details to the form data
data := map[string]string{}
//data := map[string]string{
// "email": "",
// "old_password": "",
// "password": "",
// "username": "",
//}
if len(data) == 0 {
t.Log("Cannot change password. Form data empty.")
return
}
_, body, _ := bot.Requester("PUT", "https://disqus.com/users/self/account/").
Client.
Send(data).
End()
t.Log(body)
}