aboutsummaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-09-19 19:49:59 +0800
committerGitHub <noreply@github.com>2021-09-19 19:49:59 +0800
commita4bfef265d9e512830350635a0489c2cdcd6508f (patch)
tree1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /integrations
parent462306e263db5a809dbe2cdf62e99307aeff28de (diff)
downloadgitea-a4bfef265d9e512830350635a0489c2cdcd6508f.tar.gz
gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.zip
Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db * Fix lint * Fix lint * Fix test * Fix lint * Fix lint * revert unnecessary change * Fix test * Fix wrong replace string * Use *Context * Correct committer spelling and fix wrong replaced words Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'integrations')
-rw-r--r--integrations/admin_user_test.go3
-rw-r--r--integrations/api_admin_org_test.go3
-rw-r--r--integrations/api_admin_test.go15
-rw-r--r--integrations/api_comment_test.go69
-rw-r--r--integrations/api_issue_label_test.go45
-rw-r--r--integrations/api_issue_milestone_test.go7
-rw-r--r--integrations/api_issue_reaction_test.go15
-rw-r--r--integrations/api_issue_stopwatch_test.go27
-rw-r--r--integrations/api_issue_subscription_test.go19
-rw-r--r--integrations/api_issue_test.go27
-rw-r--r--integrations/api_issue_tracked_time_test.go19
-rw-r--r--integrations/api_keys_test.go17
-rw-r--r--integrations/api_notification_test.go9
-rw-r--r--integrations/api_oauth2_apps_test.go29
-rw-r--r--integrations/api_org_test.go3
-rw-r--r--integrations/api_pull_commits_test.go5
-rw-r--r--integrations/api_pull_review_test.go19
-rw-r--r--integrations/api_pull_test.go41
-rw-r--r--integrations/api_releases_test.go29
-rw-r--r--integrations/api_repo_edit_test.go29
-rw-r--r--integrations/api_repo_file_create_test.go21
-rw-r--r--integrations/api_repo_file_delete_test.go13
-rw-r--r--integrations/api_repo_file_update_test.go13
-rw-r--r--integrations/api_repo_get_contents_list_test.go15
-rw-r--r--integrations/api_repo_get_contents_test.go13
-rw-r--r--integrations/api_repo_git_blobs_test.go13
-rw-r--r--integrations/api_repo_git_commits_test.go9
-rw-r--r--integrations/api_repo_git_hook_test.go37
-rw-r--r--integrations/api_repo_git_notes_test.go3
-rw-r--r--integrations/api_repo_git_ref_test.go3
-rw-r--r--integrations/api_repo_git_tags_test.go9
-rw-r--r--integrations/api_repo_git_trees_test.go13
-rw-r--r--integrations/api_repo_lfs_locks_test.go17
-rw-r--r--integrations/api_repo_lfs_migrate_test.go3
-rw-r--r--integrations/api_repo_lfs_test.go9
-rw-r--r--integrations/api_repo_raw_test.go3
-rw-r--r--integrations/api_repo_tags_test.go3
-rw-r--r--integrations/api_repo_teams_test.go7
-rw-r--r--integrations/api_repo_test.go53
-rw-r--r--integrations/api_repo_topic_test.go11
-rw-r--r--integrations/api_team_test.go27
-rw-r--r--integrations/api_team_user_test.go3
-rw-r--r--integrations/api_token_test.go13
-rw-r--r--integrations/api_user_orgs_test.go5
-rw-r--r--integrations/api_user_search_test.go3
-rw-r--r--integrations/benchmarks_test.go3
-rw-r--r--integrations/change_default_branch_test.go5
-rw-r--r--integrations/delete_user_test.go21
-rw-r--r--integrations/empty_repo_test.go5
-rw-r--r--integrations/eventsource_test.go7
-rw-r--r--integrations/git_test.go15
-rw-r--r--integrations/gpg_git_test.go3
-rw-r--r--integrations/integration_test.go7
-rw-r--r--integrations/issue_test.go31
-rw-r--r--integrations/migrate_test.go5
-rw-r--r--integrations/migration-test/migration_test.go10
-rw-r--r--integrations/mirror_pull_test.go5
-rw-r--r--integrations/mirror_push_test.go5
-rw-r--r--integrations/org_count_test.go3
-rw-r--r--integrations/privateactivity_test.go5
-rw-r--r--integrations/pull_merge_test.go13
-rw-r--r--integrations/pull_update_test.go11
-rw-r--r--integrations/release_test.go7
-rw-r--r--integrations/repo_fork_test.go3
-rw-r--r--integrations/repo_generate_test.go3
-rw-r--r--integrations/repo_tag_test.go5
-rw-r--r--integrations/repo_watch_test.go5
-rw-r--r--integrations/repofiles_delete_test.go7
-rw-r--r--integrations/signin_test.go5
-rw-r--r--integrations/signup_test.go3
-rw-r--r--integrations/user_avatar_test.go5
-rw-r--r--integrations/user_test.go9
-rw-r--r--integrations/xss_test.go3
73 files changed, 515 insertions, 443 deletions
diff --git a/integrations/admin_user_test.go b/integrations/admin_user_test.go
index 96233436e8..3acf349041 100644
--- a/integrations/admin_user_test.go
+++ b/integrations/admin_user_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
@@ -60,7 +61,7 @@ func makeRequest(t *testing.T, formData models.User, headerCode int) {
})
session.MakeRequest(t, req, headerCode)
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: formData.ID}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: formData.ID}).(*models.User)
assert.Equal(t, formData.Name, user.Name)
assert.Equal(t, formData.LoginName, user.LoginName)
assert.Equal(t, formData.Email, user.Email)
diff --git a/integrations/api_admin_org_test.go b/integrations/api_admin_org_test.go
index b10f5607d3..7b149a38d5 100644
--- a/integrations/api_admin_org_test.go
+++ b/integrations/api_admin_org_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -42,7 +43,7 @@ func TestAPIAdminOrgCreate(t *testing.T) {
assert.Equal(t, org.Location, apiOrg.Location)
assert.Equal(t, org.Visibility, apiOrg.Visibility)
- models.AssertExistsAndLoadBean(t, &models.User{
+ db.AssertExistsAndLoadBean(t, &models.User{
Name: org.UserName,
LowerName: strings.ToLower(org.UserName),
FullName: org.FullName,
diff --git a/integrations/api_admin_test.go b/integrations/api_admin_test.go
index da6a89c974..ae3cc7dcfb 100644
--- a/integrations/api_admin_test.go
+++ b/integrations/api_admin_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs"
@@ -20,7 +21,7 @@ func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) {
defer prepareTestEnv(t)()
// user1 is an admin user
session := loginUser(t, "user1")
- keyOwner := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
+ keyOwner := db.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
token := getTokenForLoggedInUser(t, session)
urlStr := fmt.Sprintf("/api/v1/admin/users/%s/keys?token=%s", keyOwner.Name, token)
@@ -32,7 +33,7 @@ func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) {
var newPublicKey api.PublicKey
DecodeJSON(t, resp, &newPublicKey)
- models.AssertExistsAndLoadBean(t, &models.PublicKey{
+ db.AssertExistsAndLoadBean(t, &models.PublicKey{
ID: newPublicKey.ID,
Name: newPublicKey.Title,
Content: newPublicKey.Key,
@@ -43,7 +44,7 @@ func TestAPIAdminCreateAndDeleteSSHKey(t *testing.T) {
req = NewRequestf(t, "DELETE", "/api/v1/admin/users/%s/keys/%d?token=%s",
keyOwner.Name, newPublicKey.ID, token)
session.MakeRequest(t, req, http.StatusNoContent)
- models.AssertNotExistsBean(t, &models.PublicKey{ID: newPublicKey.ID})
+ db.AssertNotExistsBean(t, &models.PublicKey{ID: newPublicKey.ID})
}
func TestAPIAdminDeleteMissingSSHKey(t *testing.T) {
@@ -52,7 +53,7 @@ func TestAPIAdminDeleteMissingSSHKey(t *testing.T) {
session := loginUser(t, "user1")
token := getTokenForLoggedInUser(t, session)
- req := NewRequestf(t, "DELETE", "/api/v1/admin/users/user1/keys/%d?token=%s", models.NonexistentID, token)
+ req := NewRequestf(t, "DELETE", "/api/v1/admin/users/user1/keys/%d?token=%s", db.NonexistentID, token)
session.MakeRequest(t, req, http.StatusNotFound)
}
@@ -127,7 +128,7 @@ func TestAPIListUsers(t *testing.T) {
}
}
assert.True(t, found)
- numberOfUsers := models.GetCount(t, &models.User{}, "type = 0")
+ numberOfUsers := db.GetCount(t, &models.User{}, "type = 0")
assert.Equal(t, numberOfUsers, len(users))
}
@@ -193,7 +194,7 @@ func TestAPIEditUser(t *testing.T) {
json.Unmarshal(resp.Body.Bytes(), &errMap)
assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string))
- user2 := models.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User)
assert.False(t, user2.IsRestricted)
bTrue := true
req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
@@ -204,6 +205,6 @@ func TestAPIEditUser(t *testing.T) {
Restricted: &bTrue,
})
session.MakeRequest(t, req, http.StatusOK)
- user2 = models.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User)
+ user2 = db.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User)
assert.True(t, user2.IsRestricted)
}
diff --git a/integrations/api_comment_test.go b/integrations/api_comment_test.go
index f64f4a1c9c..a5513af6e3 100644
--- a/integrations/api_comment_test.go
+++ b/integrations/api_comment_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -20,11 +21,11 @@ import (
func TestAPIListRepoComments(t *testing.T) {
defer prepareTestEnv(t)()
- comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
- models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
- repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ comment := db.AssertExistsAndLoadBean(t, &models.Comment{},
+ db.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
+ repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, repoOwner.Name)
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments", repoOwner.Name, repo.Name))
@@ -36,9 +37,9 @@ func TestAPIListRepoComments(t *testing.T) {
assert.Len(t, apiComments, 2)
for _, apiComment := range apiComments {
c := &models.Comment{ID: apiComment.ID}
- models.AssertExistsAndLoadBean(t, c,
- models.Cond("type = ?", models.CommentTypeComment))
- models.AssertExistsAndLoadBean(t, &models.Issue{ID: c.IssueID, RepoID: repo.ID})
+ db.AssertExistsAndLoadBean(t, c,
+ db.Cond("type = ?", models.CommentTypeComment))
+ db.AssertExistsAndLoadBean(t, &models.Issue{ID: c.IssueID, RepoID: repo.ID})
}
//test before and since filters
@@ -66,11 +67,11 @@ func TestAPIListRepoComments(t *testing.T) {
func TestAPIListIssueComments(t *testing.T) {
defer prepareTestEnv(t)()
- comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
- models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
- repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ comment := db.AssertExistsAndLoadBean(t, &models.Comment{},
+ db.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
+ repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, repoOwner.Name)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/comments",
@@ -79,8 +80,8 @@ func TestAPIListIssueComments(t *testing.T) {
var comments []*api.Comment
DecodeJSON(t, resp, &comments)
- expectedCount := models.GetCount(t, &models.Comment{IssueID: issue.ID},
- models.Cond("type = ?", models.CommentTypeComment))
+ expectedCount := db.GetCount(t, &models.Comment{IssueID: issue.ID},
+ db.Cond("type = ?", models.CommentTypeComment))
assert.EqualValues(t, expectedCount, len(comments))
}
@@ -88,9 +89,9 @@ func TestAPICreateComment(t *testing.T) {
defer prepareTestEnv(t)()
const commentBody = "Comment body"
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{}).(*models.Issue)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
- repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{}).(*models.Issue)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
+ repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -104,16 +105,16 @@ func TestAPICreateComment(t *testing.T) {
var updatedComment api.Comment
DecodeJSON(t, resp, &updatedComment)
assert.EqualValues(t, commentBody, updatedComment.Body)
- models.AssertExistsAndLoadBean(t, &models.Comment{ID: updatedComment.ID, IssueID: issue.ID, Content: commentBody})
+ db.AssertExistsAndLoadBean(t, &models.Comment{ID: updatedComment.ID, IssueID: issue.ID, Content: commentBody})
}
func TestAPIGetComment(t *testing.T) {
defer prepareTestEnv(t)()
- comment := models.AssertExistsAndLoadBean(t, &models.Comment{ID: 2}).(*models.Comment)
+ comment := db.AssertExistsAndLoadBean(t, &models.Comment{ID: 2}).(*models.Comment)
assert.NoError(t, comment.LoadIssue())
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: comment.Issue.RepoID}).(*models.Repository)
- repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: comment.Issue.RepoID}).(*models.Repository)
+ repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -138,11 +139,11 @@ func TestAPIEditComment(t *testing.T) {
defer prepareTestEnv(t)()
const newCommentBody = "This is the new comment body"
- comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
- models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
- repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ comment := db.AssertExistsAndLoadBean(t, &models.Comment{},
+ db.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
+ repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -157,17 +158,17 @@ func TestAPIEditComment(t *testing.T) {
DecodeJSON(t, resp, &updatedComment)
assert.EqualValues(t, comment.ID, updatedComment.ID)
assert.EqualValues(t, newCommentBody, updatedComment.Body)
- models.AssertExistsAndLoadBean(t, &models.Comment{ID: comment.ID, IssueID: issue.ID, Content: newCommentBody})
+ db.AssertExistsAndLoadBean(t, &models.Comment{ID: comment.ID, IssueID: issue.ID, Content: newCommentBody})
}
func TestAPIDeleteComment(t *testing.T) {
defer prepareTestEnv(t)()
- comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
- models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
- repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ comment := db.AssertExistsAndLoadBean(t, &models.Comment{},
+ db.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
+ repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -175,5 +176,5 @@ func TestAPIDeleteComment(t *testing.T) {
repoOwner.Name, repo.Name, comment.ID, token)
session.MakeRequest(t, req, http.StatusNoContent)
- models.AssertNotExistsBean(t, &models.Comment{ID: comment.ID})
+ db.AssertNotExistsBean(t, &models.Comment{ID: comment.ID})
}
diff --git a/integrations/api_issue_label_test.go b/integrations/api_issue_label_test.go
index 64c3515dd2..4508069e17 100644
--- a/integrations/api_issue_label_test.go
+++ b/integrations/api_issue_label_test.go
@@ -11,16 +11,17 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
)
func TestAPIModifyLabels(t *testing.T) {
- assert.NoError(t, models.LoadFixtures())
+ assert.NoError(t, db.LoadFixtures())
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/labels?token=%s", owner.Name, repo.Name, token)
@@ -34,7 +35,7 @@ func TestAPIModifyLabels(t *testing.T) {
resp := session.MakeRequest(t, req, http.StatusCreated)
apiLabel := new(api.Label)
DecodeJSON(t, resp, &apiLabel)
- dbLabel := models.AssertExistsAndLoadBean(t, &models.Label{ID: apiLabel.ID, RepoID: repo.ID}).(*models.Label)
+ dbLabel := db.AssertExistsAndLoadBean(t, &models.Label{ID: apiLabel.ID, RepoID: repo.ID}).(*models.Label)
assert.EqualValues(t, dbLabel.Name, apiLabel.Name)
assert.EqualValues(t, strings.TrimLeft(dbLabel.Color, "#"), apiLabel.Color)
@@ -87,12 +88,12 @@ func TestAPIModifyLabels(t *testing.T) {
}
func TestAPIAddIssueLabels(t *testing.T) {
- assert.NoError(t, models.LoadFixtures())
+ assert.NoError(t, db.LoadFixtures())
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
- _ = models.AssertExistsAndLoadBean(t, &models.Label{RepoID: repo.ID, ID: 2}).(*models.Label)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
+ _ = db.AssertExistsAndLoadBean(t, &models.Label{RepoID: repo.ID, ID: 2}).(*models.Label)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -104,18 +105,18 @@ func TestAPIAddIssueLabels(t *testing.T) {
resp := session.MakeRequest(t, req, http.StatusOK)
var apiLabels []*api.Label
DecodeJSON(t, resp, &apiLabels)
- assert.Len(t, apiLabels, models.GetCount(t, &models.IssueLabel{IssueID: issue.ID}))
+ assert.Len(t, apiLabels, db.GetCount(t, &models.IssueLabel{IssueID: issue.ID}))
- models.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: issue.ID, LabelID: 2})
+ db.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: issue.ID, LabelID: 2})
}
func TestAPIReplaceIssueLabels(t *testing.T) {
- assert.NoError(t, models.LoadFixtures())
+ assert.NoError(t, db.LoadFixtures())
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
- label := models.AssertExistsAndLoadBean(t, &models.Label{RepoID: repo.ID}).(*models.Label)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
+ label := db.AssertExistsAndLoadBean(t, &models.Label{RepoID: repo.ID}).(*models.Label)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -131,15 +132,15 @@ func TestAPIReplaceIssueLabels(t *testing.T) {
assert.EqualValues(t, label.ID, apiLabels[0].ID)
}
- models.AssertCount(t, &models.IssueLabel{IssueID: issue.ID}, 1)
- models.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: issue.ID, LabelID: label.ID})
+ db.AssertCount(t, &models.IssueLabel{IssueID: issue.ID}, 1)
+ db.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: issue.ID, LabelID: label.ID})
}
func TestAPIModifyOrgLabels(t *testing.T) {
- assert.NoError(t, models.LoadFixtures())
+ assert.NoError(t, db.LoadFixtures())
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
user := "user1"
session := loginUser(t, user)
token := getTokenForLoggedInUser(t, session)
@@ -154,7 +155,7 @@ func TestAPIModifyOrgLabels(t *testing.T) {
resp := session.MakeRequest(t, req, http.StatusCreated)
apiLabel := new(api.Label)
DecodeJSON(t, resp, &apiLabel)
- dbLabel := models.AssertExistsAndLoadBean(t, &models.Label{ID: apiLabel.ID, OrgID: owner.ID}).(*models.Label)
+ dbLabel := db.AssertExistsAndLoadBean(t, &models.Label{ID: apiLabel.ID, OrgID: owner.ID}).(*models.Label)
assert.EqualValues(t, dbLabel.Name, apiLabel.Name)
assert.EqualValues(t, strings.TrimLeft(dbLabel.Color, "#"), apiLabel.Color)
diff --git a/integrations/api_issue_milestone_test.go b/integrations/api_issue_milestone_test.go
index b9942d9a3c..ba4ada1213 100644
--- a/integrations/api_issue_milestone_test.go
+++ b/integrations/api_issue_milestone_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -18,9 +19,9 @@ import (
func TestAPIIssuesMilestone(t *testing.T) {
defer prepareTestEnv(t)()
- milestone := models.AssertExistsAndLoadBean(t, &models.Milestone{ID: 1}).(*models.Milestone)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: milestone.RepoID}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ milestone := db.AssertExistsAndLoadBean(t, &models.Milestone{ID: 1}).(*models.Milestone)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: milestone.RepoID}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
assert.Equal(t, int64(1), int64(milestone.NumIssues))
assert.Equal(t, structs.StateOpen, milestone.State())
diff --git a/integrations/api_issue_reaction_test.go b/integrations/api_issue_reaction_test.go
index ad4adc1eae..d064f48854 100644
--- a/integrations/api_issue_reaction_test.go
+++ b/integrations/api_issue_reaction_test.go
@@ -11,6 +11,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -20,14 +21,14 @@ import (
func TestAPIIssuesReactions(t *testing.T) {
defer prepareTestEnv(t)()
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
_ = issue.LoadRepo()
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/reactions?token=%s",
owner.Name, issue.Repo.Name, issue.Index, token)
@@ -77,17 +78,17 @@ func TestAPIIssuesReactions(t *testing.T) {
func TestAPICommentReactions(t *testing.T) {
defer prepareTestEnv(t)()
- comment := models.AssertExistsAndLoadBean(t, &models.Comment{ID: 2}).(*models.Comment)
+ comment := db.AssertExistsAndLoadBean(t, &models.Comment{ID: 2}).(*models.Comment)
_ = comment.LoadIssue()
issue := comment.Issue
_ = issue.LoadRepo()
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
- user1 := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user1 := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d/reactions?token=%s",
owner.Name, issue.Repo.Name, comment.ID, token)
diff --git a/integrations/api_issue_stopwatch_test.go b/integrations/api_issue_stopwatch_test.go
index c0b8fd9c69..8ccd79f691 100644
--- a/integrations/api_issue_stopwatch_test.go
+++ b/integrations/api_issue_stopwatch_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -17,8 +18,8 @@ import (
func TestAPIListStopWatches(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -26,8 +27,8 @@ func TestAPIListStopWatches(t *testing.T) {
resp := session.MakeRequest(t, req, http.StatusOK)
var apiWatches []*api.StopWatch
DecodeJSON(t, resp, &apiWatches)
- stopwatch := models.AssertExistsAndLoadBean(t, &models.Stopwatch{UserID: owner.ID}).(*models.Stopwatch)
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: stopwatch.IssueID}).(*models.Issue)
+ stopwatch := db.AssertExistsAndLoadBean(t, &models.Stopwatch{UserID: owner.ID}).(*models.Stopwatch)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: stopwatch.IssueID}).(*models.Issue)
if assert.Len(t, apiWatches, 1) {
assert.EqualValues(t, stopwatch.CreatedUnix.AsTime().Unix(), apiWatches[0].Created.Unix())
assert.EqualValues(t, issue.Index, apiWatches[0].IssueIndex)
@@ -41,10 +42,10 @@ func TestAPIListStopWatches(t *testing.T) {
func TestAPIStopStopWatches(t *testing.T) {
defer prepareTestEnv(t)()
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
_ = issue.LoadRepo()
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
@@ -57,10 +58,10 @@ func TestAPIStopStopWatches(t *testing.T) {
func TestAPICancelStopWatches(t *testing.T) {
defer prepareTestEnv(t)()
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
_ = issue.LoadRepo()
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
@@ -73,10 +74,10 @@ func TestAPICancelStopWatches(t *testing.T) {
func TestAPIStartStopWatches(t *testing.T) {
defer prepareTestEnv(t)()
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue)
_ = issue.LoadRepo()
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: issue.Repo.OwnerID}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_issue_subscription_test.go b/integrations/api_issue_subscription_test.go
index d0b1921015..30c3076611 100644
--- a/integrations/api_issue_subscription_test.go
+++ b/integrations/api_issue_subscription_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -18,20 +19,20 @@ import (
func TestAPIIssueSubscriptions(t *testing.T) {
defer prepareTestEnv(t)()
- issue1 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
- issue2 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
- issue3 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue)
- issue4 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 4}).(*models.Issue)
- issue5 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 8}).(*models.Issue)
+ issue1 := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 1}).(*models.Issue)
+ issue2 := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
+ issue3 := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue)
+ issue4 := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 4}).(*models.Issue)
+ issue5 := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 8}).(*models.Issue)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: issue1.PosterID}).(*models.User)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: issue1.PosterID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
testSubscription := func(issue *models.Issue, isWatching bool) {
- issueRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
+ issueRepo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/check?token=%s", issueRepo.OwnerName, issueRepo.Name, issue.Index, token)
req := NewRequest(t, "GET", urlStr)
@@ -52,7 +53,7 @@ func TestAPIIssueSubscriptions(t *testing.T) {
testSubscription(issue4, false)
testSubscription(issue5, false)
- issue1Repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue1.RepoID}).(*models.Repository)
+ issue1Repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue1.RepoID}).(*models.Repository)
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/%s?token=%s", issue1Repo.OwnerName, issue1Repo.Name, issue1.Index, owner.Name, token)
req := NewRequest(t, "DELETE", urlStr)
session.MakeRequest(t, req, http.StatusCreated)
@@ -62,7 +63,7 @@ func TestAPIIssueSubscriptions(t *testing.T) {
session.MakeRequest(t, req, http.StatusOK)
testSubscription(issue1, false)
- issue5Repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue5.RepoID}).(*models.Repository)
+ issue5Repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issue5.RepoID}).(*models.Repository)
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/%s?token=%s", issue5Repo.OwnerName, issue5Repo.Name, issue5.Index, owner.Name, token)
req = NewRequest(t, "PUT", urlStr)
session.MakeRequest(t, req, http.StatusCreated)
diff --git a/integrations/api_issue_test.go b/integrations/api_issue_test.go
index 245ab76c7b..df258a9831 100644
--- a/integrations/api_issue_test.go
+++ b/integrations/api_issue_test.go
@@ -12,6 +12,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -20,8 +21,8 @@ import (
func TestAPIListIssues(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -31,9 +32,9 @@ func TestAPIListIssues(t *testing.T) {
resp := session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
var apiIssues []*api.Issue
DecodeJSON(t, resp, &apiIssues)
- assert.Len(t, apiIssues, models.GetCount(t, &models.Issue{RepoID: repo.ID}))
+ assert.Len(t, apiIssues, db.GetCount(t, &models.Issue{RepoID: repo.ID}))
for _, apiIssue := range apiIssues {
- models.AssertExistsAndLoadBean(t, &models.Issue{ID: apiIssue.ID, RepoID: repo.ID})
+ db.AssertExistsAndLoadBean(t, &models.Issue{ID: apiIssue.ID, RepoID: repo.ID})
}
// test milestone filter
@@ -71,8 +72,8 @@ func TestAPICreateIssue(t *testing.T) {
defer prepareTestEnv(t)()
const body, title = "apiTestBody", "apiTestTitle"
- repoBefore := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repoBefore.OwnerID}).(*models.User)
+ repoBefore := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repoBefore.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -88,14 +89,14 @@ func TestAPICreateIssue(t *testing.T) {
assert.Equal(t, body, apiIssue.Body)
assert.Equal(t, title, apiIssue.Title)
- models.AssertExistsAndLoadBean(t, &models.Issue{
+ db.AssertExistsAndLoadBean(t, &models.Issue{
RepoID: repoBefore.ID,
AssigneeID: owner.ID,
Content: body,
Title: title,
})
- repoAfter := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repoAfter := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
assert.Equal(t, repoBefore.NumIssues+1, repoAfter.NumIssues)
assert.Equal(t, repoBefore.NumClosedIssues, repoAfter.NumClosedIssues)
}
@@ -103,9 +104,9 @@ func TestAPICreateIssue(t *testing.T) {
func TestAPIEditIssue(t *testing.T) {
defer prepareTestEnv(t)()
- issueBefore := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 10}).(*models.Issue)
- repoBefore := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issueBefore.RepoID}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repoBefore.OwnerID}).(*models.User)
+ issueBefore := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 10}).(*models.Issue)
+ repoBefore := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issueBefore.RepoID}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repoBefore.OwnerID}).(*models.User)
assert.NoError(t, issueBefore.LoadAttributes())
assert.Equal(t, int64(1019307200), int64(issueBefore.DeadlineUnix))
assert.Equal(t, api.StateOpen, issueBefore.State())
@@ -134,8 +135,8 @@ func TestAPIEditIssue(t *testing.T) {
var apiIssue api.Issue
DecodeJSON(t, resp, &apiIssue)
- issueAfter := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 10}).(*models.Issue)
- repoAfter := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issueBefore.RepoID}).(*models.Repository)
+ issueAfter := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 10}).(*models.Issue)
+ repoAfter := db.AssertExistsAndLoadBean(t, &models.Repository{ID: issueBefore.RepoID}).(*models.Repository)
// check deleted user
assert.Equal(t, int64(500), issueAfter.PosterID)
diff --git a/integrations/api_issue_tracked_time_test.go b/integrations/api_issue_tracked_time_test.go
index 9731c5a93b..fcf18e45df 100644
--- a/integrations/api_issue_tracked_time_test.go
+++ b/integrations/api_issue_tracked_time_test.go
@@ -11,6 +11,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -19,8 +20,8 @@ import (
func TestAPIGetTrackedTimes(t *testing.T) {
defer prepareTestEnv(t)()
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- issue2 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ issue2 := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
assert.NoError(t, issue2.LoadRepo())
session := loginUser(t, user2.Name)
@@ -61,10 +62,10 @@ func TestAPIGetTrackedTimes(t *testing.T) {
func TestAPIDeleteTrackedTime(t *testing.T) {
defer prepareTestEnv(t)()
- time6 := models.AssertExistsAndLoadBean(t, &models.TrackedTime{ID: 6}).(*models.TrackedTime)
- issue2 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
+ time6 := db.AssertExistsAndLoadBean(t, &models.TrackedTime{ID: 6}).(*models.TrackedTime)
+ issue2 := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
assert.NoError(t, issue2.LoadRepo())
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session)
@@ -73,7 +74,7 @@ func TestAPIDeleteTrackedTime(t *testing.T) {
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/times/%d?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, time6.ID, token)
session.MakeRequest(t, req, http.StatusForbidden)
- time3 := models.AssertExistsAndLoadBean(t, &models.TrackedTime{ID: 3}).(*models.TrackedTime)
+ time3 := db.AssertExistsAndLoadBean(t, &models.TrackedTime{ID: 3}).(*models.TrackedTime)
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/times/%d?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, time3.ID, token)
session.MakeRequest(t, req, http.StatusNoContent)
//Delete non existing time
@@ -96,10 +97,10 @@ func TestAPIDeleteTrackedTime(t *testing.T) {
func TestAPIAddTrackedTimes(t *testing.T) {
defer prepareTestEnv(t)()
- issue2 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
+ issue2 := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
assert.NoError(t, issue2.LoadRepo())
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- admin := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ admin := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
session := loginUser(t, admin.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_keys_test.go b/integrations/api_keys_test.go
index 50e1e7a35b..161b05e8ce 100644
--- a/integrations/api_keys_test.go
+++ b/integrations/api_keys_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -45,8 +46,8 @@ func TestDeleteDeployKeyNoLogin(t *testing.T) {
func TestCreateReadOnlyDeployKey(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{Name: "repo1"}).(*models.Repository)
- repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{Name: "repo1"}).(*models.Repository)
+ repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -61,7 +62,7 @@ func TestCreateReadOnlyDeployKey(t *testing.T) {
var newDeployKey api.DeployKey
DecodeJSON(t, resp, &newDeployKey)
- models.AssertExistsAndLoadBean(t, &models.DeployKey{
+ db.AssertExistsAndLoadBean(t, &models.DeployKey{
ID: newDeployKey.ID,
Name: rawKeyBody.Title,
Content: rawKeyBody.Key,
@@ -71,8 +72,8 @@ func TestCreateReadOnlyDeployKey(t *testing.T) {
func TestCreateReadWriteDeployKey(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{Name: "repo1"}).(*models.Repository)
- repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{Name: "repo1"}).(*models.Repository)
+ repoOwner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, repoOwner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -86,7 +87,7 @@ func TestCreateReadWriteDeployKey(t *testing.T) {
var newDeployKey api.DeployKey
DecodeJSON(t, resp, &newDeployKey)
- models.AssertExistsAndLoadBean(t, &models.DeployKey{
+ db.AssertExistsAndLoadBean(t, &models.DeployKey{
ID: newDeployKey.ID,
Name: rawKeyBody.Title,
Content: rawKeyBody.Key,
@@ -96,7 +97,7 @@ func TestCreateReadWriteDeployKey(t *testing.T) {
func TestCreateUserKey(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
session := loginUser(t, "user1")
token := url.QueryEscape(getTokenForLoggedInUser(t, session))
@@ -112,7 +113,7 @@ func TestCreateUserKey(t *testing.T) {
var newPublicKey api.PublicKey
DecodeJSON(t, resp, &newPublicKey)
- models.AssertExistsAndLoadBean(t, &models.PublicKey{
+ db.AssertExistsAndLoadBean(t, &models.PublicKey{
ID: newPublicKey.ID,
OwnerID: user.ID,
Name: rawKeyBody.Title,
diff --git a/integrations/api_notification_test.go b/integrations/api_notification_test.go
index 96af14fb82..3049f1b995 100644
--- a/integrations/api_notification_test.go
+++ b/integrations/api_notification_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -18,9 +19,9 @@ import (
func TestAPINotification(t *testing.T) {
defer prepareTestEnv(t)()
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- thread5 := models.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ thread5 := db.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification)
assert.NoError(t, thread5.LoadAttributes())
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session)
@@ -111,7 +112,7 @@ func TestAPINotification(t *testing.T) {
resp = session.MakeRequest(t, req, http.StatusResetContent)
assert.Equal(t, models.NotificationStatusUnread, thread5.Status)
- thread5 = models.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification)
+ thread5 = db.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification)
assert.Equal(t, models.NotificationStatusRead, thread5.Status)
// -- check notifications --
diff --git a/integrations/api_oauth2_apps_test.go b/integrations/api_oauth2_apps_test.go
index 5c90dbb3bc..4cda41755a 100644
--- a/integrations/api_oauth2_apps_test.go
+++ b/integrations/api_oauth2_apps_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -25,7 +26,7 @@ func TestOAuth2Application(t *testing.T) {
}
func testAPICreateOAuth2Application(t *testing.T) {
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
appBody := api.CreateOAuth2ApplicationOptions{
Name: "test-app-1",
RedirectURIs: []string{
@@ -45,15 +46,15 @@ func testAPICreateOAuth2Application(t *testing.T) {
assert.Len(t, createdApp.ClientID, 36)
assert.NotEmpty(t, createdApp.Created)
assert.EqualValues(t, appBody.RedirectURIs[0], createdApp.RedirectURIs[0])
- models.AssertExistsAndLoadBean(t, &models.OAuth2Application{UID: user.ID, Name: createdApp.Name})
+ db.AssertExistsAndLoadBean(t, &models.OAuth2Application{UID: user.ID, Name: createdApp.Name})
}
func testAPIListOAuth2Applications(t *testing.T) {
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
- existApp := models.AssertExistsAndLoadBean(t, &models.OAuth2Application{
+ existApp := db.AssertExistsAndLoadBean(t, &models.OAuth2Application{
UID: user.ID,
Name: "test-app-1",
RedirectURIs: []string{
@@ -74,15 +75,15 @@ func testAPIListOAuth2Applications(t *testing.T) {
assert.Len(t, expectedApp.ClientID, 36)
assert.Empty(t, expectedApp.ClientSecret)
assert.EqualValues(t, existApp.RedirectURIs[0], expectedApp.RedirectURIs[0])
- models.AssertExistsAndLoadBean(t, &models.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
+ db.AssertExistsAndLoadBean(t, &models.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
}
func testAPIDeleteOAuth2Application(t *testing.T) {
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
- oldApp := models.AssertExistsAndLoadBean(t, &models.OAuth2Application{
+ oldApp := db.AssertExistsAndLoadBean(t, &models.OAuth2Application{
UID: user.ID,
Name: "test-app-1",
}).(*models.OAuth2Application)
@@ -91,7 +92,7 @@ func testAPIDeleteOAuth2Application(t *testing.T) {
req := NewRequest(t, "DELETE", urlStr)
session.MakeRequest(t, req, http.StatusNoContent)
- models.AssertNotExistsBean(t, &models.OAuth2Application{UID: oldApp.UID, Name: oldApp.Name})
+ db.AssertNotExistsBean(t, &models.OAuth2Application{UID: oldApp.UID, Name: oldApp.Name})
// Delete again will return not found
req = NewRequest(t, "DELETE", urlStr)
@@ -99,11 +100,11 @@ func testAPIDeleteOAuth2Application(t *testing.T) {
}
func testAPIGetOAuth2Application(t *testing.T) {
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
- existApp := models.AssertExistsAndLoadBean(t, &models.OAuth2Application{
+ existApp := db.AssertExistsAndLoadBean(t, &models.OAuth2Application{
UID: user.ID,
Name: "test-app-1",
RedirectURIs: []string{
@@ -125,13 +126,13 @@ func testAPIGetOAuth2Application(t *testing.T) {
assert.Empty(t, expectedApp.ClientSecret)
assert.Len(t, expectedApp.RedirectURIs, 1)
assert.EqualValues(t, existApp.RedirectURIs[0], expectedApp.RedirectURIs[0])
- models.AssertExistsAndLoadBean(t, &models.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
+ db.AssertExistsAndLoadBean(t, &models.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
}
func testAPIUpdateOAuth2Application(t *testing.T) {
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- existApp := models.AssertExistsAndLoadBean(t, &models.OAuth2Application{
+ existApp := db.AssertExistsAndLoadBean(t, &models.OAuth2Application{
UID: user.ID,
Name: "test-app-1",
RedirectURIs: []string{
@@ -159,5 +160,5 @@ func testAPIUpdateOAuth2Application(t *testing.T) {
assert.Len(t, expectedApp.RedirectURIs, 2)
assert.EqualValues(t, expectedApp.RedirectURIs[0], appBody.RedirectURIs[0])
assert.EqualValues(t, expectedApp.RedirectURIs[1], appBody.RedirectURIs[1])
- models.AssertExistsAndLoadBean(t, &models.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
+ db.AssertExistsAndLoadBean(t, &models.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
}
diff --git a/integrations/api_org_test.go b/integrations/api_org_test.go
index bc4428b99e..6268fa4a10 100644
--- a/integrations/api_org_test.go
+++ b/integrations/api_org_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -43,7 +44,7 @@ func TestAPIOrgCreate(t *testing.T) {
assert.Equal(t, org.Location, apiOrg.Location)
assert.Equal(t, org.Visibility, apiOrg.Visibility)
- models.AssertExistsAndLoadBean(t, &models.User{
+ db.AssertExistsAndLoadBean(t, &models.User{
Name: org.UserName,
LowerName: strings.ToLower(org.UserName),
FullName: org.FullName,
diff --git a/integrations/api_pull_commits_test.go b/integrations/api_pull_commits_test.go
index 30682d9c14..615589fd12 100644
--- a/integrations/api_pull_commits_test.go
+++ b/integrations/api_pull_commits_test.go
@@ -9,15 +9,16 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
)
func TestAPIPullCommits(t *testing.T) {
defer prepareTestEnv(t)()
- pullIssue := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
+ pullIssue := db.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
assert.NoError(t, pullIssue.LoadIssue())
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.HeadRepoID}).(*models.Repository)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.HeadRepoID}).(*models.Repository)
session := loginUser(t, "user2")
req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pullIssue.Index)
diff --git a/integrations/api_pull_review_test.go b/integrations/api_pull_review_test.go
index b0e380376b..123ba0a2b5 100644
--- a/integrations/api_pull_review_test.go
+++ b/integrations/api_pull_review_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs"
@@ -18,9 +19,9 @@ import (
func TestAPIPullReview(t *testing.T) {
defer prepareTestEnv(t)()
- pullIssue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue)
+ pullIssue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue)
assert.NoError(t, pullIssue.LoadAttributes())
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.RepoID}).(*models.Repository)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.RepoID}).(*models.Repository)
// test ListPullReviews
session := loginUser(t, "user2")
@@ -62,7 +63,7 @@ func TestAPIPullReview(t *testing.T) {
assert.EqualValues(t, *reviews[5], review)
// test GetPullReviewComments
- comment := models.AssertExistsAndLoadBean(t, &models.Comment{ID: 7}).(*models.Comment)
+ comment := db.AssertExistsAndLoadBean(t, &models.Comment{ID: 7}).(*models.Comment)
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews/%d/comments?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, 10, token)
resp = session.MakeRequest(t, req, http.StatusOK)
var reviewComments []*api.PullReviewComment
@@ -195,9 +196,9 @@ func TestAPIPullReview(t *testing.T) {
// test get review requests
// to make it simple, use same api with get review
- pullIssue12 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 12}).(*models.Issue)
+ pullIssue12 := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 12}).(*models.Issue)
assert.NoError(t, pullIssue12.LoadAttributes())
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue12.RepoID}).(*models.Repository)
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue12.RepoID}).(*models.Repository)
req = NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token)
resp = session.MakeRequest(t, req, http.StatusOK)
@@ -219,9 +220,9 @@ func TestAPIPullReview(t *testing.T) {
func TestAPIPullReviewRequest(t *testing.T) {
defer prepareTestEnv(t)()
- pullIssue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue)
+ pullIssue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 3}).(*models.Issue)
assert.NoError(t, pullIssue.LoadAttributes())
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.RepoID}).(*models.Repository)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.RepoID}).(*models.Repository)
// Test add Review Request
session := loginUser(t, "user2")
@@ -264,9 +265,9 @@ func TestAPIPullReviewRequest(t *testing.T) {
session.MakeRequest(t, req, http.StatusNoContent)
// Test team review request
- pullIssue12 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 12}).(*models.Issue)
+ pullIssue12 := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 12}).(*models.Issue)
assert.NoError(t, pullIssue12.LoadAttributes())
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue12.RepoID}).(*models.Repository)
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue12.RepoID}).(*models.Repository)
// Test add Team Review Request
req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/requested_reviewers?token=%s", repo3.OwnerName, repo3.Name, pullIssue12.Index, token), &api.PullReviewRequestOptions{
diff --git a/integrations/api_pull_test.go b/integrations/api_pull_test.go
index e6a4aca153..069650993d 100644
--- a/integrations/api_pull_test.go
+++ b/integrations/api_pull_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/services/forms"
@@ -20,8 +21,8 @@ import (
func TestAPIViewPulls(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, "user2")
token := getTokenForLoggedInUser(t, session)
@@ -30,16 +31,16 @@ func TestAPIViewPulls(t *testing.T) {
var pulls []*api.PullRequest
DecodeJSON(t, resp, &pulls)
- expectedLen := models.GetCount(t, &models.Issue{RepoID: repo.ID}, models.Cond("is_pull = ?", true))
+ expectedLen := db.GetCount(t, &models.Issue{RepoID: repo.ID}, db.Cond("is_pull = ?", true))
assert.Len(t, pulls, expectedLen)
}
// TestAPIMergePullWIP ensures that we can't merge a WIP pull request
func TestAPIMergePullWIP(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
- pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{Status: models.PullRequestStatusMergeable}, models.Cond("has_merged = ?", false)).(*models.PullRequest)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ pr := db.AssertExistsAndLoadBean(t, &models.PullRequest{Status: models.PullRequestStatusMergeable}, db.Cond("has_merged = ?", false)).(*models.PullRequest)
pr.LoadIssue()
issue_service.ChangeTitle(pr.Issue, owner, setting.Repository.PullRequest.WorkInProgressPrefixes[0]+" "+pr.Issue.Title)
@@ -60,12 +61,12 @@ func TestAPIMergePullWIP(t *testing.T) {
func TestAPICreatePullSuccess(t *testing.T) {
defer prepareTestEnv(t)()
- repo10 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
+ repo10 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
// repo10 have code, pulls units.
- repo11 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
+ repo11 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
// repo11 only have code unit but should still create pulls
- owner10 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
- owner11 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo11.OwnerID}).(*models.User)
+ owner10 := db.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
+ owner11 := db.AssertExistsAndLoadBean(t, &models.User{ID: repo11.OwnerID}).(*models.User)
session := loginUser(t, owner11.Name)
token := getTokenForLoggedInUser(t, session)
@@ -81,11 +82,11 @@ func TestAPICreatePullSuccess(t *testing.T) {
func TestAPICreatePullWithFieldsSuccess(t *testing.T) {
defer prepareTestEnv(t)()
// repo10 have code, pulls units.
- repo10 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
- owner10 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
+ repo10 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
+ owner10 := db.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
// repo11 only have code unit but should still create pulls
- repo11 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
- owner11 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo11.OwnerID}).(*models.User)
+ repo11 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
+ owner11 := db.AssertExistsAndLoadBean(t, &models.User{ID: repo11.OwnerID}).(*models.User)
session := loginUser(t, owner11.Name)
token := getTokenForLoggedInUser(t, session)
@@ -118,11 +119,11 @@ func TestAPICreatePullWithFieldsSuccess(t *testing.T) {
func TestAPICreatePullWithFieldsFailure(t *testing.T) {
defer prepareTestEnv(t)()
// repo10 have code, pulls units.
- repo10 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
- owner10 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
+ repo10 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
+ owner10 := db.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
// repo11 only have code unit but should still create pulls
- repo11 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
- owner11 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo11.OwnerID}).(*models.User)
+ repo11 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 11}).(*models.Repository)
+ owner11 := db.AssertExistsAndLoadBean(t, &models.User{ID: repo11.OwnerID}).(*models.User)
session := loginUser(t, owner11.Name)
token := getTokenForLoggedInUser(t, session)
@@ -151,8 +152,8 @@ func TestAPICreatePullWithFieldsFailure(t *testing.T) {
func TestAPIEditPull(t *testing.T) {
defer prepareTestEnv(t)()
- repo10 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
- owner10 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
+ repo10 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
+ owner10 := db.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
session := loginUser(t, owner10.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_releases_test.go b/integrations/api_releases_test.go
index 027b282036..cb04c2a8d3 100644
--- a/integrations/api_releases_test.go
+++ b/integrations/api_releases_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
api "code.gitea.io/gitea/modules/structs"
@@ -20,8 +21,8 @@ import (
func TestAPIListReleases(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
session := loginUser(t, user2.LowerName)
token := getTokenForLoggedInUser(t, session)
@@ -84,7 +85,7 @@ func createNewReleaseUsingAPI(t *testing.T, session *TestSession, token string,
var newRelease api.Release
DecodeJSON(t, resp, &newRelease)
- models.AssertExistsAndLoadBean(t, &models.Release{
+ db.AssertExistsAndLoadBean(t, &models.Release{
ID: newRelease.ID,
TagName: newRelease.TagName,
Title: newRelease.Title,
@@ -97,8 +98,8 @@ func createNewReleaseUsingAPI(t *testing.T, session *TestSession, token string,
func TestAPICreateAndUpdateRelease(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session)
@@ -137,7 +138,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &newRelease)
- models.AssertExistsAndLoadBean(t, &models.Release{
+ db.AssertExistsAndLoadBean(t, &models.Release{
ID: newRelease.ID,
TagName: newRelease.TagName,
Title: newRelease.Title,
@@ -148,8 +149,8 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
func TestAPICreateReleaseToDefaultBranch(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session)
@@ -159,8 +160,8 @@ func TestAPICreateReleaseToDefaultBranch(t *testing.T) {
func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session)
@@ -177,8 +178,8 @@ func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) {
func TestAPIGetReleaseByTag(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.LowerName)
tag := "v1.1"
@@ -210,8 +211,8 @@ func TestAPIGetReleaseByTag(t *testing.T) {
func TestAPIDeleteReleaseByTagName(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_repo_edit_test.go b/integrations/api_repo_edit_test.go
index 618c1f0ad0..e980357a0f 100644
--- a/integrations/api_repo_edit_test.go
+++ b/integrations/api_repo_edit_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -132,13 +133,13 @@ func TestAPIRepoEdit(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
bFalse, bTrue := false, true
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
- user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
- user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
- repo15 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 15}).(*models.Repository) // empty repo
- repo16 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
+ user4 := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
+ repo15 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 15}).(*models.Repository) // empty repo
+ repo16 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
// Get user2's token
session := loginUser(t, user2.Name)
@@ -164,7 +165,7 @@ func TestAPIRepoEdit(t *testing.T) {
assert.Equal(t, *repoEditOption.Website, repo.Website)
assert.Equal(t, *repoEditOption.Archived, repo.Archived)
// check repo1 from database
- repo1edited := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo1edited := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repo1editedOption := getRepoEditOptionFromRepo(repo1edited)
assert.Equal(t, *repoEditOption.Name, *repo1editedOption.Name)
assert.Equal(t, *repoEditOption.Description, *repo1editedOption.Description)
@@ -189,7 +190,7 @@ func TestAPIRepoEdit(t *testing.T) {
DecodeJSON(t, resp, &repo)
assert.NotNil(t, repo)
// check repo1 was written to database
- repo1edited = models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo1edited = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repo1editedOption = getRepoEditOptionFromRepo(repo1edited)
assert.Equal(t, *repo1editedOption.HasIssues, true)
assert.Nil(t, repo1editedOption.ExternalTracker)
@@ -211,7 +212,7 @@ func TestAPIRepoEdit(t *testing.T) {
DecodeJSON(t, resp, &repo)
assert.NotNil(t, repo)
// check repo1 was written to database
- repo1edited = models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo1edited = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repo1editedOption = getRepoEditOptionFromRepo(repo1edited)
assert.Equal(t, *repo1editedOption.HasIssues, true)
assert.Equal(t, *repo1editedOption.ExternalTracker, *repoEditOption.ExternalTracker)
@@ -242,7 +243,7 @@ func TestAPIRepoEdit(t *testing.T) {
DecodeJSON(t, resp, &repo)
assert.NotNil(t, repo)
// check repo1 was written to database
- repo1edited = models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo1edited = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repo1editedOption = getRepoEditOptionFromRepo(repo1edited)
assert.Equal(t, *repo1editedOption.Description, *repoEditOption.Description)
assert.Equal(t, *repo1editedOption.HasIssues, true)
@@ -287,7 +288,7 @@ func TestAPIRepoEdit(t *testing.T) {
_ = session.MakeRequest(t, req, http.StatusOK)
// Test making a repo public that is private
- repo16 = models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
+ repo16 = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
assert.True(t, repo16.IsPrivate)
repoEditOption = &api.EditRepoOption{
Private: &bFalse,
@@ -295,7 +296,7 @@ func TestAPIRepoEdit(t *testing.T) {
url = fmt.Sprintf("/api/v1/repos/%s/%s?token=%s", user2.Name, repo16.Name, token2)
req = NewRequestWithJSON(t, "PATCH", url, &repoEditOption)
_ = session.MakeRequest(t, req, http.StatusOK)
- repo16 = models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
+ repo16 = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
assert.False(t, repo16.IsPrivate)
// Make it private again
repoEditOption.Private = &bTrue
@@ -309,7 +310,7 @@ func TestAPIRepoEdit(t *testing.T) {
Archived: &bTrue,
})
_ = session.MakeRequest(t, req, http.StatusOK)
- repo15 = models.AssertExistsAndLoadBean(t, &models.Repository{ID: 15}).(*models.Repository)
+ repo15 = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 15}).(*models.Repository)
assert.True(t, repo15.IsArchived)
req = NewRequestWithJSON(t, "PATCH", url, &api.EditRepoOption{
Archived: &bFalse,
diff --git a/integrations/api_repo_file_create_test.go b/integrations/api_repo_file_create_test.go
index 17ed6cb7cf..5b0e3927f9 100644
--- a/integrations/api_repo_file_create_test.go
+++ b/integrations/api_repo_file_create_test.go
@@ -14,6 +14,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
@@ -108,8 +109,8 @@ func getExpectedFileResponseForCreate(commitID, treePath string) *api.FileRespon
func BenchmarkAPICreateFileSmall(b *testing.B) {
onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
b := t.(*testing.B)
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
for n := 0; n < b.N; n++ {
treePath := fmt.Sprintf("update/file%d.txt", n)
@@ -123,8 +124,8 @@ func BenchmarkAPICreateFileMedium(b *testing.B) {
onGiteaRunTB(b, func(t testing.TB, u *url.URL) {
b := t.(*testing.B)
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
b.ResetTimer()
for n := 0; n < b.N; n++ {
@@ -137,12 +138,12 @@ func BenchmarkAPICreateFileMedium(b *testing.B) {
func TestAPICreateFile(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
- user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
- user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
- repo16 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
+ user4 := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
+ repo16 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
fileID := 0
// Get user2's token
diff --git a/integrations/api_repo_file_delete_test.go b/integrations/api_repo_file_delete_test.go
index 178aec6f5b..69e24d29c3 100644
--- a/integrations/api_repo_file_delete_test.go
+++ b/integrations/api_repo_file_delete_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -37,12 +38,12 @@ func getDeleteFileOptions() *api.DeleteFileOptions {
func TestAPIDeleteFile(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
- user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
- user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
- repo16 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
+ user4 := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
+ repo16 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
fileID := 0
// Get user2's token
diff --git a/integrations/api_repo_file_update_test.go b/integrations/api_repo_file_update_test.go
index 69a9463774..b6d9be24f5 100644
--- a/integrations/api_repo_file_update_test.go
+++ b/integrations/api_repo_file_update_test.go
@@ -13,6 +13,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
@@ -103,12 +104,12 @@ func getExpectedFileResponseForUpdate(commitID, treePath string) *api.FileRespon
func TestAPIUpdateFile(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
- user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
- user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
- repo16 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
+ user4 := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
+ repo16 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
fileID := 0
// Get user2's token
diff --git a/integrations/api_repo_get_contents_list_test.go b/integrations/api_repo_get_contents_list_test.go
index ddbd877a40..625231a8b2 100644
--- a/integrations/api_repo_get_contents_list_test.go
+++ b/integrations/api_repo_get_contents_list_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -52,13 +53,13 @@ func TestAPIGetContentsList(t *testing.T) {
func testAPIGetContentsList(t *testing.T, u *url.URL) {
/*** SETUP ***/
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
- user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
- user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
- repo16 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
- treePath := "" // root dir
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
+ user4 := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
+ repo16 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
+ treePath := "" // root dir
// Get user2's token
session := loginUser(t, user2.Name)
diff --git a/integrations/api_repo_get_contents_test.go b/integrations/api_repo_get_contents_test.go
index 3d4a31be81..e096a718bd 100644
--- a/integrations/api_repo_get_contents_test.go
+++ b/integrations/api_repo_get_contents_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -53,12 +54,12 @@ func TestAPIGetContents(t *testing.T) {
func testAPIGetContents(t *testing.T, u *url.URL) {
/*** SETUP ***/
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
- user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
- user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
- repo16 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3, is an org
+ user4 := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
+ repo16 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
treePath := "README.md"
// Get user2's token
diff --git a/integrations/api_repo_git_blobs_test.go b/integrations/api_repo_git_blobs_test.go
index 675916eeaa..5bbf13ac46 100644
--- a/integrations/api_repo_git_blobs_test.go
+++ b/integrations/api_repo_git_blobs_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -16,12 +17,12 @@ import (
func TestAPIReposGitBlobs(t *testing.T) {
defer prepareTestEnv(t)()
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
- user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3
- user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
- repo16 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3
+ user4 := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
+ repo16 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
repo1ReadmeSHA := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
repo3ReadmeSHA := "d56a3073c1dbb7b15963110a049d50cdb5db99fc"
repo16ReadmeSHA := "f90451c72ef61a7645293d17b47be7a8e983da57"
diff --git a/integrations/api_repo_git_commits_test.go b/integrations/api_repo_git_commits_test.go
index d6bd5fc62e..19dab433d4 100644
--- a/integrations/api_repo_git_commits_test.go
+++ b/integrations/api_repo_git_commits_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -24,7 +25,7 @@ func compareCommitFiles(t *testing.T, expect []string, files []*api.CommitAffect
func TestAPIReposGitCommits(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Login as User2.
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
@@ -52,7 +53,7 @@ func TestAPIReposGitCommits(t *testing.T) {
func TestAPIReposGitCommitList(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Login as User2.
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
@@ -75,7 +76,7 @@ func TestAPIReposGitCommitList(t *testing.T) {
func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Login as User2.
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
@@ -92,7 +93,7 @@ func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Login as User2.
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_repo_git_hook_test.go b/integrations/api_repo_git_hook_test.go
index f7e55d92ae..490251b30b 100644
--- a/integrations/api_repo_git_hook_test.go
+++ b/integrations/api_repo_git_hook_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -23,8 +24,8 @@ echo Hello, World!
func TestAPIListGitHooks(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
// user1 is an admin user
session := loginUser(t, "user1")
@@ -49,8 +50,8 @@ func TestAPIListGitHooks(t *testing.T) {
func TestAPIListGitHooksNoHooks(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
// user1 is an admin user
session := loginUser(t, "user1")
@@ -70,8 +71,8 @@ func TestAPIListGitHooksNoHooks(t *testing.T) {
func TestAPIListGitHooksNoAccess(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -83,8 +84,8 @@ func TestAPIListGitHooksNoAccess(t *testing.T) {
func TestAPIGetGitHook(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
// user1 is an admin user
session := loginUser(t, "user1")
@@ -101,8 +102,8 @@ func TestAPIGetGitHook(t *testing.T) {
func TestAPIGetGitHookNoAccess(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -114,8 +115,8 @@ func TestAPIGetGitHookNoAccess(t *testing.T) {
func TestAPIEditGitHook(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
// user1 is an admin user
session := loginUser(t, "user1")
@@ -144,8 +145,8 @@ func TestAPIEditGitHook(t *testing.T) {
func TestAPIEditGitHookNoAccess(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
@@ -160,8 +161,8 @@ func TestAPIEditGitHookNoAccess(t *testing.T) {
func TestAPIDeleteGitHook(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 37}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
// user1 is an admin user
session := loginUser(t, "user1")
@@ -183,8 +184,8 @@ func TestAPIDeleteGitHook(t *testing.T) {
func TestAPIDeleteGitHookNoAccess(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_repo_git_notes_test.go b/integrations/api_repo_git_notes_test.go
index 6eae5e970d..02235f9d91 100644
--- a/integrations/api_repo_git_notes_test.go
+++ b/integrations/api_repo_git_notes_test.go
@@ -10,13 +10,14 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
)
func TestAPIReposGitNotes(t *testing.T) {
onGiteaRun(t, func(*testing.T, *url.URL) {
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Login as User2.
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_repo_git_ref_test.go b/integrations/api_repo_git_ref_test.go
index 39237f59a2..fcf5edc758 100644
--- a/integrations/api_repo_git_ref_test.go
+++ b/integrations/api_repo_git_ref_test.go
@@ -9,11 +9,12 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func TestAPIReposGitRefs(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Login as User2.
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_repo_git_tags_test.go b/integrations/api_repo_git_tags_test.go
index bf6fc7c858..01e0450c6b 100644
--- a/integrations/api_repo_git_tags_test.go
+++ b/integrations/api_repo_git_tags_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
@@ -19,8 +20,8 @@ import (
func TestAPIGitTags(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
// Login as User2.
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
@@ -64,8 +65,8 @@ func TestAPIGitTags(t *testing.T) {
func TestAPIDeleteTagByName(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_repo_git_trees_test.go b/integrations/api_repo_git_trees_test.go
index 6b4e120dec..bf605d4d86 100644
--- a/integrations/api_repo_git_trees_test.go
+++ b/integrations/api_repo_git_trees_test.go
@@ -9,16 +9,17 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func TestAPIReposGitTrees(t *testing.T) {
defer prepareTestEnv(t)()
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
- user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3
- user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
- repo16 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo1 & repo16
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of the repo3
+ user4 := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // owner of neither repos
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) // public repo
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // public repo
+ repo16 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) // private repo
repo1TreeSHA := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
repo3TreeSHA := "2a47ca4b614a9f5a43abbd5ad851a54a616ffee6"
repo16TreeSHA := "69554a64c1e6030f051e5c3f94bfbd773cd6a324"
diff --git a/integrations/api_repo_lfs_locks_test.go b/integrations/api_repo_lfs_locks_test.go
index 03549c11f4..b2d8f0e631 100644
--- a/integrations/api_repo_lfs_locks_test.go
+++ b/integrations/api_repo_lfs_locks_test.go
@@ -11,6 +11,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -21,8 +22,8 @@ import (
func TestAPILFSLocksNotStarted(t *testing.T) {
defer prepareTestEnv(t)()
setting.LFS.StartServer = false
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
req := NewRequestf(t, "GET", "/%s/%s.git/info/lfs/locks", user.Name, repo.Name)
MakeRequest(t, req, http.StatusNotFound)
@@ -37,8 +38,8 @@ func TestAPILFSLocksNotStarted(t *testing.T) {
func TestAPILFSLocksNotLogin(t *testing.T) {
defer prepareTestEnv(t)()
setting.LFS.StartServer = true
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
req := NewRequestf(t, "GET", "/%s/%s.git/info/lfs/locks", user.Name, repo.Name)
req.Header.Set("Accept", lfs.MediaType)
@@ -51,11 +52,11 @@ func TestAPILFSLocksNotLogin(t *testing.T) {
func TestAPILFSLocksLogged(t *testing.T) {
defer prepareTestEnv(t)()
setting.LFS.StartServer = true
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) //in org 3
- user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) //in org 3
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) //in org 3
+ user4 := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) //in org 3
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // own by org 3
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository) // own by org 3
tests := []struct {
user *models.User
diff --git a/integrations/api_repo_lfs_migrate_test.go b/integrations/api_repo_lfs_migrate_test.go
index 7280658b74..9acc96e4f4 100644
--- a/integrations/api_repo_lfs_migrate_test.go
+++ b/integrations/api_repo_lfs_migrate_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -25,7 +26,7 @@ func TestAPIRepoLFSMigrateLocal(t *testing.T) {
setting.ImportLocalPaths = true
setting.Migrations.AllowLocalNetworks = true
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_repo_lfs_test.go b/integrations/api_repo_lfs_test.go
index 56a6fa81fd..22c324f973 100644
--- a/integrations/api_repo_lfs_test.go
+++ b/integrations/api_repo_lfs_test.go
@@ -13,6 +13,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/setting"
@@ -25,8 +26,8 @@ func TestAPILFSNotStarted(t *testing.T) {
setting.LFS.StartServer = false
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
req := NewRequestf(t, "POST", "/%s/%s.git/info/lfs/objects/batch", user.Name, repo.Name)
MakeRequest(t, req, http.StatusNotFound)
@@ -45,8 +46,8 @@ func TestAPILFSMediaType(t *testing.T) {
setting.LFS.StartServer = true
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
req := NewRequestf(t, "POST", "/%s/%s.git/info/lfs/objects/batch", user.Name, repo.Name)
MakeRequest(t, req, http.StatusUnsupportedMediaType)
diff --git a/integrations/api_repo_raw_test.go b/integrations/api_repo_raw_test.go
index 62b734fa06..77b33473c8 100644
--- a/integrations/api_repo_raw_test.go
+++ b/integrations/api_repo_raw_test.go
@@ -9,11 +9,12 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func TestAPIReposRaw(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Login as User2.
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_repo_tags_test.go b/integrations/api_repo_tags_test.go
index 0bf54d3a95..8897bc44bc 100644
--- a/integrations/api_repo_tags_test.go
+++ b/integrations/api_repo_tags_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -18,7 +19,7 @@ import (
func TestAPIRepoTags(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Login as User2.
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/api_repo_teams_test.go b/integrations/api_repo_teams_test.go
index 4a155130b9..e718d79cbe 100644
--- a/integrations/api_repo_teams_test.go
+++ b/integrations/api_repo_teams_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -19,9 +20,9 @@ func TestAPIRepoTeams(t *testing.T) {
defer prepareTestEnv(t)()
// publicOrgRepo = user3/repo21
- publicOrgRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 32}).(*models.Repository)
+ publicOrgRepo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 32}).(*models.Repository)
// user4
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
@@ -61,7 +62,7 @@ func TestAPIRepoTeams(t *testing.T) {
res = session.MakeRequest(t, req, http.StatusForbidden)
// AddTeam with user2
- user = models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user = db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
session = loginUser(t, user.Name)
token = getTokenForLoggedInUser(t, session)
url = fmt.Sprintf("/api/v1/repos/%s/teams/%s?token=%s", publicOrgRepo.FullName(), "team1", token)
diff --git a/integrations/api_repo_test.go b/integrations/api_repo_test.go
index 3948489f56..63da373827 100644
--- a/integrations/api_repo_test.go
+++ b/integrations/api_repo_test.go
@@ -12,6 +12,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
@@ -21,15 +22,15 @@ import (
func TestAPIUserReposNotLogin(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
req := NewRequestf(t, "GET", "/api/v1/users/%s/repos", user.Name)
resp := MakeRequest(t, req, http.StatusOK)
var apiRepos []api.Repository
DecodeJSON(t, resp, &apiRepos)
- expectedLen := models.GetCount(t, models.Repository{OwnerID: user.ID},
- models.Cond("is_private = ?", false))
+ expectedLen := db.GetCount(t, models.Repository{OwnerID: user.ID},
+ db.Cond("is_private = ?", false))
assert.Len(t, apiRepos, expectedLen)
for _, repo := range apiRepos {
assert.EqualValues(t, user.ID, repo.Owner.ID)
@@ -52,11 +53,11 @@ func TestAPISearchRepo(t *testing.T) {
assert.False(t, repo.Private)
}
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 15}).(*models.User)
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 16}).(*models.User)
- user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 18}).(*models.User)
- user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 20}).(*models.User)
- orgUser := models.AssertExistsAndLoadBean(t, &models.User{ID: 17}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 15}).(*models.User)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 16}).(*models.User)
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{ID: 18}).(*models.User)
+ user4 := db.AssertExistsAndLoadBean(t, &models.User{ID: 20}).(*models.User)
+ orgUser := db.AssertExistsAndLoadBean(t, &models.User{ID: 17}).(*models.User)
oldAPIDefaultNum := setting.API.DefaultPagingNum
defer func() {
@@ -208,7 +209,7 @@ var repoCache = make(map[int64]*models.Repository)
func getRepo(t *testing.T, repoID int64) *models.Repository {
if _, ok := repoCache[repoID]; !ok {
- repoCache[repoID] = models.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository)
+ repoCache[repoID] = db.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository)
}
return repoCache[repoID]
}
@@ -245,11 +246,11 @@ func TestAPIViewRepo(t *testing.T) {
func TestAPIOrgRepos(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
- user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
// User3 is an Org. Check their repos.
- sourceOrg := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
+ sourceOrg := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
expectedResults := map[*models.User]struct {
count int
@@ -291,7 +292,7 @@ func TestAPIOrgRepos(t *testing.T) {
func TestAPIGetRepoByIDUnauthorized(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
req := NewRequestf(t, "GET", "/api/v1/repositories/2?token="+token)
@@ -315,7 +316,7 @@ func TestAPIRepoMigrate(t *testing.T) {
defer prepareTestEnv(t)()
for _, testCase := range testCases {
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
req := NewRequestWithJSON(t, "POST", "/api/v1/repos/migrate?token="+token, &api.MigrateRepoOptions{
@@ -394,7 +395,7 @@ func TestAPIOrgRepoCreate(t *testing.T) {
defer prepareTestEnv(t)()
for _, testCase := range testCases {
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/org/%s/repos?token="+token, testCase.orgName), &api.CreateRepoOption{
@@ -462,7 +463,7 @@ func TestAPIRepoTransfer(t *testing.T) {
defer prepareTestEnv(t)()
//create repo to move
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
repoName := "moveME"
@@ -479,8 +480,8 @@ func TestAPIRepoTransfer(t *testing.T) {
//start testing
for _, testCase := range testCases {
- user = models.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: apiRepo.ID}).(*models.Repository)
+ user = db.AssertExistsAndLoadBean(t, &models.User{ID: testCase.ctxUserID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: apiRepo.ID}).(*models.Repository)
session = loginUser(t, user.Name)
token = getTokenForLoggedInUser(t, session)
req = NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/transfer?token=%s", repo.OwnerName, repo.Name, token), &api.TransferRepoOption{
@@ -491,18 +492,18 @@ func TestAPIRepoTransfer(t *testing.T) {
}
//cleanup
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: apiRepo.ID}).(*models.Repository)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: apiRepo.ID}).(*models.Repository)
_ = models.DeleteRepository(user, repo.OwnerID, repo.ID)
}
func TestAPIGenerateRepo(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
- templateRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 44}).(*models.Repository)
+ templateRepo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 44}).(*models.Repository)
// user
repo := new(api.Repository)
@@ -534,10 +535,10 @@ func TestAPIGenerateRepo(t *testing.T) {
func TestAPIRepoGetReviewers(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/reviewers?token=%s", user.Name, repo.Name, token)
resp := session.MakeRequest(t, req, http.StatusOK)
@@ -548,10 +549,10 @@ func TestAPIRepoGetReviewers(t *testing.T) {
func TestAPIRepoGetAssignees(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/assignees?token=%s", user.Name, repo.Name, token)
resp := session.MakeRequest(t, req, http.StatusOK)
diff --git a/integrations/api_repo_topic_test.go b/integrations/api_repo_topic_test.go
index bab17a68be..cc76f18858 100644
--- a/integrations/api_repo_topic_test.go
+++ b/integrations/api_repo_topic_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -50,11 +51,11 @@ func TestAPITopicSearch(t *testing.T) {
func TestAPIRepoTopic(t *testing.T) {
defer prepareTestEnv(t)()
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of repo2
- user3 := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of repo3
- user4 := models.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // write access to repo 3
- repo2 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
- repo3 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of repo2
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User) // owner of repo3
+ user4 := db.AssertExistsAndLoadBean(t, &models.User{ID: 4}).(*models.User) // write access to repo 3
+ repo2 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ repo3 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
// Get user2's token
session := loginUser(t, user2.Name)
diff --git a/integrations/api_team_test.go b/integrations/api_team_test.go
index 0b77dc3be7..0864500335 100644
--- a/integrations/api_team_test.go
+++ b/integrations/api_team_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
@@ -20,9 +21,9 @@ import (
func TestAPITeam(t *testing.T) {
defer prepareTestEnv(t)()
- teamUser := models.AssertExistsAndLoadBean(t, &models.TeamUser{}).(*models.TeamUser)
- team := models.AssertExistsAndLoadBean(t, &models.Team{ID: teamUser.TeamID}).(*models.Team)
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: teamUser.UID}).(*models.User)
+ teamUser := db.AssertExistsAndLoadBean(t, &models.TeamUser{}).(*models.TeamUser)
+ team := db.AssertExistsAndLoadBean(t, &models.Team{ID: teamUser.TeamID}).(*models.Team)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: teamUser.UID}).(*models.User)
session := loginUser(t, user.Name)
token := getTokenForLoggedInUser(t, session)
@@ -35,8 +36,8 @@ func TestAPITeam(t *testing.T) {
assert.Equal(t, team.Name, apiTeam.Name)
// non team member user will not access the teams details
- teamUser2 := models.AssertExistsAndLoadBean(t, &models.TeamUser{ID: 3}).(*models.TeamUser)
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: teamUser2.UID}).(*models.User)
+ teamUser2 := db.AssertExistsAndLoadBean(t, &models.TeamUser{ID: 3}).(*models.TeamUser)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: teamUser2.UID}).(*models.User)
session = loginUser(t, user2.Name)
token = getTokenForLoggedInUser(t, session)
@@ -47,11 +48,11 @@ func TestAPITeam(t *testing.T) {
_ = session.MakeRequest(t, req, http.StatusUnauthorized)
// Get an admin user able to create, update and delete teams.
- user = models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user = db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
session = loginUser(t, user.Name)
token = getTokenForLoggedInUser(t, session)
- org := models.AssertExistsAndLoadBean(t, &models.User{ID: 6}).(*models.User)
+ org := db.AssertExistsAndLoadBean(t, &models.User{ID: 6}).(*models.User)
// Create team.
teamToCreate := &api.CreateTeamOption{
@@ -101,7 +102,7 @@ func TestAPITeam(t *testing.T) {
teamToEdit.Permission, teamToEdit.Units)
// Read team.
- teamRead := models.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team)
+ teamRead := db.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team)
req = NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamID)
resp = session.MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiTeam)
@@ -111,7 +112,7 @@ func TestAPITeam(t *testing.T) {
// Delete team.
req = NewRequestf(t, "DELETE", "/api/v1/teams/%d?token="+token, teamID)
session.MakeRequest(t, req, http.StatusNoContent)
- models.AssertNotExistsBean(t, &models.Team{ID: teamID})
+ db.AssertNotExistsBean(t, &models.Team{ID: teamID})
}
func checkTeamResponse(t *testing.T, apiTeam *api.Team, name, description string, includesAllRepositories bool, permission string, units []string) {
@@ -125,7 +126,7 @@ func checkTeamResponse(t *testing.T, apiTeam *api.Team, name, description string
}
func checkTeamBean(t *testing.T, id int64, name, description string, includesAllRepositories bool, permission string, units []string) {
- team := models.AssertExistsAndLoadBean(t, &models.Team{ID: id}).(*models.Team)
+ team := db.AssertExistsAndLoadBean(t, &models.Team{ID: id}).(*models.Team)
assert.NoError(t, team.GetUnits(), "GetUnits")
checkTeamResponse(t, convert.ToTeam(team), name, description, includesAllRepositories, permission, units)
}
@@ -138,8 +139,8 @@ type TeamSearchResults struct {
func TestAPITeamSearch(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- org := models.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ org := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
var results TeamSearchResults
@@ -154,7 +155,7 @@ func TestAPITeamSearch(t *testing.T) {
assert.Equal(t, "test_team", results.Data[0].Name)
// no access if not organization member
- user5 := models.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+ user5 := db.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
session = loginUser(t, user5.Name)
csrf = GetCSRF(t, session, "/"+org.Name)
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s", org.Name, "team")
diff --git a/integrations/api_team_user_test.go b/integrations/api_team_user_test.go
index 5a8fba512f..747227269c 100644
--- a/integrations/api_team_user_test.go
+++ b/integrations/api_team_user_test.go
@@ -10,6 +10,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -29,7 +30,7 @@ func TestAPITeamUser(t *testing.T) {
var user2 *api.User
DecodeJSON(t, resp, &user2)
user2.Created = user2.Created.In(time.Local)
- user := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
expectedUser := convert.ToUser(user, user)
diff --git a/integrations/api_token_test.go b/integrations/api_token_test.go
index 464b7ba38e..1a6d53547b 100644
--- a/integrations/api_token_test.go
+++ b/integrations/api_token_test.go
@@ -9,13 +9,14 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
)
// TestAPICreateAndDeleteToken tests that token that was just created can be deleted
func TestAPICreateAndDeleteToken(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
req := NewRequestWithJSON(t, "POST", "/api/v1/users/user1/tokens", map[string]string{
"name": "test-key-1",
@@ -25,7 +26,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
var newAccessToken api.AccessToken
DecodeJSON(t, resp, &newAccessToken)
- models.AssertExistsAndLoadBean(t, &models.AccessToken{
+ db.AssertExistsAndLoadBean(t, &models.AccessToken{
ID: newAccessToken.ID,
Name: newAccessToken.Name,
Token: newAccessToken.Token,
@@ -36,7 +37,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
req = AddBasicAuthHeader(req, user.Name)
MakeRequest(t, req, http.StatusNoContent)
- models.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID})
+ db.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID})
req = NewRequestWithJSON(t, "POST", "/api/v1/users/user1/tokens", map[string]string{
"name": "test-key-2",
@@ -49,15 +50,15 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
req = AddBasicAuthHeader(req, user.Name)
MakeRequest(t, req, http.StatusNoContent)
- models.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID})
+ db.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID})
}
// TestAPIDeleteMissingToken ensures that error is thrown when token not found
func TestAPIDeleteMissingToken(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
- req := NewRequestf(t, "DELETE", "/api/v1/users/user1/tokens/%d", models.NonexistentID)
+ req := NewRequestf(t, "DELETE", "/api/v1/users/user1/tokens/%d", db.NonexistentID)
req = AddBasicAuthHeader(req, user.Name)
MakeRequest(t, req, http.StatusNotFound)
}
diff --git a/integrations/api_user_orgs_test.go b/integrations/api_user_orgs_test.go
index c72ee76098..36b11335c0 100644
--- a/integrations/api_user_orgs_test.go
+++ b/integrations/api_user_orgs_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -24,7 +25,7 @@ func TestUserOrgs(t *testing.T) {
orgs := getUserOrgs(t, adminUsername, normalUsername)
- user3 := models.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
assert.Equal(t, []*api.Organization{
{
@@ -80,7 +81,7 @@ func TestMyOrgs(t *testing.T) {
resp = session.MakeRequest(t, req, http.StatusOK)
var orgs []*api.Organization
DecodeJSON(t, resp, &orgs)
- user3 := models.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
+ user3 := db.AssertExistsAndLoadBean(t, &models.User{Name: "user3"}).(*models.User)
assert.Equal(t, []*api.Organization{
{
diff --git a/integrations/api_user_search_test.go b/integrations/api_user_search_test.go
index f7349827e5..d6144d9e87 100644
--- a/integrations/api_user_search_test.go
+++ b/integrations/api_user_search_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -51,7 +52,7 @@ func TestAPIUserSearchNotLoggedIn(t *testing.T) {
var modelUser *models.User
for _, user := range results.Data {
assert.Contains(t, user.UserName, query)
- modelUser = models.AssertExistsAndLoadBean(t, &models.User{ID: user.ID}).(*models.User)
+ modelUser = db.AssertExistsAndLoadBean(t, &models.User{ID: user.ID}).(*models.User)
if modelUser.KeepEmailPrivate {
assert.EqualValues(t, fmt.Sprintf("%s@%s", modelUser.LowerName, setting.Service.NoReplyAddress), user.Email)
} else {
diff --git a/integrations/benchmarks_test.go b/integrations/benchmarks_test.go
index 841ecbf7ee..5df0d7b749 100644
--- a/integrations/benchmarks_test.go
+++ b/integrations/benchmarks_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
)
@@ -32,7 +33,7 @@ func BenchmarkRepoBranchCommit(b *testing.B) {
for _, repoID := range samples {
b.StopTimer()
- repo := models.AssertExistsAndLoadBean(b, &models.Repository{ID: repoID}).(*models.Repository)
+ repo := db.AssertExistsAndLoadBean(b, &models.Repository{ID: repoID}).(*models.Repository)
b.StartTimer()
b.Run(repo.Name, func(b *testing.B) {
session := loginUser(b, "user2")
diff --git a/integrations/change_default_branch_test.go b/integrations/change_default_branch_test.go
index dcd6d9b08b..d6a6664350 100644
--- a/integrations/change_default_branch_test.go
+++ b/integrations/change_default_branch_test.go
@@ -10,12 +10,13 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func TestChangeDefaultBranch(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
session := loginUser(t, owner.Name)
branchesURL := fmt.Sprintf("/%s/%s/settings/branches", owner.Name, repo.Name)
diff --git a/integrations/delete_user_test.go b/integrations/delete_user_test.go
index 86be6f22ad..f529734e19 100644
--- a/integrations/delete_user_test.go
+++ b/integrations/delete_user_test.go
@@ -10,18 +10,19 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func assertUserDeleted(t *testing.T, userID int64) {
- models.AssertNotExistsBean(t, &models.User{ID: userID})
- models.AssertNotExistsBean(t, &models.Follow{UserID: userID})
- models.AssertNotExistsBean(t, &models.Follow{FollowID: userID})
- models.AssertNotExistsBean(t, &models.Repository{OwnerID: userID})
- models.AssertNotExistsBean(t, &models.Access{UserID: userID})
- models.AssertNotExistsBean(t, &models.OrgUser{UID: userID})
- models.AssertNotExistsBean(t, &models.IssueUser{UID: userID})
- models.AssertNotExistsBean(t, &models.TeamUser{UID: userID})
- models.AssertNotExistsBean(t, &models.Star{UID: userID})
+ db.AssertNotExistsBean(t, &models.User{ID: userID})
+ db.AssertNotExistsBean(t, &models.Follow{UserID: userID})
+ db.AssertNotExistsBean(t, &models.Follow{FollowID: userID})
+ db.AssertNotExistsBean(t, &models.Repository{OwnerID: userID})
+ db.AssertNotExistsBean(t, &models.Access{UserID: userID})
+ db.AssertNotExistsBean(t, &models.OrgUser{UID: userID})
+ db.AssertNotExistsBean(t, &models.IssueUser{UID: userID})
+ db.AssertNotExistsBean(t, &models.TeamUser{UID: userID})
+ db.AssertNotExistsBean(t, &models.Star{UID: userID})
}
func TestUserDeleteAccount(t *testing.T) {
@@ -51,5 +52,5 @@ func TestUserDeleteAccountStillOwnRepos(t *testing.T) {
session.MakeRequest(t, req, http.StatusFound)
// user should not have been deleted, because the user still owns repos
- models.AssertExistsAndLoadBean(t, &models.User{ID: 2})
+ db.AssertExistsAndLoadBean(t, &models.User{ID: 2})
}
diff --git a/integrations/empty_repo_test.go b/integrations/empty_repo_test.go
index 77b8adf686..7346c34b27 100644
--- a/integrations/empty_repo_test.go
+++ b/integrations/empty_repo_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func TestEmptyRepo(t *testing.T) {
@@ -19,8 +20,8 @@ func TestEmptyRepo(t *testing.T) {
"commit/1ae57b34ccf7e18373",
"graph",
}
- emptyRepo := models.AssertExistsAndLoadBean(t, &models.Repository{}, models.Cond("is_empty = ?", true)).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: emptyRepo.OwnerID}).(*models.User)
+ emptyRepo := db.AssertExistsAndLoadBean(t, &models.Repository{}, db.Cond("is_empty = ?", true)).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: emptyRepo.OwnerID}).(*models.User)
for _, subpath := range subpaths {
req := NewRequestf(t, "GET", "/%s/%s/%s", owner.Name, emptyRepo.Name, subpath)
MakeRequest(t, req, http.StatusNotFound)
diff --git a/integrations/eventsource_test.go b/integrations/eventsource_test.go
index caaf8c2cef..17c5ff8ab4 100644
--- a/integrations/eventsource_test.go
+++ b/integrations/eventsource_test.go
@@ -11,6 +11,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/eventsource"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -49,9 +50,9 @@ func TestEventSourceManagerRun(t *testing.T) {
}
}
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- thread5 := models.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ thread5 := db.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification)
assert.NoError(t, thread5.LoadAttributes())
session := loginUser(t, user2.Name)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/git_test.go b/integrations/git_test.go
index caafd1122a..72e01d3753 100644
--- a/integrations/git_test.go
+++ b/integrations/git_test.go
@@ -18,6 +18,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/setting"
@@ -630,7 +631,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
return
}
- pullNum := models.GetCount(t, &models.PullRequest{})
+ pullNum := db.GetCount(t, &models.PullRequest{})
t.Run("CreateHeadBranch", doGitCreateBranch(dstPath, headBranch))
@@ -666,8 +667,8 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
if !assert.NoError(t, err) {
return
}
- models.AssertCount(t, &models.PullRequest{}, pullNum+1)
- pr1 = models.AssertExistsAndLoadBean(t, &models.PullRequest{
+ db.AssertCount(t, &models.PullRequest{}, pullNum+1)
+ pr1 = db.AssertExistsAndLoadBean(t, &models.PullRequest{
HeadRepoID: repo.ID,
Flow: models.PullRequestFlowAGit,
}).(*models.PullRequest)
@@ -687,8 +688,8 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
if !assert.NoError(t, err) {
return
}
- models.AssertCount(t, &models.PullRequest{}, pullNum+2)
- pr2 = models.AssertExistsAndLoadBean(t, &models.PullRequest{
+ db.AssertCount(t, &models.PullRequest{}, pullNum+2)
+ pr2 = db.AssertExistsAndLoadBean(t, &models.PullRequest{
HeadRepoID: repo.ID,
Index: pr1.Index + 1,
Flow: models.PullRequestFlowAGit,
@@ -740,7 +741,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
if !assert.NoError(t, err) {
return
}
- models.AssertCount(t, &models.PullRequest{}, pullNum+2)
+ db.AssertCount(t, &models.PullRequest{}, pullNum+2)
prMsg, err := doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr1.Index)(t)
if !assert.NoError(t, err) {
return
@@ -752,7 +753,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB
if !assert.NoError(t, err) {
return
}
- models.AssertCount(t, &models.PullRequest{}, pullNum+2)
+ db.AssertCount(t, &models.PullRequest{}, pullNum+2)
prMsg, err = doAPIGetPullRequest(*ctx, ctx.Username, ctx.Reponame, pr2.Index)(t)
if !assert.NoError(t, err) {
return
diff --git a/integrations/gpg_git_test.go b/integrations/gpg_git_test.go
index 8c78faf7d2..11d9a0e2a5 100644
--- a/integrations/gpg_git_test.go
+++ b/integrations/gpg_git_test.go
@@ -13,6 +13,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -60,7 +61,7 @@ func TestGPGGit(t *testing.T) {
setting.Repository.Signing.SigningKey = rootKeyID
setting.Repository.Signing.SigningName = "gitea"
setting.Repository.Signing.SigningEmail = "gitea@fake.local"
- user := models.AssertExistsAndLoadBean(t, &models.User{Name: username}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{Name: username}).(*models.User)
setting.Repository.Signing.InitialCommit = []string{"never"}
setting.Repository.Signing.CRUDActions = []string{"never"}
diff --git a/integrations/integration_test.go b/integrations/integration_test.go
index 1003f136dd..fac36320cf 100644
--- a/integrations/integration_test.go
+++ b/integrations/integration_test.go
@@ -25,6 +25,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
@@ -111,7 +112,7 @@ func TestMain(m *testing.M) {
}
}
- err := models.InitFixtures(
+ err := db.InitFixtures(
path.Join(filepath.Dir(setting.AppPath), "models/fixtures/"),
)
if err != nil {
@@ -247,7 +248,7 @@ func prepareTestEnv(t testing.TB, skip ...int) func() {
ourSkip += skip[0]
}
deferFn := PrintCurrentTest(t, ourSkip)
- assert.NoError(t, models.LoadFixtures())
+ assert.NoError(t, db.LoadFixtures())
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
@@ -524,7 +525,7 @@ func GetCSRF(t testing.TB, session *TestSession, urlStr string) string {
// within a single test this is required
func resetFixtures(t *testing.T) {
assert.NoError(t, queue.GetManager().FlushAll(context.Background(), -1))
- assert.NoError(t, models.LoadFixtures())
+ assert.NoError(t, db.LoadFixtures())
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
}
diff --git a/integrations/issue_test.go b/integrations/issue_test.go
index 9b1447bd8d..132f0822ab 100644
--- a/integrations/issue_test.go
+++ b/integrations/issue_test.go
@@ -14,6 +14,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/indexer/issues"
"code.gitea.io/gitea/modules/references"
"code.gitea.io/gitea/modules/setting"
@@ -35,7 +36,7 @@ func getIssue(t *testing.T, repoID int64, issueSelection *goquery.Selection) *mo
indexStr := href[strings.LastIndexByte(href, '/')+1:]
index, err := strconv.Atoi(indexStr)
assert.NoError(t, err, "Invalid issue href: %s", href)
- return models.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repoID, Index: int64(index)}).(*models.Issue)
+ return db.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repoID, Index: int64(index)}).(*models.Issue)
}
func assertMatch(t testing.TB, issue *models.Issue, keyword string) {
@@ -60,8 +61,8 @@ func TestNoLoginViewIssues(t *testing.T) {
func TestViewIssuesSortByType(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
session := loginUser(t, user.Name)
req := NewRequest(t, "GET", repo.RelLink()+"/issues?type=created_by")
@@ -69,10 +70,10 @@ func TestViewIssuesSortByType(t *testing.T) {
htmlDoc := NewHTMLParser(t, resp.Body)
issuesSelection := getIssuesSelection(t, htmlDoc)
- expectedNumIssues := models.GetCount(t,
+ expectedNumIssues := db.GetCount(t,
&models.Issue{RepoID: repo.ID, PosterID: user.ID},
- models.Cond("is_closed=?", false),
- models.Cond("is_pull=?", false),
+ db.Cond("is_closed=?", false),
+ db.Cond("is_pull=?", false),
)
if expectedNumIssues > setting.UI.IssuePagingNum {
expectedNumIssues = setting.UI.IssuePagingNum
@@ -88,8 +89,8 @@ func TestViewIssuesSortByType(t *testing.T) {
func TestViewIssuesKeyword(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{
RepoID: repo.ID,
Index: 1,
}).(*models.Issue)
@@ -235,7 +236,7 @@ func TestIssueCrossReference(t *testing.T) {
// Ref from issue title
issueRefURL, issueRef := testIssueWithBean(t, "user2", 1, fmt.Sprintf("Title ref #%d", issueBase.Index), "Description")
- models.AssertExistsAndLoadBean(t, &models.Comment{
+ db.AssertExistsAndLoadBean(t, &models.Comment{
IssueID: issueBase.ID,
RefRepoID: 1,
RefIssueID: issueRef.ID,
@@ -245,7 +246,7 @@ func TestIssueCrossReference(t *testing.T) {
// Edit title, neuter ref
testIssueChangeInfo(t, "user2", issueRefURL, "title", "Title no ref")
- models.AssertExistsAndLoadBean(t, &models.Comment{
+ db.AssertExistsAndLoadBean(t, &models.Comment{
IssueID: issueBase.ID,
RefRepoID: 1,
RefIssueID: issueRef.ID,
@@ -255,7 +256,7 @@ func TestIssueCrossReference(t *testing.T) {
// Ref from issue content
issueRefURL, issueRef = testIssueWithBean(t, "user2", 1, "TitleXRef", fmt.Sprintf("Description ref #%d", issueBase.Index))
- models.AssertExistsAndLoadBean(t, &models.Comment{
+ db.AssertExistsAndLoadBean(t, &models.Comment{
IssueID: issueBase.ID,
RefRepoID: 1,
RefIssueID: issueRef.ID,
@@ -265,7 +266,7 @@ func TestIssueCrossReference(t *testing.T) {
// Edit content, neuter ref
testIssueChangeInfo(t, "user2", issueRefURL, "content", "Description no ref")
- models.AssertExistsAndLoadBean(t, &models.Comment{
+ db.AssertExistsAndLoadBean(t, &models.Comment{
IssueID: issueBase.ID,
RefRepoID: 1,
RefIssueID: issueRef.ID,
@@ -283,11 +284,11 @@ func TestIssueCrossReference(t *testing.T) {
RefCommentID: commentID,
RefIsPull: false,
RefAction: references.XRefActionNone}
- models.AssertExistsAndLoadBean(t, comment)
+ db.AssertExistsAndLoadBean(t, comment)
// Ref from a different repository
issueRefURL, issueRef = testIssueWithBean(t, "user12", 10, "TitleXRef", fmt.Sprintf("Description ref user2/repo1#%d", issueBase.Index))
- models.AssertExistsAndLoadBean(t, &models.Comment{
+ db.AssertExistsAndLoadBean(t, &models.Comment{
IssueID: issueBase.ID,
RefRepoID: 10,
RefIssueID: issueRef.ID,
@@ -303,7 +304,7 @@ func testIssueWithBean(t *testing.T, user string, repoID int64, title, content s
index, err := strconv.Atoi(indexStr)
assert.NoError(t, err, "Invalid issue href: %s", issueURL)
issue := &models.Issue{RepoID: repoID, Index: int64(index)}
- models.AssertExistsAndLoadBean(t, issue)
+ db.AssertExistsAndLoadBean(t, issue)
return issueURL, issue
}
diff --git a/integrations/migrate_test.go b/integrations/migrate_test.go
index b0395fbc3d..e79be238d5 100644
--- a/integrations/migrate_test.go
+++ b/integrations/migrate_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/migrations"
"code.gitea.io/gitea/modules/setting"
@@ -17,9 +18,9 @@ import (
)
func TestMigrateLocalPath(t *testing.T) {
- assert.NoError(t, models.PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- adminUser := models.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
+ adminUser := db.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
old := setting.ImportLocalPaths
setting.ImportLocalPaths = true
diff --git a/integrations/migration-test/migration_test.go b/integrations/migration-test/migration_test.go
index 209ff5a058..66aca0ef70 100644
--- a/integrations/migration-test/migration_test.go
+++ b/integrations/migration-test/migration_test.go
@@ -19,7 +19,7 @@ import (
"testing"
"code.gitea.io/gitea/integrations"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/migrations"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/charset"
@@ -256,13 +256,13 @@ func doMigrationTest(t *testing.T, version string) {
setting.NewXORMLogService(false)
- err := models.NewEngine(context.Background(), wrappedMigrate)
+ err := db.NewEngine(context.Background(), wrappedMigrate)
assert.NoError(t, err)
currentEngine.Close()
- beans, _ := models.NamesToBean()
+ beans, _ := db.NamesToBean()
- err = models.NewEngine(context.Background(), func(x *xorm.Engine) error {
+ err = db.NewEngine(context.Background(), func(x *xorm.Engine) error {
currentEngine = x
return migrations.RecreateTables(beans...)(x)
})
@@ -270,7 +270,7 @@ func doMigrationTest(t *testing.T, version string) {
currentEngine.Close()
// We do this a second time to ensure that there is not a problem with retained indices
- err = models.NewEngine(context.Background(), func(x *xorm.Engine) error {
+ err = db.NewEngine(context.Background(), func(x *xorm.Engine) error {
currentEngine = x
return migrations.RecreateTables(beans...)(x)
})
diff --git a/integrations/mirror_pull_test.go b/integrations/mirror_pull_test.go
index 3908f35557..f396aac4b4 100644
--- a/integrations/mirror_pull_test.go
+++ b/integrations/mirror_pull_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
migration "code.gitea.io/gitea/modules/migrations/base"
"code.gitea.io/gitea/modules/repository"
@@ -21,8 +22,8 @@ import (
func TestMirrorPull(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repoPath := models.RepoPath(user.Name, repo.Name)
opts := migration.MigrateOptions{
diff --git a/integrations/mirror_push_test.go b/integrations/mirror_push_test.go
index 3191ef7704..3d2966cfdc 100644
--- a/integrations/mirror_push_test.go
+++ b/integrations/mirror_push_test.go
@@ -12,6 +12,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -29,8 +30,8 @@ func testMirrorPush(t *testing.T, u *url.URL) {
setting.Migrations.AllowLocalNetworks = true
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- srcRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ srcRepo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
mirrorRepo, err := repository.CreateRepository(user, user, models.CreateRepoOptions{
Name: "test-push-mirror",
diff --git a/integrations/org_count_test.go b/integrations/org_count_test.go
index 20917dc17e..bd64139b2f 100644
--- a/integrations/org_count_test.go
+++ b/integrations/org_count_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
)
@@ -110,7 +111,7 @@ func doCheckOrgCounts(username string, orgCounts map[string]int, strict bool, ca
}
return func(t *testing.T) {
- user := models.AssertExistsAndLoadBean(t, &models.User{
+ user := db.AssertExistsAndLoadBean(t, &models.User{
Name: username,
}).(*models.User)
diff --git a/integrations/privateactivity_test.go b/integrations/privateactivity_test.go
index 23c6a7e8cc..e7b618abd6 100644
--- a/integrations/privateactivity_test.go
+++ b/integrations/privateactivity_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -24,8 +25,8 @@ const privateActivityTestOtherUser = "user4"
// activity helpers
func testPrivateActivityDoSomethingForActionEntries(t *testing.T) {
- repoBefore := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repoBefore.OwnerID}).(*models.User)
+ repoBefore := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repoBefore.OwnerID}).(*models.User)
session := loginUser(t, privateActivityTestUser)
token := getTokenForLoggedInUser(t, session)
diff --git a/integrations/pull_merge_test.go b/integrations/pull_merge_test.go
index b4a3397a45..867817c2c2 100644
--- a/integrations/pull_merge_test.go
+++ b/integrations/pull_merge_test.go
@@ -17,6 +17,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -219,15 +220,15 @@ func TestCantMergeConflict(t *testing.T) {
session.MakeRequest(t, req, 201)
// Now this PR will be marked conflict - or at least a race will do - so drop down to pure code at this point...
- user1 := models.AssertExistsAndLoadBean(t, &models.User{
+ user1 := db.AssertExistsAndLoadBean(t, &models.User{
Name: "user1",
}).(*models.User)
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{
OwnerID: user1.ID,
Name: "repo1",
}).(*models.Repository)
- pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{
+ pr := db.AssertExistsAndLoadBean(t, &models.PullRequest{
HeadRepoID: repo1.ID,
BaseRepoID: repo1.ID,
HeadBranch: "conflict",
@@ -256,10 +257,10 @@ func TestCantMergeUnrelated(t *testing.T) {
// Now we want to create a commit on a branch that is totally unrelated to our current head
// Drop down to pure code at this point
- user1 := models.AssertExistsAndLoadBean(t, &models.User{
+ user1 := db.AssertExistsAndLoadBean(t, &models.User{
Name: "user1",
}).(*models.User)
- repo1 := models.AssertExistsAndLoadBean(t, &models.Repository{
+ repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{
OwnerID: user1.ID,
Name: "repo1",
}).(*models.Repository)
@@ -318,7 +319,7 @@ func TestCantMergeUnrelated(t *testing.T) {
// Now this PR could be marked conflict - or at least a race may occur - so drop down to pure code at this point...
gitRepo, err := git.OpenRepository(path)
assert.NoError(t, err)
- pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{
+ pr := db.AssertExistsAndLoadBean(t, &models.PullRequest{
HeadRepoID: repo1.ID,
BaseRepoID: repo1.ID,
HeadBranch: "unrelated",
diff --git a/integrations/pull_update_test.go b/integrations/pull_update_test.go
index 3e3b987b64..ea3a4794a6 100644
--- a/integrations/pull_update_test.go
+++ b/integrations/pull_update_test.go
@@ -11,6 +11,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/repofiles"
repo_module "code.gitea.io/gitea/modules/repository"
pull_service "code.gitea.io/gitea/services/pull"
@@ -22,8 +23,8 @@ import (
func TestAPIPullUpdate(t *testing.T) {
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
//Create PR to test
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- org26 := models.AssertExistsAndLoadBean(t, &models.User{ID: 26}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ org26 := db.AssertExistsAndLoadBean(t, &models.User{ID: 26}).(*models.User)
pr := createOutdatedPR(t, user, org26)
//Test GetDiverging
@@ -50,8 +51,8 @@ func TestAPIPullUpdate(t *testing.T) {
func TestAPIPullUpdateByRebase(t *testing.T) {
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
//Create PR to test
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- org26 := models.AssertExistsAndLoadBean(t, &models.User{ID: 26}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ org26 := db.AssertExistsAndLoadBean(t, &models.User{ID: 26}).(*models.User)
pr := createOutdatedPR(t, user, org26)
//Test GetDiverging
@@ -162,7 +163,7 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *models.User) *models.PullReq
err = pull_service.NewPullRequest(baseRepo, pullIssue, nil, nil, pullRequest, nil)
assert.NoError(t, err)
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{Title: "Test Pull -to-update-"}).(*models.Issue)
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{Title: "Test Pull -to-update-"}).(*models.Issue)
pr, err := models.GetPullRequestByIssueID(issue.ID)
assert.NoError(t, err)
diff --git a/integrations/release_test.go b/integrations/release_test.go
index 4458387ef7..2e9de31699 100644
--- a/integrations/release_test.go
+++ b/integrations/release_test.go
@@ -11,6 +11,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
@@ -133,7 +134,7 @@ func TestCreateReleasePaging(t *testing.T) {
func TestViewReleaseListNoLogin(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
link := repo.Link() + "/releases"
@@ -159,7 +160,7 @@ func TestViewReleaseListNoLogin(t *testing.T) {
func TestViewReleaseListLogin(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
link := repo.Link() + "/releases"
@@ -190,7 +191,7 @@ func TestViewReleaseListLogin(t *testing.T) {
func TestViewTagsList(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
link := repo.Link() + "/tags"
diff --git a/integrations/repo_fork_test.go b/integrations/repo_fork_test.go
index d0542c1a72..f9a994fd8e 100644
--- a/integrations/repo_fork_test.go
+++ b/integrations/repo_fork_test.go
@@ -11,12 +11,13 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkOwnerName, forkRepoName string) *httptest.ResponseRecorder {
- forkOwner := models.AssertExistsAndLoadBean(t, &models.User{Name: forkOwnerName}).(*models.User)
+ forkOwner := db.AssertExistsAndLoadBean(t, &models.User{Name: forkOwnerName}).(*models.User)
// Step0: check the existence of the to-fork repo
req := NewRequestf(t, "GET", "/%s/%s", forkOwnerName, forkRepoName)
diff --git a/integrations/repo_generate_test.go b/integrations/repo_generate_test.go
index 1aa91236ea..7afce7474a 100644
--- a/integrations/repo_generate_test.go
+++ b/integrations/repo_generate_test.go
@@ -11,12 +11,13 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
func testRepoGenerate(t *testing.T, session *TestSession, templateOwnerName, templateRepoName, generateOwnerName, generateRepoName string) *httptest.ResponseRecorder {
- generateOwner := models.AssertExistsAndLoadBean(t, &models.User{Name: generateOwnerName}).(*models.User)
+ generateOwner := db.AssertExistsAndLoadBean(t, &models.User{Name: generateOwnerName}).(*models.User)
// Step0: check the existence of the generated repo
req := NewRequestf(t, "GET", "/%s/%s", generateOwnerName, generateRepoName)
diff --git a/integrations/repo_tag_test.go b/integrations/repo_tag_test.go
index eb3f2b47fb..05505a644d 100644
--- a/integrations/repo_tag_test.go
+++ b/integrations/repo_tag_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/release"
@@ -20,8 +21,8 @@ import (
func TestCreateNewTagProtected(t *testing.T) {
defer prepareTestEnv(t)()
- repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
t.Run("API", func(t *testing.T) {
defer PrintCurrentTest(t)()
diff --git a/integrations/repo_watch_test.go b/integrations/repo_watch_test.go
index d96b014a73..7ae9f1fe7f 100644
--- a/integrations/repo_watch_test.go
+++ b/integrations/repo_watch_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
)
@@ -17,8 +18,8 @@ func TestRepoWatch(t *testing.T) {
// Test round-trip auto-watch
setting.Service.AutoWatchOnChanges = true
session := loginUser(t, "user2")
- models.AssertNotExistsBean(t, &models.Watch{UserID: 2, RepoID: 3})
+ db.AssertNotExistsBean(t, &models.Watch{UserID: 2, RepoID: 3})
testEditFile(t, session, "user3", "repo3", "master", "README.md", "Hello, World (Edited for watch)\n")
- models.AssertExistsAndLoadBean(t, &models.Watch{UserID: 2, RepoID: 3, Mode: models.RepoWatchModeAuto})
+ db.AssertExistsAndLoadBean(t, &models.Watch{UserID: 2, RepoID: 3, Mode: models.RepoWatchModeAuto})
})
}
diff --git a/integrations/repofiles_delete_test.go b/integrations/repofiles_delete_test.go
index 1fa316c41e..22fef4b03e 100644
--- a/integrations/repofiles_delete_test.go
+++ b/integrations/repofiles_delete_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/repofiles"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -66,7 +67,7 @@ func TestDeleteRepoFile(t *testing.T) {
func testDeleteRepoFile(t *testing.T, u *url.URL) {
// setup
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -105,7 +106,7 @@ func TestDeleteRepoFileWithoutBranchNames(t *testing.T) {
func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) {
// setup
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -135,7 +136,7 @@ func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) {
func TestDeleteRepoFileErrors(t *testing.T) {
// setup
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
diff --git a/integrations/signin_test.go b/integrations/signin_test.go
index 390bf6408b..081f87f0bd 100644
--- a/integrations/signin_test.go
+++ b/integrations/signin_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
"github.com/unknwon/i18n"
@@ -33,13 +34,13 @@ func testLoginFailed(t *testing.T, username, password, message string) {
func TestSignin(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// add new user with user2's email
user.Name = "testuser"
user.LowerName = strings.ToLower(user.Name)
user.ID = 0
- models.AssertSuccessfulInsert(t, user)
+ db.AssertSuccessfulInsert(t, user)
samples := []struct {
username string
diff --git a/integrations/signup_test.go b/integrations/signup_test.go
index 66ff8ac2d7..dccb1f6767 100644
--- a/integrations/signup_test.go
+++ b/integrations/signup_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
"github.com/unknwon/i18n"
@@ -52,7 +53,7 @@ func TestSignupAsRestricted(t *testing.T) {
req = NewRequest(t, "GET", "/restrictedUser")
MakeRequest(t, req, http.StatusOK)
- user2 := models.AssertExistsAndLoadBean(t, &models.User{Name: "restrictedUser"}).(*models.User)
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{Name: "restrictedUser"}).(*models.User)
assert.True(t, user2.IsRestricted)
}
diff --git a/integrations/user_avatar_test.go b/integrations/user_avatar_test.go
index 1a3a851281..c909fd6851 100644
--- a/integrations/user_avatar_test.go
+++ b/integrations/user_avatar_test.go
@@ -15,13 +15,14 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/avatar"
"github.com/stretchr/testify/assert"
)
func TestUserAvatar(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
- user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo3, is an org
+ user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo3, is an org
seed := user2.Email
if len(seed) == 0 {
@@ -71,7 +72,7 @@ func TestUserAvatar(t *testing.T) {
session.MakeRequest(t, req, http.StatusFound)
- user2 = models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo3, is an org
+ user2 = db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo3, is an org
req = NewRequest(t, "GET", user2.AvatarLink())
resp := session.MakeRequest(t, req, http.StatusFound)
diff --git a/integrations/user_test.go b/integrations/user_test.go
index 199d5e242f..f9e507afbe 100644
--- a/integrations/user_test.go
+++ b/integrations/user_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/test"
"github.com/stretchr/testify/assert"
@@ -34,8 +35,8 @@ func TestRenameUsername(t *testing.T) {
})
session.MakeRequest(t, req, http.StatusFound)
- models.AssertExistsAndLoadBean(t, &models.User{Name: "newUsername"})
- models.AssertNotExistsBean(t, &models.User{Name: "user2"})
+ db.AssertExistsAndLoadBean(t, &models.User{Name: "newUsername"})
+ db.AssertNotExistsBean(t, &models.User{Name: "user2"})
}
func TestRenameInvalidUsername(t *testing.T) {
@@ -66,7 +67,7 @@ func TestRenameInvalidUsername(t *testing.T) {
i18n.Tr("en", "form.alpha_dash_dot_error"),
)
- models.AssertNotExistsBean(t, &models.User{Name: invalidUsername})
+ db.AssertNotExistsBean(t, &models.User{Name: invalidUsername})
}
}
@@ -112,7 +113,7 @@ func TestRenameReservedUsername(t *testing.T) {
i18n.Tr("en", "user.form.name_reserved", reservedUsername),
)
- models.AssertNotExistsBean(t, &models.User{Name: reservedUsername})
+ db.AssertNotExistsBean(t, &models.User{Name: reservedUsername})
}
}
diff --git a/integrations/xss_test.go b/integrations/xss_test.go
index 2d83e1e106..427c97de26 100644
--- a/integrations/xss_test.go
+++ b/integrations/xss_test.go
@@ -9,13 +9,14 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
func TestXSSUserFullName(t *testing.T) {
defer prepareTestEnv(t)()
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
const fullName = `name & <script class="evil">alert('Oh no!');</script>`
session := loginUser(t, user.Name)