mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 06:03:51 +03:00
[TESTS] createUser via the user model helper for integration tests
(cherry picked from commitc1d14c5fff
) (cherry picked from commite0e8aabc98
) (cherry picked from commit392a415070
) (cherry picked from commitc7cf1307ca
) (cherry picked from commit93b13d092b
) [TESTS] createUser via the user model helper for integration tests (squash) (cherry picked from commit6ff2383952
) (cherry picked from commitde2a6fe8c3
) (cherry picked from commit398a6ab072
) (cherry picked from commit16abc89780
) (cherry picked from commit312a3ec5d9
) (cherry picked from commit85c6d8e290
) (cherry picked from commit79150d30a4
) (cherry picked from commit436137962d
) (cherry picked from commite4eb8d471e
) (cherry picked from commita7257052f4
)
This commit is contained in:
parent
c43ca210fc
commit
d5eba9a6dd
1 changed files with 19 additions and 0 deletions
|
@ -23,7 +23,9 @@ import (
|
|||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"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 +35,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"
|
||||
|
@ -228,6 +231,22 @@ func getUserToken(t testing.TB, userName string, scope ...auth.AccessTokenScope)
|
|||
return getTokenForLoggedInUser(t, loginUser(t, userName), scope...)
|
||||
}
|
||||
|
||||
func createUser(ctx context.Context, t testing.TB, user *user_model.User) func() {
|
||||
user.MustChangePassword = false
|
||||
user.LowerName = strings.ToLower(user.Name)
|
||||
|
||||
assert.NoError(t, db.Insert(ctx, user))
|
||||
|
||||
if len(user.Email) > 0 {
|
||||
changePrimaryEmail := true
|
||||
assert.NoError(t, user_model.UpdateUser(ctx, user, changePrimaryEmail))
|
||||
}
|
||||
|
||||
return func() {
|
||||
assert.NoError(t, user_service.DeleteUser(ctx, user, true))
|
||||
}
|
||||
}
|
||||
|
||||
func loginUser(t testing.TB, userName string) *TestSession {
|
||||
t.Helper()
|
||||
|
||||
|
|
Loading…
Reference in a new issue