mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-28 20:56:11 +01:00
[TESTS] createUser via the user model helper for integration tests (squash)
(cherry picked from commit 6ff2383952
)
This commit is contained in:
parent
2b988e5415
commit
de2a6fe8c3
|
@ -23,6 +23,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/auth"
|
"code.gitea.io/gitea/models/auth"
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
gitea_context "code.gitea.io/gitea/modules/context"
|
gitea_context "code.gitea.io/gitea/modules/context"
|
||||||
|
@ -241,18 +242,19 @@ func getUserToken(t testing.TB, userName string, scope ...auth.AccessTokenScope)
|
||||||
return getTokenForLoggedInUser(t, loginUser(t, userName), scope...)
|
return getTokenForLoggedInUser(t, loginUser(t, userName), scope...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createUser(t testing.TB, userName, email, password string) func() {
|
func createUser(ctx context.Context, t testing.TB, user *user_model.User) func() {
|
||||||
u := &user_model.User{
|
user.MustChangePassword = false
|
||||||
Name: userName,
|
user.LowerName = strings.ToLower(user.Name)
|
||||||
Email: email,
|
|
||||||
Passwd: password,
|
assert.NoError(t, db.Insert(ctx, user))
|
||||||
MustChangePassword: false,
|
|
||||||
LoginType: auth.Plain,
|
if len(user.Email) > 0 {
|
||||||
|
changePrimaryEmail := true
|
||||||
|
assert.NoError(t, user_model.UpdateUser(ctx, user, changePrimaryEmail))
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, user_model.CreateUser(u, &user_model.CreateUserOverwriteOptions{}))
|
|
||||||
return func() {
|
return func() {
|
||||||
assert.NoError(t, user_service.DeleteUser(context.Background(), u, true))
|
assert.NoError(t, user_service.DeleteUser(ctx, user, true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue