mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
Move user related model into models/user (#17781)
* Move user related model into models/user * Fix lint for windows * Fix windows lint * Fix windows lint * Move some tests in models * Merge
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -40,7 +41,7 @@ const bodyTpl = `
|
||||
</html>
|
||||
`
|
||||
|
||||
func prepareMailerTest(t *testing.T) (doer *models.User, repo *models.Repository, issue *models.Issue, comment *models.Comment) {
|
||||
func prepareMailerTest(t *testing.T) (doer *user_model.User, repo *models.Repository, issue *models.Issue, comment *models.Comment) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
var mailService = setting.Mailer{
|
||||
From: "test@gitea.com",
|
||||
@@ -49,7 +50,7 @@ func prepareMailerTest(t *testing.T) (doer *models.User, repo *models.Repository
|
||||
setting.MailService = &mailService
|
||||
setting.Domain = "localhost"
|
||||
|
||||
doer = unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
doer = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
|
||||
repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1, Owner: doer}).(*models.Repository)
|
||||
issue = unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1, Repo: repo, Poster: doer}).(*models.Issue)
|
||||
assert.NoError(t, issue.LoadRepo())
|
||||
@@ -64,7 +65,7 @@ func TestComposeIssueCommentMessage(t *testing.T) {
|
||||
btpl := template.Must(template.New("issue/comment").Parse(bodyTpl))
|
||||
InitMailRender(stpl, btpl)
|
||||
|
||||
recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
||||
msgs, err := composeIssueCommentMessages(&mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
|
||||
Content: "test body", Comment: comment}, "en-US", recipients, false, "issue comment")
|
||||
assert.NoError(t, err)
|
||||
@@ -91,7 +92,7 @@ func TestComposeIssueMessage(t *testing.T) {
|
||||
btpl := template.Must(template.New("issue/new").Parse(bodyTpl))
|
||||
InitMailRender(stpl, btpl)
|
||||
|
||||
recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
||||
msgs, err := composeIssueCommentMessages(&mailCommentContext{Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
|
||||
Content: "test body"}, "en-US", recipients, false, "issue create")
|
||||
assert.NoError(t, err)
|
||||
@@ -113,7 +114,7 @@ func TestComposeIssueMessage(t *testing.T) {
|
||||
|
||||
func TestTemplateSelection(t *testing.T) {
|
||||
doer, repo, issue, comment := prepareMailerTest(t)
|
||||
recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}}
|
||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
|
||||
|
||||
stpl := texttmpl.Must(texttmpl.New("issue/default").Parse("issue/default/subject"))
|
||||
texttmpl.Must(stpl.New("issue/new").Parse("issue/new/subject"))
|
||||
@@ -159,14 +160,14 @@ func TestTemplateServices(t *testing.T) {
|
||||
doer, _, issue, comment := prepareMailerTest(t)
|
||||
assert.NoError(t, issue.LoadRepo())
|
||||
|
||||
expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *models.User,
|
||||
expect := func(t *testing.T, issue *models.Issue, comment *models.Comment, doer *user_model.User,
|
||||
actionType models.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string) {
|
||||
|
||||
stpl := texttmpl.Must(texttmpl.New("issue/default").Parse(tplSubject))
|
||||
btpl := template.Must(template.New("issue/default").Parse(tplBody))
|
||||
InitMailRender(stpl, btpl)
|
||||
|
||||
recipients := []*models.User{{Name: "Test", Email: "test@gitea.com"}}
|
||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
|
||||
msg := testComposeIssueCommentMessage(t, &mailCommentContext{Issue: issue, Doer: doer, ActionType: actionType,
|
||||
Content: "test body", Comment: comment}, recipients, fromMention, "TestTemplateServices")
|
||||
|
||||
@@ -198,7 +199,7 @@ func TestTemplateServices(t *testing.T) {
|
||||
"//Re: //")
|
||||
}
|
||||
|
||||
func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recipients []*models.User, fromMention bool, info string) *Message {
|
||||
func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recipients []*user_model.User, fromMention bool, info string) *Message {
|
||||
msgs, err := composeIssueCommentMessages(ctx, "en-US", recipients, fromMention, info)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, msgs, 1)
|
||||
@@ -209,7 +210,7 @@ func TestGenerateAdditionalHeaders(t *testing.T) {
|
||||
doer, _, issue, _ := prepareMailerTest(t)
|
||||
|
||||
ctx := &mailCommentContext{Issue: issue, Doer: doer}
|
||||
recipient := &models.User{Name: "Test", Email: "test@gitea.com"}
|
||||
recipient := &user_model.User{Name: "Test", Email: "test@gitea.com"}
|
||||
|
||||
headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient)
|
||||
|
||||
|
Reference in New Issue
Block a user