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>
This commit is contained in:
Lunny Xiao 2021-09-19 19:49:59 +08:00 committed by GitHub
parent 462306e263
commit a4bfef265d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
335 changed files with 4191 additions and 3654 deletions

View file

@ -8,6 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
@ -23,16 +24,16 @@ func TestIssue_AddLabels(t *testing.T) {
{2, []int64{}, 1}, // pull-request, empty
}
for _, test := range tests {
assert.NoError(t, models.PrepareTestDatabase())
issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
assert.NoError(t, db.PrepareTestDatabase())
issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
labels := make([]*models.Label, len(test.labelIDs))
for i, labelID := range test.labelIDs {
labels[i] = models.AssertExistsAndLoadBean(t, &models.Label{ID: labelID}).(*models.Label)
labels[i] = db.AssertExistsAndLoadBean(t, &models.Label{ID: labelID}).(*models.Label)
}
doer := models.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
doer := db.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
assert.NoError(t, AddLabels(issue, doer, labels))
for _, labelID := range test.labelIDs {
models.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: labelID})
db.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: labelID})
}
}
}
@ -49,11 +50,11 @@ func TestIssue_AddLabel(t *testing.T) {
{2, 1, 2}, // pull-request, already-added label
}
for _, test := range tests {
assert.NoError(t, models.PrepareTestDatabase())
issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
label := models.AssertExistsAndLoadBean(t, &models.Label{ID: test.labelID}).(*models.Label)
doer := models.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
assert.NoError(t, db.PrepareTestDatabase())
issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
label := db.AssertExistsAndLoadBean(t, &models.Label{ID: test.labelID}).(*models.Label)
doer := db.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
assert.NoError(t, AddLabel(issue, doer, label))
models.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
db.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
}
}