1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

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
335 changed files with 4191 additions and 3654 deletions

View File

@@ -10,6 +10,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/setting"
"code.gitea.io/gitea/modules/test"
@@ -42,7 +43,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) {
} else {
return
}
models.PrepareTestEnv(t)
db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/settings/keys")
@@ -57,7 +58,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) {
DeployKeysPost(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
models.AssertExistsAndLoadBean(t, &models.DeployKey{
db.AssertExistsAndLoadBean(t, &models.DeployKey{
Name: addKeyForm.Title,
Content: addKeyForm.Content,
Mode: models.AccessModeRead,
@@ -71,7 +72,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) {
return
}
models.PrepareTestEnv(t)
db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/settings/keys")
@@ -87,7 +88,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) {
DeployKeysPost(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
models.AssertExistsAndLoadBean(t, &models.DeployKey{
db.AssertExistsAndLoadBean(t, &models.DeployKey{
Name: addKeyForm.Title,
Content: addKeyForm.Content,
Mode: models.AccessModeWrite,
@@ -96,7 +97,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) {
func TestCollaborationPost(t *testing.T) {
models.PrepareTestEnv(t)
db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/issues/labels")
test.LoadUser(t, ctx, 2)
test.LoadUser(t, ctx, 4)
@@ -132,7 +133,7 @@ func TestCollaborationPost(t *testing.T) {
func TestCollaborationPost_InactiveUser(t *testing.T) {
models.PrepareTestEnv(t)
db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/issues/labels")
test.LoadUser(t, ctx, 2)
test.LoadUser(t, ctx, 9)
@@ -156,7 +157,7 @@ func TestCollaborationPost_InactiveUser(t *testing.T) {
func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) {
models.PrepareTestEnv(t)
db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/issues/labels")
test.LoadUser(t, ctx, 2)
test.LoadUser(t, ctx, 4)
@@ -198,7 +199,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) {
func TestCollaborationPost_NonExistentUser(t *testing.T) {
models.PrepareTestEnv(t)
db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/issues/labels")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
@@ -220,7 +221,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) {
}
func TestAddTeamPost(t *testing.T) {
models.PrepareTestEnv(t)
db.PrepareTestEnv(t)
ctx := test.MockContext(t, "org26/repo43")
ctx.Req.Form.Set("team", "team11")
@@ -260,7 +261,7 @@ func TestAddTeamPost(t *testing.T) {
}
func TestAddTeamPost_NotAllowed(t *testing.T) {
models.PrepareTestEnv(t)
db.PrepareTestEnv(t)
ctx := test.MockContext(t, "org26/repo43")
ctx.Req.Form.Set("team", "team11")
@@ -301,7 +302,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) {
}
func TestAddTeamPost_AddTeamTwice(t *testing.T) {
models.PrepareTestEnv(t)
db.PrepareTestEnv(t)
ctx := test.MockContext(t, "org26/repo43")
ctx.Req.Form.Set("team", "team11")
@@ -342,7 +343,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) {
}
func TestAddTeamPost_NonExistentTeam(t *testing.T) {
models.PrepareTestEnv(t)
db.PrepareTestEnv(t)
ctx := test.MockContext(t, "org26/repo43")
ctx.Req.Form.Set("team", "team-non-existent")
@@ -375,7 +376,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) {
}
func TestDeleteTeam(t *testing.T) {
models.PrepareTestEnv(t)
db.PrepareTestEnv(t)
ctx := test.MockContext(t, "org3/team1/repo3")
ctx.Req.Form.Set("id", "2")