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:
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
|
@@ -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("..", "..", ".."))
|
||||
}
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
@@ -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("..", "..", "..", ".."))
|
||||
}
|
||||
|
Reference in New Issue
Block a user