@@ -65,6 +65,10 @@ def test_adding_subproject_fails_when_user_is_not_admin(self):
65
65
form .errors ['child' ][0 ],
66
66
r'Select a valid choice.' ,
67
67
)
68
+ self .assertEqual (
69
+ [proj_id for (proj_id , __ ) in form .fields ['child' ].choices ],
70
+ ['' ],
71
+ )
68
72
69
73
def test_adding_subproject_passes_when_user_is_admin (self ):
70
74
user = fixture .get (User )
@@ -161,6 +165,45 @@ def test_exclude_self_project_as_subproject(self):
161
165
[proj_id for (proj_id , __ ) in form .fields ['child' ].choices ],
162
166
)
163
167
168
+ def test_alias_already_exists_for_a_project (self ):
169
+ user = fixture .get (User )
170
+ project = fixture .get (Project , users = [user ])
171
+ subproject = fixture .get (Project , users = [user ])
172
+ subproject_2 = fixture .get (Project , users = [user ])
173
+ relation = fixture .get (
174
+ ProjectRelationship , parent = project , child = subproject ,
175
+ alias = 'subproject'
176
+ )
177
+ form = ProjectRelationshipForm (
178
+ {
179
+ 'child' : subproject_2 .id ,
180
+ 'alias' : 'subproject'
181
+ },
182
+ project = project ,
183
+ user = user ,
184
+ )
185
+ self .assertFalse (form .is_valid ())
186
+ error_msg = 'A subproject with this alias already exists'
187
+ self .assertDictEqual (form .errors , {'alias' : [error_msg ]})
188
+
189
+ def test_edit_only_lists_instance_project_in_child_choices (self ):
190
+ user = fixture .get (User )
191
+ project = fixture .get (Project , users = [user ])
192
+ subproject = fixture .get (Project , users = [user ])
193
+ relation = fixture .get (
194
+ ProjectRelationship , parent = project , child = subproject ,
195
+ alias = 'subproject'
196
+ )
197
+ form = ProjectRelationshipForm (
198
+ instance = relation ,
199
+ project = project ,
200
+ user = user ,
201
+ )
202
+ self .assertEqual (
203
+ [proj_id for (proj_id , __ ) in form .fields ['child' ].choices ],
204
+ ['' , relation .child .id ],
205
+ )
206
+
164
207
165
208
@override_settings (PUBLIC_DOMAIN = 'readthedocs.org' )
166
209
class ResolverBase (TestCase ):
@@ -172,12 +215,12 @@ def setUp(self):
172
215
self .pip = fixture .get (Project , slug = 'pip' , users = [self .owner ], main_language_project = None )
173
216
self .subproject = fixture .get (
174
217
Project , slug = 'sub' , language = 'ja' ,
175
- users = [ self .owner ],
218
+ users = [self .owner ],
176
219
main_language_project = None ,
177
220
)
178
221
self .translation = fixture .get (
179
222
Project , slug = 'trans' , language = 'ja' ,
180
- users = [ self .owner ],
223
+ users = [self .owner ],
181
224
main_language_project = None ,
182
225
)
183
226
self .pip .add_subproject (self .subproject )
0 commit comments