aboutsummaryrefslogtreecommitdiffstats
path: root/models/review_test.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-09-19 19:49:59 +0800
committerGitHub <noreply@github.com>2021-09-19 19:49:59 +0800
commita4bfef265d9e512830350635a0489c2cdcd6508f (patch)
tree1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /models/review_test.go
parent462306e263db5a809dbe2cdf62e99307aeff28de (diff)
downloadgitea-a4bfef265d9e512830350635a0489c2cdcd6508f.tar.gz
gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.zip
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>
Diffstat (limited to 'models/review_test.go')
-rw-r--r--models/review_test.go71
1 files changed, 36 insertions, 35 deletions
diff --git a/models/review_test.go b/models/review_test.go
index accc184193..c809a3d662 100644
--- a/models/review_test.go
+++ b/models/review_test.go
@@ -7,11 +7,12 @@ package models
import (
"testing"
+ "code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
func TestGetReviewByID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
review, err := GetReviewByID(1)
assert.NoError(t, err)
assert.Equal(t, "Demo Review", review.Content)
@@ -23,23 +24,23 @@ func TestGetReviewByID(t *testing.T) {
}
func TestReview_LoadAttributes(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- review := AssertExistsAndLoadBean(t, &Review{ID: 1}).(*Review)
+ assert.NoError(t, db.PrepareTestDatabase())
+ review := db.AssertExistsAndLoadBean(t, &Review{ID: 1}).(*Review)
assert.NoError(t, review.LoadAttributes())
assert.NotNil(t, review.Issue)
assert.NotNil(t, review.Reviewer)
- invalidReview1 := AssertExistsAndLoadBean(t, &Review{ID: 2}).(*Review)
+ invalidReview1 := db.AssertExistsAndLoadBean(t, &Review{ID: 2}).(*Review)
assert.Error(t, invalidReview1.LoadAttributes())
- invalidReview2 := AssertExistsAndLoadBean(t, &Review{ID: 3}).(*Review)
+ invalidReview2 := db.AssertExistsAndLoadBean(t, &Review{ID: 3}).(*Review)
assert.Error(t, invalidReview2.LoadAttributes())
}
func TestReview_LoadCodeComments(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- review := AssertExistsAndLoadBean(t, &Review{ID: 4}).(*Review)
+ review := db.AssertExistsAndLoadBean(t, &Review{ID: 4}).(*Review)
assert.NoError(t, review.LoadAttributes())
assert.NoError(t, review.LoadCodeComments())
assert.Len(t, review.CodeComments, 1)
@@ -56,7 +57,7 @@ func TestReviewType_Icon(t *testing.T) {
}
func TestFindReviews(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
reviews, err := FindReviews(FindReviewOptions{
Type: ReviewTypeApprove,
IssueID: 2,
@@ -68,9 +69,9 @@ func TestFindReviews(t *testing.T) {
}
func TestGetCurrentReview(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- issue := AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
- user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
+ user := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
review, err := GetCurrentReview(user, issue)
assert.NoError(t, err)
@@ -78,7 +79,7 @@ func TestGetCurrentReview(t *testing.T) {
assert.Equal(t, ReviewTypePending, review.Type)
assert.Equal(t, "Pending Review", review.Content)
- user2 := AssertExistsAndLoadBean(t, &User{ID: 7}).(*User)
+ user2 := db.AssertExistsAndLoadBean(t, &User{ID: 7}).(*User)
review2, err := GetCurrentReview(user2, issue)
assert.Error(t, err)
assert.True(t, IsErrReviewNotExist(err))
@@ -86,10 +87,10 @@ func TestGetCurrentReview(t *testing.T) {
}
func TestCreateReview(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- issue := AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
- user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
+ issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
+ user := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
review, err := CreateReview(CreateReviewOptions{
Content: "New Review",
@@ -99,16 +100,16 @@ func TestCreateReview(t *testing.T) {
})
assert.NoError(t, err)
assert.Equal(t, "New Review", review.Content)
- AssertExistsAndLoadBean(t, &Review{Content: "New Review"})
+ db.AssertExistsAndLoadBean(t, &Review{Content: "New Review"})
}
func TestGetReviewersByIssueID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- issue := AssertExistsAndLoadBean(t, &Issue{ID: 3}).(*Issue)
- user2 := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
- user3 := AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
- user4 := AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
+ issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 3}).(*Issue)
+ user2 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ user3 := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
+ user4 := db.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User)
expectedReviews := []*Review{}
expectedReviews = append(expectedReviews,
@@ -143,45 +144,45 @@ func TestGetReviewersByIssueID(t *testing.T) {
}
func TestDismissReview(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- rejectReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
- approveReviewExample := AssertExistsAndLoadBean(t, &Review{ID: 8}).(*Review)
+ rejectReviewExample := db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample := db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ approveReviewExample := db.AssertExistsAndLoadBean(t, &Review{ID: 8}).(*Review)
assert.False(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(rejectReviewExample, true))
- rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ rejectReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, true))
- rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ rejectReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, true))
- rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ rejectReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, false))
- rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ rejectReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)
assert.NoError(t, DismissReview(requestReviewExample, false))
- rejectReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
- requestReviewExample = AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
+ rejectReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 9}).(*Review)
+ requestReviewExample = db.AssertExistsAndLoadBean(t, &Review{ID: 11}).(*Review)
assert.True(t, rejectReviewExample.Dismissed)
assert.False(t, requestReviewExample.Dismissed)
assert.False(t, approveReviewExample.Dismissed)