Restore config after finisht the test case (#9085)

Этот коммит содержится в:
Carlos Tadeu Panato Junior
2018-07-11 12:58:16 +02:00
коммит произвёл GitHub
родитель 7c08ff9986
Коммит 7ed712f938
6 изменённых файлов: 152 добавлений и 5 удалений

Просмотреть файл

@@ -22,6 +22,13 @@ func TestCreateUser(t *testing.T) {
Client := th.Client
AdminClient := th.SystemAdminClient
enableOpenServer := th.App.Config().TeamSettings.EnableOpenServer
enableUserCreation := th.App.Config().TeamSettings.EnableUserCreation
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableOpenServer = enableOpenServer })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableUserCreation = enableUserCreation })
}()
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
ruser, resp := Client.CreateUser(&user)
@@ -161,6 +168,12 @@ func TestCreateUserWithToken(t *testing.T) {
})
t.Run("EnableUserCreationDisable", func(t *testing.T) {
enableUserCreation := th.App.Config().TeamSettings.EnableUserCreation
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableUserCreation = enableUserCreation })
}()
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
token := model.NewToken(
@@ -176,7 +189,6 @@ func TestCreateUserWithToken(t *testing.T) {
CheckNotImplementedStatus(t, resp)
CheckErrorMessage(t, resp, "api.user.create_user.signup_email_disabled.app_error")
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = true })
})
t.Run("EnableOpenServerDisable", func(t *testing.T) {
@@ -188,6 +200,11 @@ func TestCreateUserWithToken(t *testing.T) {
)
<-th.App.Srv.Store.Token().Save(token)
enableOpenServer := th.App.Config().TeamSettings.EnableOpenServer
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableOpenServer = enableOpenServer })
}()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = false })
ruser, resp := Client.CreateUserWithToken(&user, token.Token)
@@ -270,6 +287,11 @@ func TestCreateUserWithInviteId(t *testing.T) {
t.Run("EnableUserCreationDisable", func(t *testing.T) {
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
enableUserCreation := th.App.Config().TeamSettings.EnableUserCreation
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableUserCreation = enableUserCreation })
}()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = false })
inviteId := th.BasicTeam.InviteId
@@ -277,13 +299,16 @@ func TestCreateUserWithInviteId(t *testing.T) {
_, resp := Client.CreateUserWithInviteId(&user, inviteId)
CheckNotImplementedStatus(t, resp)
CheckErrorMessage(t, resp, "api.user.create_user.signup_email_disabled.app_error")
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = true })
})
t.Run("EnableOpenServerDisable", func(t *testing.T) {
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
enableOpenServer := th.App.Config().TeamSettings.EnableOpenServer
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.EnableOpenServer = enableOpenServer })
}()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = false })
inviteId := th.BasicTeam.InviteId
@@ -332,6 +357,13 @@ func TestGetUser(t *testing.T) {
th.App.UpdateUser(user, false)
showEmailAddress := th.App.Config().PrivacySettings.ShowEmailAddress
showFullName := th.App.Config().PrivacySettings.ShowFullName
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = showEmailAddress })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = showFullName })
}()
ruser, resp := Client.GetUser(user.Id, "")
CheckNoError(t, resp)
CheckUserSanitization(t, ruser)
@@ -393,6 +425,13 @@ func TestGetUserByUsername(t *testing.T) {
user := th.BasicUser
showEmailAddress := th.App.Config().PrivacySettings.ShowEmailAddress
showFullName := th.App.Config().PrivacySettings.ShowFullName
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = showEmailAddress })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = showFullName })
}()
ruser, resp := Client.GetUserByUsername(user.Username, "")
CheckNoError(t, resp)
CheckUserSanitization(t, ruser)
@@ -452,6 +491,13 @@ func TestGetUserByEmail(t *testing.T) {
defer th.TearDown()
Client := th.Client
showEmailAddress := th.App.Config().PrivacySettings.ShowEmailAddress
showFullName := th.App.Config().PrivacySettings.ShowFullName
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = showEmailAddress })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = showFullName })
}()
user := th.CreateUser()
ruser, resp := Client.GetUserByEmail(user.Email, "")
@@ -510,6 +556,13 @@ func TestSearchUsers(t *testing.T) {
defer th.TearDown()
Client := th.Client
showEmailAddress := th.App.Config().PrivacySettings.ShowEmailAddress
showFullName := th.App.Config().PrivacySettings.ShowFullName
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowEmailAddress = showEmailAddress })
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = showFullName })
}()
search := &model.UserSearch{Term: th.BasicUser.Username}
users, resp := Client.SearchUsers(search)
@@ -696,6 +749,11 @@ func TestAutocompleteUsers(t *testing.T) {
channelId := th.BasicChannel.Id
username := th.BasicUser.Username
showFullName := th.App.Config().PrivacySettings.ShowFullName
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.PrivacySettings.ShowFullName = showFullName })
}()
rusers, resp := Client.AutocompleteUsersInChannel(teamId, channelId, username, "")
CheckNoError(t, resp)