mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 05:15:33 +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
) (cherry picked from commitd5eba9a6dd
) (cherry picked from commitd89ef2ffa9
) (cherry picked from commitf1d25aa307
) (cherry picked from commit60c7c07353
) (cherry picked from commitcfeff3afdb
) (cherry picked from commit608ac6bd68
) (cherry picked from commitc64e530a13
) (cherry picked from commit513db02971
) (cherry picked from commit43eaaa5a61
) (cherry picked from commit678eb49440
) (cherry picked from commitf7458dabda
) (cherry picked from commit32568e43b4
) (cherry picked from commit3fcbb2043d
) (cherry picked from commit95f0b8eefa
) (cherry picked from commitf285b9469d
) (cherry picked from commit4b8a02ad08
) (cherry picked from commit70eb98025b
) (cherry picked from commitdc2d448705
) (cherry picked from commite1402ca319
)
This commit is contained in:
parent
bce1ab85f7
commit
807d587285
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"
|
||||
|
@ -231,6 +234,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