[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)
This commit is contained in:
		
							parent
							
								
									f9d054d17f
								
							
						
					
					
						commit
						398a6ab072
					
				
					 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"
 | 
			
		||||
| 
						 | 
				
			
			@ -239,6 +242,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…
	
	Add table
		Add a link
		
	
		Reference in a new issue