Skip to content

Commit 330bdae

Browse files
committed
Fix test
1 parent 3486a8b commit 330bdae

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

integrations/api_ui_issue_stopwatch_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"testing"
1010

1111
"code.gitea.io/gitea/models"
12-
"code.gitea.io/gitea/models/db"
12+
"code.gitea.io/gitea/models/unittest"
1313
api "code.gitea.io/gitea/modules/structs"
1414

1515
"github.com/stretchr/testify/assert"
@@ -18,16 +18,16 @@ import (
1818
func TestUIAPIListStopWatches(t *testing.T) {
1919
defer prepareTestEnv(t)()
2020

21-
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
22-
owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
21+
repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
22+
owner := unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
2323

2424
session := loginUser(t, owner.Name)
2525
req := NewRequestf(t, "GET", "/api/ui/user/stopwatches")
2626
resp := session.MakeRequest(t, req, http.StatusOK)
2727
var apiWatches []*api.StopWatch
2828
DecodeJSON(t, resp, &apiWatches)
29-
stopwatch := db.AssertExistsAndLoadBean(t, &models.Stopwatch{UserID: owner.ID}).(*models.Stopwatch)
30-
issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: stopwatch.IssueID}).(*models.Issue)
29+
stopwatch := unittest.AssertExistsAndLoadBean(t, &models.Stopwatch{UserID: owner.ID}).(*models.Stopwatch)
30+
issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: stopwatch.IssueID}).(*models.Issue)
3131
if assert.Len(t, apiWatches, 1) {
3232
assert.EqualValues(t, stopwatch.CreatedUnix.AsTime().Unix(), apiWatches[0].Created.Unix())
3333
assert.EqualValues(t, issue.Index, apiWatches[0].IssueIndex)

integrations/api_ui_notification_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/models/db"
14+
"code.gitea.io/gitea/models/unittest"
1415
api "code.gitea.io/gitea/modules/structs"
1516

1617
"github.com/stretchr/testify/assert"
@@ -19,9 +20,9 @@ import (
1920
func TestNotification(t *testing.T) {
2021
defer prepareTestEnv(t)()
2122

22-
user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
23-
repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
24-
thread5 := db.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification)
23+
user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
24+
repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
25+
thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5}).(*models.Notification)
2526
assert.NoError(t, thread5.LoadAttributes())
2627

2728
token := getUserToken(t, user2.Name)

routers/api/ui/api.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"strings"
1111

1212
"code.gitea.io/gitea/models"
13+
"code.gitea.io/gitea/models/unit"
14+
user_model "code.gitea.io/gitea/models/user"
1315
"code.gitea.io/gitea/modules/context"
1416
"code.gitea.io/gitea/modules/log"
1517
"code.gitea.io/gitea/modules/setting"
@@ -44,9 +46,9 @@ func repoAssignment() func(ctx *context.APIContext) {
4446
owner, err = models.GetUserByName(userName)
4547
if err != nil {
4648
if models.IsErrUserNotExist(err) {
47-
if redirectUserID, err := models.LookupUserRedirect(userName); err == nil {
49+
if redirectUserID, err := user_model.LookupUserRedirect(userName); err == nil {
4850
context.RedirectToUser(ctx.Context, userName, redirectUserID)
49-
} else if models.IsErrUserRedirectNotExist(err) {
51+
} else if user_model.IsErrUserRedirectNotExist(err) {
5052
ctx.NotFound("GetUserByName", err)
5153
} else {
5254
ctx.Error(http.StatusInternalServerError, "LookupUserRedirect", err)
@@ -198,10 +200,10 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
198200
ctx.Org.Organization, err = models.GetOrgByName(ctx.Params(":org"))
199201
if err != nil {
200202
if models.IsErrOrgNotExist(err) {
201-
redirectUserID, err := models.LookupUserRedirect(ctx.Params(":org"))
203+
redirectUserID, err := user_model.LookupUserRedirect(ctx.Params(":org"))
202204
if err == nil {
203205
context.RedirectToUser(ctx.Context, ctx.Params(":org"), redirectUserID)
204-
} else if models.IsErrUserRedirectNotExist(err) {
206+
} else if user_model.IsErrUserRedirectNotExist(err) {
205207
ctx.NotFound("GetOrgByName", err)
206208
} else {
207209
ctx.Error(http.StatusInternalServerError, "LookupUserRedirect", err)
@@ -228,22 +230,22 @@ func orgAssignment(args ...bool) func(ctx *context.APIContext) {
228230
}
229231

230232
func mustEnableIssuesOrPulls(ctx *context.APIContext) {
231-
if !ctx.Repo.CanRead(models.UnitTypeIssues) &&
232-
!(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(models.UnitTypePullRequests)) {
233+
if !ctx.Repo.CanRead(unit.TypeIssues) &&
234+
!(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(unit.TypePullRequests)) {
233235
if ctx.Repo.Repository.CanEnablePulls() && log.IsTrace() {
234236
if ctx.IsSigned {
235237
log.Trace("Permission Denied: User %-v cannot read %-v and %-v in Repo %-v\n"+
236238
"User in Repo has Permissions: %-+v",
237239
ctx.User,
238-
models.UnitTypeIssues,
239-
models.UnitTypePullRequests,
240+
unit.TypeIssues,
241+
unit.TypePullRequests,
240242
ctx.Repo.Repository,
241243
ctx.Repo.Permission)
242244
} else {
243245
log.Trace("Permission Denied: Anonymous user cannot read %-v and %-v in Repo %-v\n"+
244246
"Anonymous user in Repo has Permissions: %-+v",
245-
models.UnitTypeIssues,
246-
models.UnitTypePullRequests,
247+
unit.TypeIssues,
248+
unit.TypePullRequests,
247249
ctx.Repo.Repository,
248250
ctx.Repo.Permission)
249251
}

0 commit comments

Comments
 (0)