[TESTS] createUser via the user model helper for integration tests

(cherry picked from commit c1d14c5fffeb823385b2984cfcdb3e195bfb151d)
(cherry picked from commit e0e8aabc985af153cf1fcb2064c17f68ec37f3a2)
(cherry picked from commit 392a415070af7f4e872c7bb013f259e2dcc8b7b4)
(cherry picked from commit c7cf1307ca227ff9f4935391582c058823419d7b)
(cherry picked from commit 93b13d092b46c261fc3c0f70ecd9d4f45ee84029)

[TESTS] createUser via the user model helper for integration tests (squash)

(cherry picked from commit 6ff23839528db66ae91e88d6b687b63c769f8f43)
(cherry picked from commit de2a6fe8c374965d50bcd6421d44c3a5d312a689)
(cherry picked from commit 398a6ab072e8364db3c5236bf258ec6bb068dc29)
(cherry picked from commit 16abc89780a228fdc288ed2ce44a95daa6368e36)
(cherry picked from commit 312a3ec5d9d50864af9dbfb8672778789b2e11ca)
(cherry picked from commit 85c6d8e29065641ccbaf57fcebe72b93141a14a4)
(cherry picked from commit 79150d30a4d9a91e9e5272f3d46bd0ee836bcab1)
(cherry picked from commit 436137962d3f150d4c28093461c30c9910f2d32d)
(cherry picked from commit e4eb8d471e8e1c8e14a6a3208418bde0b121472c)
(cherry picked from commit a7257052f49a480dd2ccfbef5c0573c9b5b73adb)
(cherry picked from commit d5eba9a6dd93eb21350dc611edff7c9a13cb2552)
(cherry picked from commit d89ef2ffa9a83249b498867a02996a3dcb17aa31)
(cherry picked from commit f1d25aa30762ae97d7994048dd03c656028dedbe)
(cherry picked from commit 60c7c0735376d7987717c0d375fa409ca9b90e8f)
(cherry picked from commit cfeff3afdb80785019f53312369953e2d996de89)
(cherry picked from commit 608ac6bd683d60fe295163ba5562aee5037b6e01)
(cherry picked from commit c64e530a13fe4afc89ad3de481fff16fe190c3d1)
(cherry picked from commit 513db02971fa98ff88f9b06bf25b03c31d0a857c)
(cherry picked from commit 43eaaa5a61134928ff9a83e571552407450d0a09)
(cherry picked from commit 678eb494408e3784336a3aeb5e5f54bd738d009e)
(cherry picked from commit f7458dabda74dedecb431a75e9f049e545fc973e)
(cherry picked from commit 32568e43b412bf53bc207f5b429ee4ef77693857)
(cherry picked from commit 3fcbb2043d04fb701a7baa26cc599c98dfaa5601)
(cherry picked from commit 95f0b8eefad590c647951f42bd0f467685901bd2)
(cherry picked from commit f285b9469d0b644abc70ebbc79c4b14fe5a03e56)
(cherry picked from commit 4b8a02ad088bc925dee1b2f0b759ea9ef77d96e8)
(cherry picked from commit 70eb98025b6012f42c0161999f7675f069bde877)
(cherry picked from commit dc2d448705404872c7f67887f7cf80658e42c3fa)
(cherry picked from commit e1402ca319f549f8ed36a9f8b58f7aba09793415)
(cherry picked from commit 807d587285c06b82d636fba371f946c68f0a22e3)
This commit is contained in:
Earl Warren 2023-06-05 11:43:31 +02:00
parent de51b21624
commit 34a5fe68a7
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -23,7 +23,9 @@ 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"
gitea_context "code.gitea.io/gitea/modules/context" gitea_context "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
@ -33,6 +35,7 @@ import (
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers" "code.gitea.io/gitea/routers"
user_service "code.gitea.io/gitea/services/user"
"code.gitea.io/gitea/tests" "code.gitea.io/gitea/tests"
"github.com/PuerkitoBio/goquery" "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...) 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 { func loginUser(t testing.TB, userName string) *TestSession {
t.Helper() t.Helper()