forked from clockworksoul/mediawiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
75 lines (61 loc) · 1.46 KB
/
Copy pathclient_test.go
File metadata and controls
75 lines (61 loc) · 1.46 KB
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
72
73
74
75
package mediawiki
import (
"context"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const (
agent = "test-bot"
)
var (
apiUrl = os.Getenv("MEDIAWIKI_URL")
password = os.Getenv("MEDIAWIKI_PASSWORD")
username = os.Getenv("MEDIAWIKI_USERNAME")
)
func TestClientGetToken(t *testing.T) {
c, err := New(apiUrl, agent)
require.NoError(t, err)
token, err := c.GetToken(context.Background(), LoginToken)
require.NoError(t, err)
require.Greater(t, len(token), 0)
}
func TestClientBotLogin(t *testing.T) {
c, err := New(apiUrl, agent)
require.NoError(t, err)
r, err := c.BotLogin(context.Background(), username, password)
require.NoError(t, err)
require.NotNil(t, r.BotLogin)
assert.Equal(t, Success, r.BotLogin.Result)
}
func TestClientParseResponse(t *testing.T) {
mock := `{
"batchcomplete": "Foo!",
"warnings": {
"tokens": {
"*": "Warning!"
}
},
"query": {
"tokens": {
"logintoken": "!!TOKEN!!"
}
},
"error": {
"code": "anerror",
"info": "You got an error."
}
}`
r := Response{}
err := ParseResponse([]byte(mock), &r)
require.NoError(t, err)
assert.Equal(t, "Foo!", r.BatchComplete)
assert.NotNil(t, r.Warnings)
assert.Equal(t, "Warning!", r.Warnings.Tokens["*"])
assert.NotNil(t, r.Query)
assert.Equal(t, "!!TOKEN!!", r.Query.Tokens["logintoken"])
assert.NotNil(t, r.Error)
assert.Equal(t, "anerror", r.Error.Code)
assert.Equal(t, "You got an error.", r.Error.Info)
}