mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-01 06:48:56 +00:00
[TESTS] createUser via the user model helper for integration tests
(cherry picked from commitc1d14c5fff
) (cherry picked from commit6af2eb3660
) (cherry picked from commit293e880821
) (cherry picked from commit1fa64b155b
)
This commit is contained in:
parent
e1687f1e20
commit
040fe78727
1 changed files with 17 additions and 0 deletions
|
@ -24,6 +24,7 @@ import (
|
|||
|
||||
"code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
gitea_context "code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
|
@ -33,6 +34,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers"
|
||||
user_service "code.gitea.io/gitea/services/user"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
@ -239,6 +241,21 @@ func getUserToken(t testing.TB, userName string, scope ...auth.AccessTokenScope)
|
|||
return getTokenForLoggedInUser(t, loginUser(t, userName), scope...)
|
||||
}
|
||||
|
||||
func createUser(t testing.TB, userName, email, password string) func() {
|
||||
u := &user_model.User{
|
||||
Name: userName,
|
||||
Email: email,
|
||||
Passwd: password,
|
||||
MustChangePassword: false,
|
||||
LoginType: auth.Plain,
|
||||
}
|
||||
|
||||
assert.NoError(t, user_model.CreateUser(u, &user_model.CreateUserOverwriteOptions{}))
|
||||
return func() {
|
||||
assert.NoError(t, user_service.DeleteUser(context.Background(), u, true))
|
||||
}
|
||||
}
|
||||
|
||||
func loginUser(t testing.TB, userName string) *TestSession {
|
||||
t.Helper()
|
||||
|
||||
|
|
Loading…
Reference in a new issue