@@ -11,7 +11,7 @@ import (
11
11
"testing"
12
12
13
13
"code.gitea.io/gitea/models"
14
- "code.gitea.io/gitea/models/db "
14
+ "code.gitea.io/gitea/models/unittest "
15
15
"code.gitea.io/gitea/modules/convert"
16
16
api "code.gitea.io/gitea/modules/structs"
17
17
@@ -21,11 +21,11 @@ import (
21
21
func TestAPIListRepoComments (t * testing.T ) {
22
22
defer prepareTestEnv (t )()
23
23
24
- comment := db .AssertExistsAndLoadBean (t , & models.Comment {},
25
- db .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
26
- issue := db .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
27
- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
28
- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
24
+ comment := unittest .AssertExistsAndLoadBean (t , & models.Comment {},
25
+ unittest .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
26
+ issue := unittest .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
27
+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
28
+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
29
29
30
30
session := loginUser (t , repoOwner .Name )
31
31
link , _ := url .Parse (fmt .Sprintf ("/api/v1/repos/%s/%s/issues/comments" , repoOwner .Name , repo .Name ))
@@ -37,9 +37,9 @@ func TestAPIListRepoComments(t *testing.T) {
37
37
assert .Len (t , apiComments , 2 )
38
38
for _ , apiComment := range apiComments {
39
39
c := & models.Comment {ID : apiComment .ID }
40
- db .AssertExistsAndLoadBean (t , c ,
41
- db .Cond ("type = ?" , models .CommentTypeComment ))
42
- db .AssertExistsAndLoadBean (t , & models.Issue {ID : c .IssueID , RepoID : repo .ID })
40
+ unittest .AssertExistsAndLoadBean (t , c ,
41
+ unittest .Cond ("type = ?" , models .CommentTypeComment ))
42
+ unittest .AssertExistsAndLoadBean (t , & models.Issue {ID : c .IssueID , RepoID : repo .ID })
43
43
}
44
44
45
45
//test before and since filters
@@ -67,11 +67,11 @@ func TestAPIListRepoComments(t *testing.T) {
67
67
func TestAPIListIssueComments (t * testing.T ) {
68
68
defer prepareTestEnv (t )()
69
69
70
- comment := db .AssertExistsAndLoadBean (t , & models.Comment {},
71
- db .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
72
- issue := db .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
73
- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
74
- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
70
+ comment := unittest .AssertExistsAndLoadBean (t , & models.Comment {},
71
+ unittest .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
72
+ issue := unittest .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
73
+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
74
+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
75
75
76
76
session := loginUser (t , repoOwner .Name )
77
77
req := NewRequestf (t , "GET" , "/api/v1/repos/%s/%s/issues/%d/comments" ,
@@ -80,18 +80,18 @@ func TestAPIListIssueComments(t *testing.T) {
80
80
81
81
var comments []* api.Comment
82
82
DecodeJSON (t , resp , & comments )
83
- expectedCount := db .GetCount (t , & models.Comment {IssueID : issue .ID },
84
- db .Cond ("type = ?" , models .CommentTypeComment ))
83
+ expectedCount := unittest .GetCount (t , & models.Comment {IssueID : issue .ID },
84
+ unittest .Cond ("type = ?" , models .CommentTypeComment ))
85
85
assert .EqualValues (t , expectedCount , len (comments ))
86
86
}
87
87
88
88
func TestAPICreateComment (t * testing.T ) {
89
89
defer prepareTestEnv (t )()
90
90
const commentBody = "Comment body"
91
91
92
- issue := db .AssertExistsAndLoadBean (t , & models.Issue {}).(* models.Issue )
93
- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
94
- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
92
+ issue := unittest .AssertExistsAndLoadBean (t , & models.Issue {}).(* models.Issue )
93
+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
94
+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
95
95
96
96
session := loginUser (t , repoOwner .Name )
97
97
token := getTokenForLoggedInUser (t , session )
@@ -105,16 +105,16 @@ func TestAPICreateComment(t *testing.T) {
105
105
var updatedComment api.Comment
106
106
DecodeJSON (t , resp , & updatedComment )
107
107
assert .EqualValues (t , commentBody , updatedComment .Body )
108
- db .AssertExistsAndLoadBean (t , & models.Comment {ID : updatedComment .ID , IssueID : issue .ID , Content : commentBody })
108
+ unittest .AssertExistsAndLoadBean (t , & models.Comment {ID : updatedComment .ID , IssueID : issue .ID , Content : commentBody })
109
109
}
110
110
111
111
func TestAPIGetComment (t * testing.T ) {
112
112
defer prepareTestEnv (t )()
113
113
114
- comment := db .AssertExistsAndLoadBean (t , & models.Comment {ID : 2 }).(* models.Comment )
114
+ comment := unittest .AssertExistsAndLoadBean (t , & models.Comment {ID : 2 }).(* models.Comment )
115
115
assert .NoError (t , comment .LoadIssue ())
116
- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : comment .Issue .RepoID }).(* models.Repository )
117
- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
116
+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : comment .Issue .RepoID }).(* models.Repository )
117
+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
118
118
119
119
session := loginUser (t , repoOwner .Name )
120
120
token := getTokenForLoggedInUser (t , session )
@@ -139,11 +139,11 @@ func TestAPIEditComment(t *testing.T) {
139
139
defer prepareTestEnv (t )()
140
140
const newCommentBody = "This is the new comment body"
141
141
142
- comment := db .AssertExistsAndLoadBean (t , & models.Comment {},
143
- db .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
144
- issue := db .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
145
- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
146
- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
142
+ comment := unittest .AssertExistsAndLoadBean (t , & models.Comment {},
143
+ unittest .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
144
+ issue := unittest .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
145
+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
146
+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
147
147
148
148
session := loginUser (t , repoOwner .Name )
149
149
token := getTokenForLoggedInUser (t , session )
@@ -158,23 +158,23 @@ func TestAPIEditComment(t *testing.T) {
158
158
DecodeJSON (t , resp , & updatedComment )
159
159
assert .EqualValues (t , comment .ID , updatedComment .ID )
160
160
assert .EqualValues (t , newCommentBody , updatedComment .Body )
161
- db .AssertExistsAndLoadBean (t , & models.Comment {ID : comment .ID , IssueID : issue .ID , Content : newCommentBody })
161
+ unittest .AssertExistsAndLoadBean (t , & models.Comment {ID : comment .ID , IssueID : issue .ID , Content : newCommentBody })
162
162
}
163
163
164
164
func TestAPIDeleteComment (t * testing.T ) {
165
165
defer prepareTestEnv (t )()
166
166
167
- comment := db .AssertExistsAndLoadBean (t , & models.Comment {},
168
- db .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
169
- issue := db .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
170
- repo := db .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
171
- repoOwner := db .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
167
+ comment := unittest .AssertExistsAndLoadBean (t , & models.Comment {},
168
+ unittest .Cond ("type = ?" , models .CommentTypeComment )).(* models.Comment )
169
+ issue := unittest .AssertExistsAndLoadBean (t , & models.Issue {ID : comment .IssueID }).(* models.Issue )
170
+ repo := unittest .AssertExistsAndLoadBean (t , & models.Repository {ID : issue .RepoID }).(* models.Repository )
171
+ repoOwner := unittest .AssertExistsAndLoadBean (t , & models.User {ID : repo .OwnerID }).(* models.User )
172
172
173
173
session := loginUser (t , repoOwner .Name )
174
174
token := getTokenForLoggedInUser (t , session )
175
175
req := NewRequestf (t , "DELETE" , "/api/v1/repos/%s/%s/issues/comments/%d?token=%s" ,
176
176
repoOwner .Name , repo .Name , comment .ID , token )
177
177
session .MakeRequest (t , req , http .StatusNoContent )
178
178
179
- db .AssertNotExistsBean (t , & models.Comment {ID : comment .ID })
179
+ unittest .AssertNotExistsBean (t , & models.Comment {ID : comment .ID })
180
180
}
0 commit comments