@@ -7,12 +7,9 @@ package models
7
7
import (
8
8
"testing"
9
9
10
- "code.gitea.io/gitea/models/db"
11
10
"code.gitea.io/gitea/models/organization"
12
- repo_model "code.gitea.io/gitea/models/repo"
13
11
"code.gitea.io/gitea/models/unittest"
14
12
user_model "code.gitea.io/gitea/models/user"
15
- "code.gitea.io/gitea/modules/setting"
16
13
17
14
"github.com/stretchr/testify/assert"
18
15
)
@@ -62,115 +59,3 @@ func TestRemoveOrgUser(t *testing.T) {
62
59
unittest .AssertExistsAndLoadBean (t , & organization.OrgUser {OrgID : 7 , UID : 5 })
63
60
unittest .CheckConsistencyFor (t , & user_model.User {}, & organization.Team {})
64
61
}
65
-
66
- func TestUser_RemoveOrgRepo (t * testing.T ) {
67
- assert .NoError (t , unittest .PrepareTestDatabase ())
68
- org := unittest .AssertExistsAndLoadBean (t , & organization.Organization {ID : 3 }).(* organization.Organization )
69
- repo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {OwnerID : org .ID }).(* repo_model.Repository )
70
-
71
- // remove a repo that does belong to org
72
- unittest .AssertExistsAndLoadBean (t , & organization.TeamRepo {RepoID : repo .ID , OrgID : org .ID })
73
- assert .NoError (t , organization .RemoveOrgRepo (db .DefaultContext , org .ID , repo .ID ))
74
- unittest .AssertNotExistsBean (t , & organization.TeamRepo {RepoID : repo .ID , OrgID : org .ID })
75
- unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : repo .ID }) // repo should still exist
76
-
77
- // remove a repo that does not belong to org
78
- assert .NoError (t , organization .RemoveOrgRepo (db .DefaultContext , org .ID , repo .ID ))
79
- unittest .AssertNotExistsBean (t , & organization.TeamRepo {RepoID : repo .ID , OrgID : org .ID })
80
-
81
- assert .NoError (t , organization .RemoveOrgRepo (db .DefaultContext , org .ID , unittest .NonexistentID ))
82
-
83
- unittest .CheckConsistencyFor (t ,
84
- & user_model.User {ID : org .ID },
85
- & organization.Team {OrgID : org .ID },
86
- & repo_model.Repository {ID : repo .ID })
87
- }
88
-
89
- func TestCreateOrganization (t * testing.T ) {
90
- // successful creation of org
91
- assert .NoError (t , unittest .PrepareTestDatabase ())
92
-
93
- owner := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 }).(* user_model.User )
94
- const newOrgName = "neworg"
95
- org := & organization.Organization {
96
- Name : newOrgName ,
97
- }
98
-
99
- unittest .AssertNotExistsBean (t , & user_model.User {Name : newOrgName , Type : user_model .UserTypeOrganization })
100
- assert .NoError (t , organization .CreateOrganization (org , owner ))
101
- org = unittest .AssertExistsAndLoadBean (t ,
102
- & organization.Organization {Name : newOrgName , Type : user_model .UserTypeOrganization }).(* organization.Organization )
103
- ownerTeam := unittest .AssertExistsAndLoadBean (t ,
104
- & organization.Team {Name : organization .OwnerTeamName , OrgID : org .ID }).(* organization.Team )
105
- unittest .AssertExistsAndLoadBean (t , & organization.TeamUser {UID : owner .ID , TeamID : ownerTeam .ID })
106
- unittest .CheckConsistencyFor (t , & user_model.User {}, & organization.Team {})
107
- }
108
-
109
- func TestCreateOrganization2 (t * testing.T ) {
110
- // unauthorized creation of org
111
- assert .NoError (t , unittest .PrepareTestDatabase ())
112
-
113
- owner := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 5 }).(* user_model.User )
114
- const newOrgName = "neworg"
115
- org := & organization.Organization {
116
- Name : newOrgName ,
117
- }
118
-
119
- unittest .AssertNotExistsBean (t , & organization.Organization {Name : newOrgName , Type : user_model .UserTypeOrganization })
120
- err := organization .CreateOrganization (org , owner )
121
- assert .Error (t , err )
122
- assert .True (t , organization .IsErrUserNotAllowedCreateOrg (err ))
123
- unittest .AssertNotExistsBean (t , & organization.Organization {Name : newOrgName , Type : user_model .UserTypeOrganization })
124
- unittest .CheckConsistencyFor (t , & organization.Organization {}, & organization.Team {})
125
- }
126
-
127
- func TestCreateOrganization3 (t * testing.T ) {
128
- // create org with same name as existent org
129
- assert .NoError (t , unittest .PrepareTestDatabase ())
130
-
131
- owner := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 }).(* user_model.User )
132
- org := & organization.Organization {Name : "user3" } // should already exist
133
- unittest .AssertExistsAndLoadBean (t , & user_model.User {Name : org .Name }) // sanity check
134
- err := organization .CreateOrganization (org , owner )
135
- assert .Error (t , err )
136
- assert .True (t , user_model .IsErrUserAlreadyExist (err ))
137
- unittest .CheckConsistencyFor (t , & user_model.User {}, & organization.Team {})
138
- }
139
-
140
- func TestCreateOrganization4 (t * testing.T ) {
141
- // create org with unusable name
142
- assert .NoError (t , unittest .PrepareTestDatabase ())
143
-
144
- owner := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 }).(* user_model.User )
145
- err := organization .CreateOrganization (& organization.Organization {Name : "assets" }, owner )
146
- assert .Error (t , err )
147
- assert .True (t , db .IsErrNameReserved (err ))
148
- unittest .CheckConsistencyFor (t , & organization.Organization {}, & organization.Team {})
149
- }
150
-
151
- func TestAddOrgUser (t * testing.T ) {
152
- assert .NoError (t , unittest .PrepareTestDatabase ())
153
- testSuccess := func (orgID , userID int64 , isPublic bool ) {
154
- org := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : orgID }).(* user_model.User )
155
- expectedNumMembers := org .NumMembers
156
- if ! unittest .BeanExists (t , & organization.OrgUser {OrgID : orgID , UID : userID }) {
157
- expectedNumMembers ++
158
- }
159
- assert .NoError (t , organization .AddOrgUser (orgID , userID ))
160
- ou := & organization.OrgUser {OrgID : orgID , UID : userID }
161
- unittest .AssertExistsAndLoadBean (t , ou )
162
- assert .Equal (t , isPublic , ou .IsPublic )
163
- org = unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : orgID }).(* user_model.User )
164
- assert .EqualValues (t , expectedNumMembers , org .NumMembers )
165
- }
166
-
167
- setting .Service .DefaultOrgMemberVisible = false
168
- testSuccess (3 , 5 , false )
169
- testSuccess (3 , 5 , false )
170
- testSuccess (6 , 2 , false )
171
-
172
- setting .Service .DefaultOrgMemberVisible = true
173
- testSuccess (6 , 3 , true )
174
-
175
- unittest .CheckConsistencyFor (t , & user_model.User {}, & organization.Team {})
176
- }
0 commit comments