diff options
Diffstat (limited to 'models/org_test.go')
-rw-r--r-- | models/org_test.go | 115 |
1 files changed, 0 insertions, 115 deletions
diff --git a/models/org_test.go b/models/org_test.go index 4d8831858c..af11bed280 100644 --- a/models/org_test.go +++ b/models/org_test.go @@ -7,12 +7,9 @@ package models import ( "testing" - "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/organization" - repo_model "code.gitea.io/gitea/models/repo" "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" ) @@ -62,115 +59,3 @@ func TestRemoveOrgUser(t *testing.T) { unittest.AssertExistsAndLoadBean(t, &organization.OrgUser{OrgID: 7, UID: 5}) unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{}) } - -func TestUser_RemoveOrgRepo(t *testing.T) { - assert.NoError(t, unittest.PrepareTestDatabase()) - org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}).(*organization.Organization) - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: org.ID}).(*repo_model.Repository) - - // remove a repo that does belong to org - unittest.AssertExistsAndLoadBean(t, &organization.TeamRepo{RepoID: repo.ID, OrgID: org.ID}) - assert.NoError(t, organization.RemoveOrgRepo(db.DefaultContext, org.ID, repo.ID)) - unittest.AssertNotExistsBean(t, &organization.TeamRepo{RepoID: repo.ID, OrgID: org.ID}) - unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo.ID}) // repo should still exist - - // remove a repo that does not belong to org - assert.NoError(t, organization.RemoveOrgRepo(db.DefaultContext, org.ID, repo.ID)) - unittest.AssertNotExistsBean(t, &organization.TeamRepo{RepoID: repo.ID, OrgID: org.ID}) - - assert.NoError(t, organization.RemoveOrgRepo(db.DefaultContext, org.ID, unittest.NonexistentID)) - - unittest.CheckConsistencyFor(t, - &user_model.User{ID: org.ID}, - &organization.Team{OrgID: org.ID}, - &repo_model.Repository{ID: repo.ID}) -} - -func TestCreateOrganization(t *testing.T) { - // successful creation of org - assert.NoError(t, unittest.PrepareTestDatabase()) - - owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - const newOrgName = "neworg" - org := &organization.Organization{ - Name: newOrgName, - } - - unittest.AssertNotExistsBean(t, &user_model.User{Name: newOrgName, Type: user_model.UserTypeOrganization}) - assert.NoError(t, organization.CreateOrganization(org, owner)) - org = unittest.AssertExistsAndLoadBean(t, - &organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization}).(*organization.Organization) - ownerTeam := unittest.AssertExistsAndLoadBean(t, - &organization.Team{Name: organization.OwnerTeamName, OrgID: org.ID}).(*organization.Team) - unittest.AssertExistsAndLoadBean(t, &organization.TeamUser{UID: owner.ID, TeamID: ownerTeam.ID}) - unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{}) -} - -func TestCreateOrganization2(t *testing.T) { - // unauthorized creation of org - assert.NoError(t, unittest.PrepareTestDatabase()) - - owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User) - const newOrgName = "neworg" - org := &organization.Organization{ - Name: newOrgName, - } - - unittest.AssertNotExistsBean(t, &organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization}) - err := organization.CreateOrganization(org, owner) - assert.Error(t, err) - assert.True(t, organization.IsErrUserNotAllowedCreateOrg(err)) - unittest.AssertNotExistsBean(t, &organization.Organization{Name: newOrgName, Type: user_model.UserTypeOrganization}) - unittest.CheckConsistencyFor(t, &organization.Organization{}, &organization.Team{}) -} - -func TestCreateOrganization3(t *testing.T) { - // create org with same name as existent org - assert.NoError(t, unittest.PrepareTestDatabase()) - - owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - org := &organization.Organization{Name: "user3"} // should already exist - unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: org.Name}) // sanity check - err := organization.CreateOrganization(org, owner) - assert.Error(t, err) - assert.True(t, user_model.IsErrUserAlreadyExist(err)) - unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{}) -} - -func TestCreateOrganization4(t *testing.T) { - // create org with unusable name - assert.NoError(t, unittest.PrepareTestDatabase()) - - owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) - err := organization.CreateOrganization(&organization.Organization{Name: "assets"}, owner) - assert.Error(t, err) - assert.True(t, db.IsErrNameReserved(err)) - unittest.CheckConsistencyFor(t, &organization.Organization{}, &organization.Team{}) -} - -func TestAddOrgUser(t *testing.T) { - assert.NoError(t, unittest.PrepareTestDatabase()) - testSuccess := func(orgID, userID int64, isPublic bool) { - org := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: orgID}).(*user_model.User) - expectedNumMembers := org.NumMembers - if !unittest.BeanExists(t, &organization.OrgUser{OrgID: orgID, UID: userID}) { - expectedNumMembers++ - } - assert.NoError(t, organization.AddOrgUser(orgID, userID)) - ou := &organization.OrgUser{OrgID: orgID, UID: userID} - unittest.AssertExistsAndLoadBean(t, ou) - assert.Equal(t, isPublic, ou.IsPublic) - org = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: orgID}).(*user_model.User) - assert.EqualValues(t, expectedNumMembers, org.NumMembers) - } - - setting.Service.DefaultOrgMemberVisible = false - testSuccess(3, 5, false) - testSuccess(3, 5, false) - testSuccess(6, 2, false) - - setting.Service.DefaultOrgMemberVisible = true - testSuccess(6, 3, true) - - unittest.CheckConsistencyFor(t, &user_model.User{}, &organization.Team{}) -} |