[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
)
This commit is contained in:
parent
be69999d30
commit
312a3ec5d9
1 changed files with 19 additions and 0 deletions
|
@ -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"
|
||||||
|
@ -239,6 +242,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()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue