From d5eba9a6dd93eb21350dc611edff7c9a13cb2552 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) --- 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 76a65e3f03..8802f9c609 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()