mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-16 15:02:43 +00:00
Reduce usage of db.DefaultContext
(#27073)
Part of #27065 This reduces the usage of `db.DefaultContext`. I think I've got enough files for the first PR. When this is merged, I will continue working on this. Considering how many files this PR affect, I hope it won't take to long to merge, so I don't end up in the merge conflict hell. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
0de09d3afc
commit
76659b1114
83 changed files with 339 additions and 324 deletions
|
@ -63,7 +63,7 @@ func TestCanCreateOrganization(t *testing.T) {
|
|||
func TestSearchUsers(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
testSuccess := func(opts *user_model.SearchUserOptions, expectedUserOrOrgIDs []int64) {
|
||||
users, _, err := user_model.SearchUsers(opts)
|
||||
users, _, err := user_model.SearchUsers(db.DefaultContext, opts)
|
||||
assert.NoError(t, err)
|
||||
cassText := fmt.Sprintf("ids: %v, opts: %v", expectedUserOrOrgIDs, opts)
|
||||
if assert.Len(t, users, len(expectedUserOrOrgIDs), "case: %s", cassText) {
|
||||
|
@ -150,16 +150,16 @@ func TestEmailNotificationPreferences(t *testing.T) {
|
|||
assert.Equal(t, test.expected, user.EmailNotifications())
|
||||
|
||||
// Try all possible settings
|
||||
assert.NoError(t, user_model.SetEmailNotifications(user, user_model.EmailNotificationsEnabled))
|
||||
assert.NoError(t, user_model.SetEmailNotifications(db.DefaultContext, user, user_model.EmailNotificationsEnabled))
|
||||
assert.Equal(t, user_model.EmailNotificationsEnabled, user.EmailNotifications())
|
||||
|
||||
assert.NoError(t, user_model.SetEmailNotifications(user, user_model.EmailNotificationsOnMention))
|
||||
assert.NoError(t, user_model.SetEmailNotifications(db.DefaultContext, user, user_model.EmailNotificationsOnMention))
|
||||
assert.Equal(t, user_model.EmailNotificationsOnMention, user.EmailNotifications())
|
||||
|
||||
assert.NoError(t, user_model.SetEmailNotifications(user, user_model.EmailNotificationsDisabled))
|
||||
assert.NoError(t, user_model.SetEmailNotifications(db.DefaultContext, user, user_model.EmailNotificationsDisabled))
|
||||
assert.Equal(t, user_model.EmailNotificationsDisabled, user.EmailNotifications())
|
||||
|
||||
assert.NoError(t, user_model.SetEmailNotifications(user, user_model.EmailNotificationsAndYourOwn))
|
||||
assert.NoError(t, user_model.SetEmailNotifications(db.DefaultContext, user, user_model.EmailNotificationsAndYourOwn))
|
||||
assert.Equal(t, user_model.EmailNotificationsAndYourOwn, user.EmailNotifications())
|
||||
}
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ func TestCreateUserInvalidEmail(t *testing.T) {
|
|||
MustChangePassword: false,
|
||||
}
|
||||
|
||||
err := user_model.CreateUser(user)
|
||||
err := user_model.CreateUser(db.DefaultContext, user)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, user_model.IsErrEmailCharIsNotSupported(err))
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ func TestCreateUserEmailAlreadyUsed(t *testing.T) {
|
|||
user.Name = "testuser"
|
||||
user.LowerName = strings.ToLower(user.Name)
|
||||
user.ID = 0
|
||||
err := user_model.CreateUser(user)
|
||||
err := user_model.CreateUser(db.DefaultContext, user)
|
||||
assert.Error(t, err)
|
||||
assert.True(t, user_model.IsErrEmailAlreadyUsed(err))
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ func TestCreateUserCustomTimestamps(t *testing.T) {
|
|||
user.ID = 0
|
||||
user.Email = "unique@example.com"
|
||||
user.CreatedUnix = creationTimestamp
|
||||
err := user_model.CreateUser(user)
|
||||
err := user_model.CreateUser(db.DefaultContext, user)
|
||||
assert.NoError(t, err)
|
||||
|
||||
fetched, err := user_model.GetUserByID(context.Background(), user.ID)
|
||||
|
@ -295,7 +295,7 @@ func TestCreateUserWithoutCustomTimestamps(t *testing.T) {
|
|||
user.Email = "unique@example.com"
|
||||
user.CreatedUnix = 0
|
||||
user.UpdatedUnix = 0
|
||||
err := user_model.CreateUser(user)
|
||||
err := user_model.CreateUser(db.DefaultContext, user)
|
||||
assert.NoError(t, err)
|
||||
|
||||
timestampEnd := time.Now().Unix()
|
||||
|
@ -429,17 +429,17 @@ func TestNewUserRedirect3(t *testing.T) {
|
|||
func TestGetUserByOpenID(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
_, err := user_model.GetUserByOpenID("https://unknown")
|
||||
_, err := user_model.GetUserByOpenID(db.DefaultContext, "https://unknown")
|
||||
if assert.Error(t, err) {
|
||||
assert.True(t, user_model.IsErrUserNotExist(err))
|
||||
}
|
||||
|
||||
user, err := user_model.GetUserByOpenID("https://user1.domain1.tld")
|
||||
user, err := user_model.GetUserByOpenID(db.DefaultContext, "https://user1.domain1.tld")
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, int64(1), user.ID)
|
||||
}
|
||||
|
||||
user, err = user_model.GetUserByOpenID("https://domain1.tld/user2/")
|
||||
user, err = user_model.GetUserByOpenID(db.DefaultContext, "https://domain1.tld/user2/")
|
||||
if assert.NoError(t, err) {
|
||||
assert.Equal(t, int64(2), user.ID)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue