-
Notifications
You must be signed in to change notification settings - Fork 5
/
users_test.go
141 lines (112 loc) · 2.69 KB
/
users_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package redmine
import (
"testing"
)
var (
testUserLogin = "test-user-login"
testUserFirstName = "First"
testUserLastName = "Last"
testUserFirstName2 = "First2"
testUserLastName2 = "Last2"
testUserMail = "test@domain.com"
)
func TestUserCRUD(t *testing.T) {
var r Context
// Init Redmine context
initTest(&r, t)
// Create and delete
uCreated := testUserCreate(t, r)
defer testUserDetele(t, r, uCreated.ID)
// Get
testUserAllGet(t, r)
testUserSingleGet(t, r, uCreated.ID)
// Update
testUserUpdate(t, r, uCreated.ID)
// Current
testUserCurrentGet(t, r)
}
func testUserCreate(t *testing.T, r Context) UserObject {
u, _, err := r.UserCreate(
UserCreate{
User: UserCreateObject{
Login: testUserLogin,
FirstName: testUserFirstName,
LastName: testUserLastName,
Mail: testUserMail,
MailNotification: StringPtr(UserNotificationOnlyAssigned.String()),
MustChangePasswd: BoolPtr(true),
GeneratePassword: BoolPtr(true),
},
SendInformation: BoolPtr(true),
},
)
if err != nil {
t.Fatal("User create error:", err)
}
t.Logf("User create: success")
return u
}
func testUserUpdate(t *testing.T, r Context, id int64) {
_, err := r.UserUpdate(
id,
UserUpdate{
User: UserUpdateObject{
FirstName: &testUserFirstName2,
LastName: &testUserLastName2,
MailNotification: StringPtr(UserNotificationOnlyNone.String()),
},
SendInformation: BoolPtr(true),
},
)
if err != nil {
t.Fatal("User update error:", err)
}
t.Logf("User update: success")
}
func testUserDetele(t *testing.T, r Context, id int64) {
_, err := r.UserDelete(id)
if err != nil {
t.Fatal("User delete error:", err)
}
t.Logf("User delete: success")
}
func testUserAllGet(t *testing.T, r Context) {
u, _, err := r.UserAllGet(UserAllGetRequest{
Filters: UserGetRequestFiltersInit().
StatusSet(UserStatusActive),
})
if err != nil {
t.Fatal("Users get error:", err)
}
for _, e := range u.Users {
if e.Login == testUserLogin {
t.Logf("Users get: success")
return
}
}
t.Fatal("Users get error: can't find created user")
}
func testUserSingleGet(t *testing.T, r Context, id int64) {
_, _, err := r.UserSingleGet(id, UserSingleGetRequest{
Includes: []UserInclude{
UserIncludeGroups,
UserIncludeMemberships,
},
})
if err != nil {
t.Fatal("User get error:", err)
}
t.Logf("User get: success")
}
func testUserCurrentGet(t *testing.T, r Context) {
_, _, err := r.UserCurrentGet(UserCurrentGetRequest{
Includes: []UserInclude{
UserIncludeGroups,
UserIncludeMemberships,
},
})
if err != nil {
t.Fatal("Current user get error:", err)
}
t.Logf("Current user get: success")
}