mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-12-07 14:09:47 +00:00
To make sure that the code stays maintainable, I added the `importas` linter to ensure that the imports for models and services stay consistent. I realised that this might be needed after finding some discrepancies between singular/plural naming, and, especially in the case of the `forgejo.org/services/context` package, multiple different aliases like `gitea_ctx`, `app_context` and `forgejo_context`. I decided for `app_context`, as that seems to be the most commonly used naming. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10253 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: nachtjasmin <nachtjasmin@posteo.de> Co-committed-by: nachtjasmin <nachtjasmin@posteo.de>
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package mailer
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"forgejo.org/models/db"
|
|
org_model "forgejo.org/models/organization"
|
|
"forgejo.org/models/unittest"
|
|
user_model "forgejo.org/models/user"
|
|
"forgejo.org/modules/setting"
|
|
"forgejo.org/modules/templates"
|
|
"forgejo.org/modules/test"
|
|
"forgejo.org/modules/translation"
|
|
|
|
_ "forgejo.org/models/actions"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
unittest.MainTest(m)
|
|
}
|
|
|
|
func AssertTranslatedLocale(t *testing.T, message string, prefixes ...string) {
|
|
t.Helper()
|
|
for _, prefix := range prefixes {
|
|
assert.NotContains(t, message, prefix, "there is an untranslated locale prefix")
|
|
}
|
|
}
|
|
|
|
func MockMailSettings(send func(msgs ...*Message)) func() {
|
|
translation.InitLocales(context.Background())
|
|
subjectTemplates, bodyTemplates = templates.Mailer(context.Background())
|
|
mailService := setting.Mailer{
|
|
From: "test@gitea.com",
|
|
}
|
|
cleanups := []func(){
|
|
test.MockVariableValue(&setting.MailService, &mailService),
|
|
test.MockVariableValue(&setting.Domain, "localhost"),
|
|
test.MockVariableValue(&SendAsync, send),
|
|
}
|
|
return func() {
|
|
for _, cleanup := range cleanups {
|
|
cleanup()
|
|
}
|
|
}
|
|
}
|
|
|
|
func CleanUpUsers(ctx context.Context, users []*user_model.User) {
|
|
for _, u := range users {
|
|
if u.IsOrganization() {
|
|
org_model.DeleteOrganization(ctx, (*org_model.Organization)(u))
|
|
} else {
|
|
db.DeleteByID[user_model.User](ctx, u.ID)
|
|
db.DeleteByBean(ctx, &user_model.EmailAddress{UID: u.ID})
|
|
}
|
|
}
|
|
}
|