forked from clockworksoul/mediawiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotect_test.go
More file actions
53 lines (41 loc) · 1.28 KB
/
Copy pathprotect_test.go
File metadata and controls
53 lines (41 loc) · 1.28 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
package mediawiki
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestProtectStandard(t *testing.T) {
name := "Protection test standard"
ctx := context.Background()
c, err := New(apiUrl, agent)
require.NoError(t, err)
_, err = c.BotLogin(ctx, username, password)
require.NoError(t, err)
defer func() {
c.Debug = nil
_, err := c.Delete().Title(name).Do(context.Background())
assert.NoError(t, err)
}()
r, err := c.Edit().Title(name).Text("This is a test.").Summary("Automated test.").Do(ctx)
require.NoError(t, err)
assert.Nil(t, r.Error)
require.NotNil(t, r.Edit)
assert.Equal(t, Success, r.Edit.Result)
rp, err := c.Protect().Title(name).Protections("edit=sysop").Reason("This is a test.").Do(ctx)
require.NoError(t, err)
assert.Nil(t, rp.Error)
CompareJSON(t, rp.RawJSON, rp, false)
}
func TestProtectError(t *testing.T) {
ctx := context.Background()
c, err := New(apiUrl, agent)
require.NoError(t, err)
_, err = c.BotLogin(ctx, username, password)
require.NoError(t, err)
rp, err := c.Protect().Title("No such page").Protections("edit=sysop").Reason("This is a test.").Do(ctx)
require.Error(t, err)
assert.NotNil(t, rp.Error)
assert.Nil(t, rp.Protect)
CompareJSON(t, rp.RawJSON, rp, false)
}