summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/hook_test.go7
-rw-r--r--routers/api/v1/repo/main_test.go4
-rw-r--r--routers/api/v1/repo/repo_test.go13
-rw-r--r--routers/common/db.go6
-rw-r--r--routers/install/install.go3
-rw-r--r--routers/web/admin/main_test.go4
-rw-r--r--routers/web/admin/users_test.go21
-rw-r--r--routers/web/org/org_labels.go3
-rw-r--r--routers/web/repo/editor_test.go8
-rw-r--r--routers/web/repo/issue_label.go3
-rw-r--r--routers/web/repo/issue_label_test.go31
-rw-r--r--routers/web/repo/main_test.go4
-rw-r--r--routers/web/repo/projects_test.go4
-rw-r--r--routers/web/repo/release_test.go7
-rw-r--r--routers/web/repo/repo.go9
-rw-r--r--routers/web/repo/settings_test.go27
-rw-r--r--routers/web/repo/wiki_test.go19
-rw-r--r--routers/web/user/auth.go3
-rw-r--r--routers/web/user/home_test.go11
-rw-r--r--routers/web/user/main_test.go4
-rw-r--r--routers/web/user/oauth_test.go5
-rw-r--r--routers/web/user/setting/account_test.go4
-rw-r--r--routers/web/user/setting/main_test.go4
23 files changed, 109 insertions, 95 deletions
diff --git a/routers/api/v1/repo/hook_test.go b/routers/api/v1/repo/hook_test.go
index 8ed4bc4b0c..79b8ec171c 100644
--- a/routers/api/v1/repo/hook_test.go
+++ b/routers/api/v1/repo/hook_test.go
@@ -9,6 +9,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/test"
@@ -16,7 +17,7 @@ import (
)
func TestTestHook(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/_pages")
ctx.SetParams(":id", "1")
@@ -26,8 +27,8 @@ func TestTestHook(t *testing.T) {
TestHook(&context.APIContext{Context: ctx, Org: nil})
assert.EqualValues(t, http.StatusNoContent, ctx.Resp.Status())
- models.AssertExistsAndLoadBean(t, &models.HookTask{
+ db.AssertExistsAndLoadBean(t, &models.HookTask{
RepoID: 1,
HookID: 1,
- }, models.Cond("is_delivered=?", false))
+ }, db.Cond("is_delivered=?", false))
}
diff --git a/routers/api/v1/repo/main_test.go b/routers/api/v1/repo/main_test.go
index 656758ffba..7a66370e05 100644
--- a/routers/api/v1/repo/main_test.go
+++ b/routers/api/v1/repo/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func TestMain(m *testing.M) {
- models.MainTest(m, filepath.Join("..", "..", "..", ".."))
+ db.MainTest(m, filepath.Join("..", "..", "..", ".."))
}
diff --git a/routers/api/v1/repo/repo_test.go b/routers/api/v1/repo/repo_test.go
index a1bd3e85d7..e4fd4f9424 100644
--- a/routers/api/v1/repo/repo_test.go
+++ b/routers/api/v1/repo/repo_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -18,7 +19,7 @@ import (
)
func TestRepoEdit(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
test.LoadRepo(t, ctx, 1)
@@ -59,13 +60,13 @@ func TestRepoEdit(t *testing.T) {
Edit(apiCtx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- models.AssertExistsAndLoadBean(t, &models.Repository{
+ db.AssertExistsAndLoadBean(t, &models.Repository{
ID: 1,
- }, models.Cond("name = ? AND is_archived = 1", *opts.Name))
+ }, db.Cond("name = ? AND is_archived = 1", *opts.Name))
}
func TestRepoEditNameChange(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
test.LoadRepo(t, ctx, 1)
@@ -81,7 +82,7 @@ func TestRepoEditNameChange(t *testing.T) {
Edit(apiCtx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- models.AssertExistsAndLoadBean(t, &models.Repository{
+ db.AssertExistsAndLoadBean(t, &models.Repository{
ID: 1,
- }, models.Cond("name = ?", opts.Name))
+ }, db.Cond("name = ?", opts.Name))
}
diff --git a/routers/common/db.go b/routers/common/db.go
index 069a46f64f..e5848796fb 100644
--- a/routers/common/db.go
+++ b/routers/common/db.go
@@ -9,7 +9,7 @@ import (
"fmt"
"time"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/migrations"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -25,7 +25,7 @@ func InitDBEngine(ctx context.Context) (err error) {
default:
}
log.Info("ORM engine initialization attempt #%d/%d...", i+1, setting.Database.DBConnectRetries)
- if err = models.NewEngine(ctx, migrations.Migrate); err == nil {
+ if err = db.NewEngine(ctx, migrations.Migrate); err == nil {
break
} else if i == setting.Database.DBConnectRetries-1 {
return err
@@ -34,6 +34,6 @@ func InitDBEngine(ctx context.Context) (err error) {
log.Info("Backing off for %d seconds", int64(setting.Database.DBConnectBackoff/time.Second))
time.Sleep(setting.Database.DBConnectBackoff)
}
- models.HasEngine = true
+ db.HasEngine = true
return nil
}
diff --git a/routers/install/install.go b/routers/install/install.go
index ad985cf184..8143ad8089 100644
--- a/routers/install/install.go
+++ b/routers/install/install.go
@@ -15,6 +15,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/context"
"code.gitea.io/gitea/modules/generate"
@@ -207,7 +208,7 @@ func SubmitInstall(ctx *context.Context) {
}
// Set test engine.
- if err = models.NewTestEngine(); err != nil {
+ if err = db.NewTestEngine(); err != nil {
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
ctx.Data["Err_DbType"] = true
ctx.RenderWithErr(ctx.Tr("install.sqlite3_not_available", "https://docs.gitea.io/en-us/install-from-binary/"), tplInstall, &form)
diff --git a/routers/web/admin/main_test.go b/routers/web/admin/main_test.go
index 352907c737..cfdefdb1b4 100644
--- a/routers/web/admin/main_test.go
+++ b/routers/web/admin/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func TestMain(m *testing.M) {
- models.MainTest(m, filepath.Join("..", "..", ".."))
+ db.MainTest(m, filepath.Join("..", "..", ".."))
}
diff --git a/routers/web/admin/users_test.go b/routers/web/admin/users_test.go
index 3d0b11a774..022d8f662c 100644
--- a/routers/web/admin/users_test.go
+++ b/routers/web/admin/users_test.go
@@ -8,6 +8,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/test"
@@ -19,10 +20,10 @@ import (
func TestNewUserPost_MustChangePassword(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := models.AssertExistsAndLoadBean(t, &models.User{
+ u := db.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -56,10 +57,10 @@ func TestNewUserPost_MustChangePassword(t *testing.T) {
}
func TestNewUserPost_MustChangePasswordFalse(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := models.AssertExistsAndLoadBean(t, &models.User{
+ u := db.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -93,10 +94,10 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) {
}
func TestNewUserPost_InvalidEmail(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := models.AssertExistsAndLoadBean(t, &models.User{
+ u := db.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -123,10 +124,10 @@ func TestNewUserPost_InvalidEmail(t *testing.T) {
}
func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := models.AssertExistsAndLoadBean(t, &models.User{
+ u := db.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -161,10 +162,10 @@ func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) {
}
func TestNewUserPost_VisibilityPrivate(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := models.AssertExistsAndLoadBean(t, &models.User{
+ u := db.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
diff --git a/routers/web/org/org_labels.go b/routers/web/org/org_labels.go
index 97a5437c61..17509c50fe 100644
--- a/routers/web/org/org_labels.go
+++ b/routers/web/org/org_labels.go
@@ -8,6 +8,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
@@ -98,7 +99,7 @@ func InitializeLabels(ctx *context.Context) {
return
}
- if err := models.InitializeLabels(models.DefaultDBContext(), ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
+ if err := models.InitializeLabels(db.DefaultContext(), ctx.Org.Organization.ID, form.TemplateName, true); err != nil {
if models.IsErrIssueLabelTemplateLoad(err) {
originalErr := err.(models.ErrIssueLabelTemplateLoad).OriginalError
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))
diff --git a/routers/web/repo/editor_test.go b/routers/web/repo/editor_test.go
index ec7aee1e77..8ab1fe1ee8 100644
--- a/routers/web/repo/editor_test.go
+++ b/routers/web/repo/editor_test.go
@@ -7,7 +7,7 @@ package repo
import (
"testing"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/test"
@@ -15,7 +15,7 @@ import (
)
func TestCleanUploadName(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
var kases = map[string]string{
".git/refs/master": "",
@@ -41,7 +41,7 @@ func TestCleanUploadName(t *testing.T) {
}
func TestGetUniquePatchBranchName(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -56,7 +56,7 @@ func TestGetUniquePatchBranchName(t *testing.T) {
}
func TestGetClosestParentWithFiles(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
diff --git a/routers/web/repo/issue_label.go b/routers/web/repo/issue_label.go
index abb529649a..daed302dca 100644
--- a/routers/web/repo/issue_label.go
+++ b/routers/web/repo/issue_label.go
@@ -8,6 +8,7 @@ import (
"net/http"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -38,7 +39,7 @@ func InitializeLabels(ctx *context.Context) {
return
}
- if err := models.InitializeLabels(models.DefaultDBContext(), ctx.Repo.Repository.ID, form.TemplateName, false); err != nil {
+ if err := models.InitializeLabels(db.DefaultContext(), ctx.Repo.Repository.ID, form.TemplateName, false); err != nil {
if models.IsErrIssueLabelTemplateLoad(err) {
originalErr := err.(models.ErrIssueLabelTemplateLoad).OriginalError
ctx.Flash.Error(ctx.Tr("repo.issues.label_templates.fail_to_load_file", form.TemplateName, originalErr))
diff --git a/routers/web/repo/issue_label_test.go b/routers/web/repo/issue_label_test.go
index bf9e72a6f4..8c3caabe17 100644
--- a/routers/web/repo/issue_label_test.go
+++ b/routers/web/repo/issue_label_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
@@ -29,14 +30,14 @@ func int64SliceToCommaSeparated(a []int64) string {
}
func TestInitializeLabels(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/labels/initialize")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 2)
web.SetForm(ctx, &forms.InitializeLabelsForm{TemplateName: "Default"})
InitializeLabels(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- models.AssertExistsAndLoadBean(t, &models.Label{
+ db.AssertExistsAndLoadBean(t, &models.Label{
RepoID: 2,
Name: "enhancement",
Color: "#84b6eb",
@@ -45,7 +46,7 @@ func TestInitializeLabels(t *testing.T) {
}
func TestRetrieveLabels(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
for _, testCase := range []struct {
RepoID int64
Sort string
@@ -72,7 +73,7 @@ func TestRetrieveLabels(t *testing.T) {
}
func TestNewLabel(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/labels/edit")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
@@ -82,7 +83,7 @@ func TestNewLabel(t *testing.T) {
})
NewLabel(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- models.AssertExistsAndLoadBean(t, &models.Label{
+ db.AssertExistsAndLoadBean(t, &models.Label{
Name: "newlabel",
Color: "#abcdef",
})
@@ -90,7 +91,7 @@ func TestNewLabel(t *testing.T) {
}
func TestUpdateLabel(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/labels/edit")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
@@ -101,7 +102,7 @@ func TestUpdateLabel(t *testing.T) {
})
UpdateLabel(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- models.AssertExistsAndLoadBean(t, &models.Label{
+ db.AssertExistsAndLoadBean(t, &models.Label{
ID: 2,
Name: "newnameforlabel",
Color: "#abcdef",
@@ -110,20 +111,20 @@ func TestUpdateLabel(t *testing.T) {
}
func TestDeleteLabel(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/labels/delete")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
ctx.Req.Form.Set("id", "2")
DeleteLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- models.AssertNotExistsBean(t, &models.Label{ID: 2})
- models.AssertNotExistsBean(t, &models.IssueLabel{LabelID: 2})
+ db.AssertNotExistsBean(t, &models.Label{ID: 2})
+ db.AssertNotExistsBean(t, &models.IssueLabel{LabelID: 2})
assert.Equal(t, ctx.Tr("repo.issues.label_deletion_success"), ctx.Flash.SuccessMsg)
}
func TestUpdateIssueLabel_Clear(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)
@@ -131,8 +132,8 @@ func TestUpdateIssueLabel_Clear(t *testing.T) {
ctx.Req.Form.Set("action", "clear")
UpdateIssueLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- models.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 1})
- models.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 3})
+ db.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 1})
+ db.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 3})
models.CheckConsistencyFor(t, &models.Label{})
}
@@ -148,7 +149,7 @@ func TestUpdateIssueLabel_Toggle(t *testing.T) {
{"toggle", []int64{1, 3}, 1, false},
{"toggle", []int64{1, 2}, 2, true},
} {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/issues/labels")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
@@ -158,7 +159,7 @@ func TestUpdateIssueLabel_Toggle(t *testing.T) {
UpdateIssueLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
for _, issueID := range testCase.IssueIDs {
- models.AssertExistsIf(t, testCase.ExpectedAdd, &models.IssueLabel{
+ db.AssertExistsIf(t, testCase.ExpectedAdd, &models.IssueLabel{
IssueID: issueID,
LabelID: testCase.LabelID,
})
diff --git a/routers/web/repo/main_test.go b/routers/web/repo/main_test.go
index 47f266365f..8322567249 100644
--- a/routers/web/repo/main_test.go
+++ b/routers/web/repo/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func TestMain(m *testing.M) {
- models.MainTest(m, filepath.Join("..", "..", ".."))
+ db.MainTest(m, filepath.Join("..", "..", ".."))
}
diff --git a/routers/web/repo/projects_test.go b/routers/web/repo/projects_test.go
index c43cf6d952..d3b78cc775 100644
--- a/routers/web/repo/projects_test.go
+++ b/routers/web/repo/projects_test.go
@@ -7,14 +7,14 @@ package repo
import (
"testing"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/test"
"github.com/stretchr/testify/assert"
)
func TestCheckProjectBoardChangePermissions(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/projects/1/2")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
diff --git a/routers/web/repo/release_test.go b/routers/web/repo/release_test.go
index 004a6ef540..7ac49c012f 100644
--- a/routers/web/repo/release_test.go
+++ b/routers/web/repo/release_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
@@ -43,7 +44,7 @@ func TestNewReleasePost(t *testing.T) {
},
},
} {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/releases/new")
test.LoadUser(t, ctx, 2)
@@ -51,14 +52,14 @@ func TestNewReleasePost(t *testing.T) {
test.LoadGitRepo(t, ctx)
web.SetForm(ctx, &testCase.Form)
NewReleasePost(ctx)
- models.AssertExistsAndLoadBean(t, &models.Release{
+ db.AssertExistsAndLoadBean(t, &models.Release{
RepoID: 1,
PublisherID: 2,
TagName: testCase.Form.TagName,
Target: testCase.Form.Target,
Title: testCase.Form.Title,
Note: testCase.Form.Content,
- }, models.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
+ }, db.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
ctx.Repo.GitRepo.Close()
}
}
diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go
index 98f60c6b59..46a80524ed 100644
--- a/routers/web/repo/repo.go
+++ b/routers/web/repo/repo.go
@@ -13,6 +13,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/context"
"code.gitea.io/gitea/modules/graceful"
@@ -342,7 +343,7 @@ func RedirectDownload(ctx *context.Context) {
)
tagNames := []string{vTag}
curRepo := ctx.Repo.Repository
- releases, err := models.GetReleasesByRepoIDAndNames(models.DefaultDBContext(), curRepo.ID, tagNames)
+ releases, err := models.GetReleasesByRepoIDAndNames(db.DefaultContext(), curRepo.ID, tagNames)
if err != nil {
if models.IsErrAttachmentNotExist(err) {
ctx.Error(http.StatusNotFound)
@@ -379,7 +380,7 @@ func Download(ctx *context.Context) {
return
}
- archiver, err := models.GetRepoArchiver(models.DefaultDBContext(), aReq.RepoID, aReq.Type, aReq.CommitID)
+ archiver, err := models.GetRepoArchiver(db.DefaultContext(), aReq.RepoID, aReq.Type, aReq.CommitID)
if err != nil {
ctx.ServerError("models.GetRepoArchiver", err)
return
@@ -409,7 +410,7 @@ func Download(ctx *context.Context) {
return
}
times++
- archiver, err = models.GetRepoArchiver(models.DefaultDBContext(), aReq.RepoID, aReq.Type, aReq.CommitID)
+ archiver, err = models.GetRepoArchiver(db.DefaultContext(), aReq.RepoID, aReq.Type, aReq.CommitID)
if err != nil {
ctx.ServerError("archiver_service.StartArchive", err)
return
@@ -465,7 +466,7 @@ func InitiateDownload(ctx *context.Context) {
return
}
- archiver, err := models.GetRepoArchiver(models.DefaultDBContext(), aReq.RepoID, aReq.Type, aReq.CommitID)
+ archiver, err := models.GetRepoArchiver(db.DefaultContext(), aReq.RepoID, aReq.Type, aReq.CommitID)
if err != nil {
ctx.ServerError("archiver_service.StartArchive", err)
return
diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go
index 5190f12d5d..f9986e44ed 100644
--- a/routers/web/repo/settings_test.go
+++ b/routers/web/repo/settings_test.go
@@ -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")
diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go
index bcdb8023ac..df565487f1 100644
--- a/routers/web/repo/wiki_test.go
+++ b/routers/web/repo/wiki_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/test"
"code.gitea.io/gitea/modules/web"
@@ -73,7 +74,7 @@ func assertPagesMetas(t *testing.T, expectedNames []string, metas interface{}) {
}
func TestWiki(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/_pages")
ctx.SetParams(":page", "Home")
@@ -85,7 +86,7 @@ func TestWiki(t *testing.T) {
}
func TestWikiPages(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/_pages")
test.LoadRepo(t, ctx, 1)
@@ -95,7 +96,7 @@ func TestWikiPages(t *testing.T) {
}
func TestNewWiki(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/_new")
test.LoadUser(t, ctx, 2)
@@ -110,7 +111,7 @@ func TestNewWikiPost(t *testing.T) {
"New page",
"&&&&",
} {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/_new")
test.LoadUser(t, ctx, 2)
@@ -128,7 +129,7 @@ func TestNewWikiPost(t *testing.T) {
}
func TestNewWikiPost_ReservedName(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/_new")
test.LoadUser(t, ctx, 2)
@@ -145,7 +146,7 @@ func TestNewWikiPost_ReservedName(t *testing.T) {
}
func TestEditWiki(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/_edit/Home")
ctx.SetParams(":page", "Home")
@@ -162,7 +163,7 @@ func TestEditWikiPost(t *testing.T) {
"Home",
"New/<page>",
} {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/_new/Home")
ctx.SetParams(":page", "Home")
test.LoadUser(t, ctx, 2)
@@ -183,7 +184,7 @@ func TestEditWikiPost(t *testing.T) {
}
func TestDeleteWikiPagePost(t *testing.T) {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/Home/delete")
test.LoadUser(t, ctx, 2)
@@ -202,7 +203,7 @@ func TestWikiRaw(t *testing.T) {
"Page With Spaced Name.md": "text/plain; charset=utf-8",
"Page-With-Spaced-Name.md": "text/plain; charset=utf-8",
} {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/raw/"+filepath)
ctx.SetParams("*", filepath)
diff --git a/routers/web/user/auth.go b/routers/web/user/auth.go
index a5c0a14d17..b4c52675fd 100644
--- a/routers/web/user/auth.go
+++ b/routers/web/user/auth.go
@@ -14,6 +14,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/eventsource"
@@ -55,7 +56,7 @@ const (
// AutoSignIn reads cookie and try to auto-login.
func AutoSignIn(ctx *context.Context) (bool, error) {
- if !models.HasEngine {
+ if !db.HasEngine {
return false, nil
}
diff --git a/routers/web/user/home_test.go b/routers/web/user/home_test.go
index b0109c354f..daf473b270 100644
--- a/routers/web/user/home_test.go
+++ b/routers/web/user/home_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"
"code.gitea.io/gitea/modules/test"
@@ -18,7 +19,7 @@ import (
func TestArchivedIssues(t *testing.T) {
// Arrange
setting.UI.IssuePagingNum = 1
- assert.NoError(t, models.LoadFixtures())
+ assert.NoError(t, db.LoadFixtures())
ctx := test.MockContext(t, "issues")
test.LoadUser(t, ctx, 30)
@@ -51,7 +52,7 @@ func TestArchivedIssues(t *testing.T) {
func TestIssues(t *testing.T) {
setting.UI.IssuePagingNum = 1
- assert.NoError(t, models.LoadFixtures())
+ assert.NoError(t, db.LoadFixtures())
ctx := test.MockContext(t, "issues")
test.LoadUser(t, ctx, 2)
@@ -67,7 +68,7 @@ func TestIssues(t *testing.T) {
func TestPulls(t *testing.T) {
setting.UI.IssuePagingNum = 20
- assert.NoError(t, models.LoadFixtures())
+ assert.NoError(t, db.LoadFixtures())
ctx := test.MockContext(t, "pulls")
test.LoadUser(t, ctx, 2)
@@ -80,7 +81,7 @@ func TestPulls(t *testing.T) {
func TestMilestones(t *testing.T) {
setting.UI.IssuePagingNum = 1
- assert.NoError(t, models.LoadFixtures())
+ assert.NoError(t, db.LoadFixtures())
ctx := test.MockContext(t, "milestones")
test.LoadUser(t, ctx, 2)
@@ -99,7 +100,7 @@ func TestMilestones(t *testing.T) {
func TestMilestonesForSpecificRepo(t *testing.T) {
setting.UI.IssuePagingNum = 1
- assert.NoError(t, models.LoadFixtures())
+ assert.NoError(t, db.LoadFixtures())
ctx := test.MockContext(t, "milestones")
test.LoadUser(t, ctx, 2)
diff --git a/routers/web/user/main_test.go b/routers/web/user/main_test.go
index be17dd1f31..272e4b8b21 100644
--- a/routers/web/user/main_test.go
+++ b/routers/web/user/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func TestMain(m *testing.M) {
- models.MainTest(m, filepath.Join("..", "..", ".."))
+ db.MainTest(m, filepath.Join("..", "..", ".."))
}
diff --git a/routers/web/user/oauth_test.go b/routers/web/user/oauth_test.go
index 40116d3c12..09abf1ee2a 100644
--- a/routers/web/user/oauth_test.go
+++ b/routers/web/user/oauth_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/services/auth/source/oauth2"
"github.com/golang-jwt/jwt"
@@ -39,7 +40,7 @@ func createAndParseToken(t *testing.T, grant *models.OAuth2Grant) *oauth2.OIDCTo
}
func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
- assert.NoError(t, models.PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
grants, err := models.GetOAuth2GrantsByUserID(3)
assert.NoError(t, err)
@@ -56,7 +57,7 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
assert.Empty(t, oidcToken.Email)
assert.False(t, oidcToken.EmailVerified)
- user := models.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+ user := db.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
grants, err = models.GetOAuth2GrantsByUserID(user.ID)
assert.NoError(t, err)
assert.Len(t, grants, 1)
diff --git a/routers/web/user/setting/account_test.go b/routers/web/user/setting/account_test.go
index 25b68da762..bfb7ac4872 100644
--- a/routers/web/user/setting/account_test.go
+++ b/routers/web/user/setting/account_test.go
@@ -8,7 +8,7 @@ import (
"net/http"
"testing"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
@@ -81,7 +81,7 @@ func TestChangePassword(t *testing.T) {
PasswordComplexity: pcLU,
},
} {
- models.PrepareTestEnv(t)
+ db.PrepareTestEnv(t)
ctx := test.MockContext(t, "user/settings/security")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
diff --git a/routers/web/user/setting/main_test.go b/routers/web/user/setting/main_test.go
index daa3f7fe5b..a0fbe55ee1 100644
--- a/routers/web/user/setting/main_test.go
+++ b/routers/web/user/setting/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func TestMain(m *testing.M) {
- models.MainTest(m, filepath.Join("..", "..", "..", ".."))
+ db.MainTest(m, filepath.Join("..", "..", "..", ".."))
}