From 3fcbb2043d04fb701a7baa26cc599c98dfaa5601 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Mon, 5 Jun 2023 11:43:31 +0200 Subject: [PATCH] [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) --- tests/integration/integration_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 8534b0393b..0706206ae1 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -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()