diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2021-11-18 18:42:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 01:42:27 +0800 |
commit | f34151bdb22c8160b0a6eafef20725ebae1768da (patch) | |
tree | 2abcc5845e4a9cf3769deb27ba5a3ecccd2ad8c9 /models/user_test.go | |
parent | 55be5fe3399d18b7d2477519707aecf5f99f1de5 (diff) | |
download | gitea-f34151bdb22c8160b0a6eafef20725ebae1768da.tar.gz gitea-f34151bdb22c8160b0a6eafef20725ebae1768da.zip |
Move user/org deletion to services (#17673)
Diffstat (limited to 'models/user_test.go')
-rw-r--r-- | models/user_test.go | 80 |
1 files changed, 0 insertions, 80 deletions
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()) |