From f34151bdb22c8160b0a6eafef20725ebae1768da Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Thu, 18 Nov 2021 18:42:27 +0100 Subject: Move user/org deletion to services (#17673) --- models/user_test.go | 80 ----------------------------------------------------- 1 file changed, 80 deletions(-) (limited to 'models/user_test.go') diff --git a/models/user_test.go b/models/user_test.go index 4e2e521767..2da5519d74 100644 --- a/models/user_test.go +++ b/models/user_test.go @@ -177,41 +177,6 @@ func TestSearchUsers(t *testing.T) { []int64{24}) } -func TestDeleteUser(t *testing.T) { - test := func(userID int64) { - assert.NoError(t, unittest.PrepareTestDatabase()) - user := unittest.AssertExistsAndLoadBean(t, &User{ID: userID}).(*User) - - ownedRepos := make([]*Repository, 0, 10) - assert.NoError(t, db.GetEngine(db.DefaultContext).Find(&ownedRepos, &Repository{OwnerID: userID})) - if len(ownedRepos) > 0 { - err := DeleteUser(user) - assert.Error(t, err) - assert.True(t, IsErrUserOwnRepos(err)) - return - } - - orgUsers := make([]*OrgUser, 0, 10) - assert.NoError(t, db.GetEngine(db.DefaultContext).Find(&orgUsers, &OrgUser{UID: userID})) - for _, orgUser := range orgUsers { - if err := RemoveOrgUser(orgUser.OrgID, orgUser.UID); err != nil { - assert.True(t, IsErrLastOrgOwner(err)) - return - } - } - assert.NoError(t, DeleteUser(user)) - unittest.AssertNotExistsBean(t, &User{ID: userID}) - unittest.CheckConsistencyFor(t, &User{}, &Repository{}) - } - test(2) - test(4) - test(8) - test(11) - - org := unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User) - assert.Error(t, DeleteUser(org)) -} - func TestEmailNotificationPreferences(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) @@ -333,21 +298,6 @@ func TestDisplayName(t *testing.T) { } } -func TestCreateUser(t *testing.T) { - user := &User{ - Name: "GiteaBot", - Email: "GiteaBot@gitea.io", - Passwd: ";p['////..-++']", - IsAdmin: false, - Theme: setting.UI.DefaultTheme, - MustChangePassword: false, - } - - assert.NoError(t, CreateUser(user)) - - assert.NoError(t, DeleteUser(user)) -} - func TestCreateUserInvalidEmail(t *testing.T) { user := &User{ Name: "GiteaBot", @@ -363,36 +313,6 @@ func TestCreateUserInvalidEmail(t *testing.T) { assert.True(t, user_model.IsErrEmailInvalid(err)) } -func TestCreateUser_Issue5882(t *testing.T) { - // Init settings - _ = setting.Admin - - passwd := ".//.;1;;//.,-=_" - - tt := []struct { - user *User - disableOrgCreation bool - }{ - {&User{Name: "GiteaBot", Email: "GiteaBot@gitea.io", Passwd: passwd, MustChangePassword: false}, false}, - {&User{Name: "GiteaBot2", Email: "GiteaBot2@gitea.io", Passwd: passwd, MustChangePassword: false}, true}, - } - - setting.Service.DefaultAllowCreateOrganization = true - - for _, v := range tt { - setting.Admin.DisableRegularOrgCreation = v.disableOrgCreation - - assert.NoError(t, CreateUser(v.user)) - - u, err := GetUserByEmail(v.user.Email) - assert.NoError(t, err) - - assert.Equal(t, !u.AllowCreateOrganization, v.disableOrgCreation) - - assert.NoError(t, DeleteUser(v.user)) - } -} - func TestGetUserIDsByNames(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) -- cgit v1.2.3