241 |
241 |
assert delete_button.text() == 'Delete'
|
242 |
242 |
|
243 |
243 |
|
244 |
|
def test_edit(superuser, app):
|
|
244 |
def test_edit(superuser, app, ou1, ou2):
|
|
245 |
role_1 = Role.objects.create(name='role-1', ou=ou1)
|
|
246 |
role_2 = Role.objects.create(name='role-2', ou=ou2)
|
|
247 |
role_3 = Role.objects.create(name='role-3', ou=ou1)
|
245 |
248 |
api_client = APIClient.objects.create(
|
246 |
|
name='foo', description='foo-description', identifier='foo-identifier', password='foo-password'
|
|
249 |
name='foo',
|
|
250 |
description='foo-description',
|
|
251 |
identifier='foo-identifier',
|
|
252 |
password='foo-password',
|
|
253 |
ou=ou1,
|
247 |
254 |
)
|
248 |
255 |
assert APIClient.objects.count() == 1
|
249 |
256 |
resp = login(app, superuser, 'a2-manager-api-client-edit', kwargs={'pk': api_client.pk})
|
... | ... | |
251 |
258 |
assert form.get('password').value == 'foo-password'
|
252 |
259 |
assert ('', False, '---------') in form['ou'].options
|
253 |
260 |
resp.form.set('password', 'easy')
|
|
261 |
with pytest.raises(KeyError):
|
|
262 |
# forcing values not presented by the Select2ModelMultipleChoiceField,
|
|
263 |
# should not happen in UI
|
|
264 |
form['apiclient_roles'].force_value([role_1.id, role_2.id])
|
|
265 |
form.submit()
|
|
266 |
form['apiclient_roles'].force_value([role_1.id, role_3.id])
|
254 |
267 |
response = form.submit().follow()
|
255 |
268 |
assert urlparse(response.request.url).path == api_client.get_absolute_url()
|
256 |
269 |
assert APIClient.objects.count() == 1
|
... | ... | |
259 |
272 |
|
260 |
273 |
|
261 |
274 |
def test_edit_local_admin(admin_ou1, app, ou1, ou2):
|
|
275 |
role_1 = Role.objects.create(name='role-1', ou=ou1)
|
|
276 |
role_2 = Role.objects.create(name='role-2', ou=ou2)
|
|
277 |
role_3 = Role.objects.create(name='role-3', ou=ou1)
|
262 |
278 |
api_client_ou1 = APIClient.objects.create(
|
263 |
279 |
name='foo',
|
264 |
280 |
description='foo-description',
|
... | ... | |
278 |
294 |
assert form.get('password').value == 'foo-password'
|
279 |
295 |
resp.form.set('password', 'easy')
|
280 |
296 |
assert ('', False, '---------') not in form['ou'].options
|
|
297 |
with pytest.raises(KeyError):
|
|
298 |
# forcing values not presented by the Select2ModelMultipleChoiceField,
|
|
299 |
# should not happen in UI
|
|
300 |
form['apiclient_roles'].force_value([role_1.id, role_2.id])
|
|
301 |
form.submit()
|
|
302 |
form['apiclient_roles'].force_value([role_1.id, role_3.id])
|
281 |
303 |
response = form.submit().follow()
|
282 |
304 |
assert urlparse(response.request.url).path == api_client_ou1.get_absolute_url()
|
283 |
305 |
api_client = APIClient.objects.get(password='easy')
|
284 |
|
-
|