From 1ccf9ec535a2b1dd249e788cbc827f61def70cc2 Mon Sep 17 00:00:00 2001 From: Paul Marillonnet Date: Wed, 16 Mar 2022 17:26:28 +0100 Subject: [PATCH] misc: add support for bullseye's django-tables2 (#62783) (and its subsequent changes in authentic2 -- #62527) --- src/authentic2_cut/apps.py | 6 +++--- tests/test_hooks.py | 33 +++++++++++++++++++++++++++++++++ tox.ini | 10 ++++++---- 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 tests/test_hooks.py diff --git a/src/authentic2_cut/apps.py b/src/authentic2_cut/apps.py index 1669a58..052d75e 100644 --- a/src/authentic2_cut/apps.py +++ b/src/authentic2_cut/apps.py @@ -255,7 +255,7 @@ class AppConfig(django.apps.AppConfig): base_columns = copy.deepcopy(type(table).base_columns) if ou and ou.slug == 'usagers': - for column_name in ['username', 'link']: + for column_name in ['username', 'get_full_name']: if column_name in base_columns: del base_columns[column_name] if column_name in sequence: @@ -271,8 +271,8 @@ class AppConfig(django.apps.AppConfig): ) sequence += ['validated'] else: - del base_columns['link'] - sequence.remove('link') + del base_columns['get_full_name'] + sequence.remove('get_full_name') table.base_columns = base_columns table.sequence = sequence diff --git a/tests/test_hooks.py b/tests/test_hooks.py new file mode 100644 index 0000000..a02e00f --- /dev/null +++ b/tests/test_hooks.py @@ -0,0 +1,33 @@ +from authentic2.manager.tables import UserTable +from authentic2.manager.user_views import UsersView +from utils import login + +from authentic2_cut.apps import AppConfig + + +def test_a2_hook_manager_modify_table(db, rf, admin, monkeypatch, app): + class DummyModule: + __path__ = [ + './dummy', + ] + + dummy = DummyModule() + app_config = AppConfig('authentic2_cut', dummy) + user_table = UserTable(data={}) + request = rf.get('/manage/users/') + request.user = admin + users_view = UsersView.as_view()(request) + + # base table contains a2 generic column + assert 'get_full_name' in list(user_table.sequence) + assert len(list(user_table.sequence)) == 6 + assert 'get_full_name' in user_table.base_columns + assert len(list(user_table.base_columns)) == 6 + + # does not crash when explicitely run + app_config.a2_hook_manager_modify_table(users_view, user_table) + + # and most of all the rendered table does not contain any such column + response = login(app, admin, '/manage/users/') + assert 'get_full_name' not in response.html + assert len(response.pyquery.find('thead').find('tr').children()) == 5 diff --git a/tox.ini b/tox.ini index 2dc2aa1..df501d3 100644 --- a/tox.ini +++ b/tox.ini @@ -6,11 +6,13 @@ [tox] toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/authentic2-cut/{env:BRANCH_NAME:} envlist = - py3-dj22-drf3{9,12} + py3-dj22-drf39-djtables1211 + py3-dj22-drf312-djtables211 [tox:jenkins] envlist = - py3-dj22-drf3{9,12} + py3-dj22-drf39-djtables1211 + py3-dj22-drf312-djtables211 check-migrations code-style pylint @@ -38,8 +40,8 @@ deps = py3: file-magic drf39: djangorestframework>=3.9.2,<3.10 drf312: djangorestframework>=3.12,<3.13 - dj22: django<2.3 - django-tables<2.0 + djtables1211: django-tables2==1.21.1 + djtables211: django-tables2==2.1.1 psycopg2-binary<2.9 oldldap: python-ldap<3 ldaptools