apiclient: prefill password (#69527)
This commit is contained in:
parent
6b77f8afb0
commit
67e3f154f4
|
@ -20,6 +20,7 @@ import itertools
|
|||
import json
|
||||
import pickle
|
||||
import random
|
||||
import uuid
|
||||
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.core.exceptions import PermissionDenied, ValidationError
|
||||
|
@ -892,6 +893,11 @@ class APIClientAddView(APIClientsMixin, CreateView):
|
|||
def get_success_url(self):
|
||||
return reverse('a2-manager-api-client-detail', kwargs={'pk': self.object.pk})
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs['initial'] = {'password': str(uuid.uuid4())}
|
||||
return kwargs
|
||||
|
||||
|
||||
api_client_add = APIClientAddView.as_view()
|
||||
|
||||
|
|
|
@ -1365,6 +1365,8 @@ def test_manager_api_client_add(superuser_or_admin, app):
|
|||
role_2 = Role.objects.create(name='role-2')
|
||||
resp = login(app, superuser_or_admin, 'a2-manager-api-client-add')
|
||||
form = resp.form
|
||||
# password is prefilled
|
||||
assert form.get('password').value
|
||||
form.set('name', 'api-client-name')
|
||||
form.set('description', 'api-client-description')
|
||||
form.set('identifier', 'api-client-identifier')
|
||||
|
@ -1415,6 +1417,7 @@ def test_manager_api_client_edit(superuser_or_admin, app):
|
|||
assert APIClient.objects.count() == 1
|
||||
resp = login(app, superuser_or_admin, 'a2-manager-api-client-edit', kwargs={'pk': api_client.pk})
|
||||
form = resp.form
|
||||
assert form.get('password').value == 'foo-password'
|
||||
resp.form.set('password', 'easy')
|
||||
response = form.submit().follow()
|
||||
assert urlparse(response.request.url).path == api_client.get_absolute_url()
|
||||
|
|
Loading…
Reference in New Issue