You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.4 KiB
74 lines
2.4 KiB
8 years ago
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
2 years ago
|
package issues_test
|
||
8 years ago
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
2 years ago
|
issues_model "code.gitea.io/gitea/models/issues"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
7 years ago
|
"code.gitea.io/gitea/modules/setting"
|
||
|
|
||
8 years ago
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestIssueList_LoadRepositories(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
|
||
2 years ago
|
issueList := issues_model.IssueList{
|
||
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}).(*issues_model.Issue),
|
||
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2}).(*issues_model.Issue),
|
||
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4}).(*issues_model.Issue),
|
||
8 years ago
|
}
|
||
|
|
||
|
repos, err := issueList.LoadRepositories()
|
||
|
assert.NoError(t, err)
|
||
|
assert.Len(t, repos, 2)
|
||
|
for _, issue := range issueList {
|
||
|
assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestIssueList_LoadAttributes(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
7 years ago
|
setting.Service.EnableTimetracking = true
|
||
2 years ago
|
issueList := issues_model.IssueList{
|
||
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}).(*issues_model.Issue),
|
||
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4}).(*issues_model.Issue),
|
||
8 years ago
|
}
|
||
|
|
||
|
assert.NoError(t, issueList.LoadAttributes())
|
||
|
for _, issue := range issueList {
|
||
|
assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
|
||
|
for _, label := range issue.Labels {
|
||
|
assert.EqualValues(t, issue.RepoID, label.RepoID)
|
||
2 years ago
|
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: label.ID})
|
||
8 years ago
|
}
|
||
|
if issue.PosterID > 0 {
|
||
|
assert.EqualValues(t, issue.PosterID, issue.Poster.ID)
|
||
|
}
|
||
|
if issue.AssigneeID > 0 {
|
||
|
assert.EqualValues(t, issue.AssigneeID, issue.Assignee.ID)
|
||
|
}
|
||
|
if issue.MilestoneID > 0 {
|
||
|
assert.EqualValues(t, issue.MilestoneID, issue.Milestone.ID)
|
||
|
}
|
||
|
if issue.IsPull {
|
||
|
assert.EqualValues(t, issue.ID, issue.PullRequest.IssueID)
|
||
|
}
|
||
|
for _, attachment := range issue.Attachments {
|
||
|
assert.EqualValues(t, issue.ID, attachment.IssueID)
|
||
|
}
|
||
|
for _, comment := range issue.Comments {
|
||
|
assert.EqualValues(t, issue.ID, comment.IssueID)
|
||
|
}
|
||
7 years ago
|
if issue.ID == int64(1) {
|
||
|
assert.Equal(t, int64(400), issue.TotalTrackedTime)
|
||
|
} else if issue.ID == int64(2) {
|
||
5 years ago
|
assert.Equal(t, int64(3682), issue.TotalTrackedTime)
|
||
7 years ago
|
}
|
||
8 years ago
|
}
|
||
|
}
|