summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorValentin Deniaud <vdeniaud@entrouvert.com>2020-10-20 12:27:14 (GMT)
committerValentin Deniaud <vdeniaud@entrouvert.com>2020-10-20 13:15:50 (GMT)
commitb0f6c1977f5824c5360fcd6b2c9a81dcd1fbb857 (patch)
tree9b266a4bbae711d75123d3e3cc322cc1fafd7450
parent911f847b24184c68b86e7e9b5a0ddb2714923b4f (diff)
downloadauthentic-wip/45338-Avoir-la-collectivite-par-defaut.zip
authentic-wip/45338-Avoir-la-collectivite-par-defaut.tar.gz
authentic-wip/45338-Avoir-la-collectivite-par-defaut.tar.bz2
manager: select default ou in users table (#45338)wip/45338-Avoir-la-collectivite-par-defaut
-rw-r--r--src/authentic2/manager/forms.py2
-rw-r--r--tests/test_manager.py7
-rw-r--r--tests/test_user_manager.py5
3 files changed, 10 insertions, 4 deletions
diff --git a/src/authentic2/manager/forms.py b/src/authentic2/manager/forms.py
index 5dbdcd8..6937c46 100644
--- a/src/authentic2/manager/forms.py
+++ b/src/authentic2/manager/forms.py
@@ -576,6 +576,8 @@ class UserSearchForm(OUSearchForm, CssClass, PrefixFormMixin, FormWithRequest):
def __init__(self, *args, **kwargs):
self.minimum_chars = kwargs.pop('minimum_chars', 0)
+ initial = kwargs.setdefault('initial', {})
+ initial['ou'] = str(get_default_ou().pk)
super(UserSearchForm, self).__init__(*args, **kwargs)
def not_enough_chars(self):
diff --git a/tests/test_manager.py b/tests/test_manager.py
index 68c49ec..329e2fb 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -410,14 +410,13 @@ def test_manager_many_ou(app, superuser, admin, simple_role, role_ou1, admin_ou1
options = field.options
assert len(options) == 4
for key, checked, label in options:
- assert not checked or key == 'all'
+ assert not checked or key == str(get_default_ou().pk)
assert 'all' in [o[0] for o in options]
assert 'none' in [o[0] for o in options]
# verify table shown
q = response.pyquery.remove_namespaces()
- assert len(q('table tbody tr')) == 3
- assert set([e.text for e in q('table tbody td.username')]) == {'admin', 'superuser',
- 'admin.ou1'}
+ assert len(q('table tbody tr')) == len(User.objects.filter(ou=get_default_ou()))
+ assert set([e.text for e in q('table tbody td.username')]) == {'admin'}
# test user's role page
response = app.get('/manage/users/%d/roles/' % admin.pk)
diff --git a/tests/test_user_manager.py b/tests/test_user_manager.py
index 34fbf8b..a182fd9 100644
--- a/tests/test_user_manager.py
+++ b/tests/test_user_manager.py
@@ -297,6 +297,7 @@ def test_export_csv(settings, app, superuser, django_assert_num_queries):
# queries should be batched to keep prefetching working without
# overspending memory for the queryset cache, 4 queries by batches
num_queries = int(4 + 4 * (user_count / DEFAULT_BATCH_SIZE + bool(user_count % DEFAULT_BATCH_SIZE)))
+ num_queries += 1 # get_default_ou form call
with django_assert_num_queries(num_queries):
response = response.click('CSV')
table = list(csv.reader(response.text.splitlines()))
@@ -335,6 +336,10 @@ def test_user_table(app, admin, user_ou1, ou1):
response = login(app, admin, '/manage/users/')
assert response.pyquery('td.username')
+ assert response.pyquery('select#id_search-ou option:selected').val() == str(get_default_ou().pk)
+ assert admin.username in response.text
+ assert not user_ou1.username in response.text
+
# hide all usernames, from specific and general view
OU.objects.update(show_username=False)
has_show_username.cache.clear()