From ba9d761bbef10d59cabc9812d2f1a4e30858a231 Mon Sep 17 00:00:00 2001
From: Paul Marillonnet <pmarillonnet@entrouvert.com>
Date: Tue, 24 Sep 2019 17:13:12 +0200
Subject: [PATCH 4/4] adapt manager tests (#34133)

---
 tests/test_manager.py | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/tests/test_manager.py b/tests/test_manager.py
index 04ed5c0d3..518b289f0 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -41,19 +41,11 @@ Role = get_role_model()
 def test_manager_login(superuser_or_admin, app):
     manager_home_page = login(app, superuser_or_admin, reverse('a2-manager-homepage'))
 
-    sections = ['users', 'roles', 'ous']
-    no_sections = ['services']
-    if superuser_or_admin.is_superuser:
-        sections += no_sections
-        no_sections = []
+    sections = ['users', 'roles', 'ous', 'services']
 
     for section in sections:
         path = reverse('a2-manager-%s' % section)
         assert manager_home_page.pyquery.remove_namespaces()('.apps a[href=\'%s\']' % path)
-    for section in no_sections:
-        path = reverse('a2-manager-%s' % section)
-        assert not manager_home_page.pyquery.remove_namespaces()('.apps a[href=\'%s\']' % path)
-
 
 def test_manager_create_ou(superuser_or_admin, app):
     ou_add = login(app, superuser_or_admin, path=reverse('a2-manager-ou-add'))
@@ -332,9 +324,9 @@ def test_manager_one_ou(app, superuser, admin, simple_role, settings):
         form.set('search-internals', True)
         response = form.submit()
         q = response.pyquery.remove_namespaces()
-        assert len(q('table tbody tr')) == 5
+        assert len(q('table tbody tr')) == 6
         # admin enroled only in the Manager role, other roles are inherited
-        assert len(q('table tbody tr td.via')) == 5
+        assert len(q('table tbody tr td.via')) == 6
         assert len(q('table tbody tr td.via:empty')) == 2
         for elt in q('table tbody td.name a'):
             assert 'Manager' in elt.text or elt.text == 'simple role'
@@ -349,7 +341,7 @@ def test_manager_one_ou(app, superuser, admin, simple_role, settings):
         response.form.set('search-internals', True)
         response = response.form.submit()
         q = response.pyquery.remove_namespaces()
-        assert len(q('table tbody tr')) == 5
+        assert len(q('table tbody tr')) == 6
         for elt in q('table tbody td.name a'):
             assert 'Manager' in elt.text or elt.text == u'simple role'
 
@@ -401,9 +393,9 @@ def test_manager_many_ou(app, superuser, admin, simple_role, role_ou1, admin_ou1
         form.set('search-internals', True)
         response = form.submit()
         q = response.pyquery.remove_namespaces()
-        assert len(q('table tbody tr')) == 4
+        assert len(q('table tbody tr')) == 5
         # admin enroled only in the Manager role, other roles are inherited
-        assert len(q('table tbody tr td.via')) == 4
+        assert len(q('table tbody tr td.via')) == 5
         assert len(q('table tbody tr td.via:empty')) == 1
         for elt in q('table tbody td.name a'):
             assert 'Manager' in elt.text
@@ -413,7 +405,7 @@ def test_manager_many_ou(app, superuser, admin, simple_role, role_ou1, admin_ou1
         form.set('search-internals', True)
         response = form.submit()
         q = response.pyquery.remove_namespaces()
-        assert len(q('table tbody tr')) == 6
+        assert len(q('table tbody tr')) == 7
         for elt in q('table tbody td.name a'):
             assert 'Manager' in elt.text
 
@@ -437,7 +429,7 @@ def test_manager_many_ou(app, superuser, admin, simple_role, role_ou1, admin_ou1
         response.form.set('search-internals', True)
         response = response.form.submit()
         q = response.pyquery.remove_namespaces()
-        assert len(q('table tbody tr')) == 12
+        assert len(q('table tbody tr')) == 15
         for elt in q('table tbody td.name a'):
             assert ('OU1' in elt.text or 'Default' in elt.text or 'Manager' in elt.text
                     or elt.text == u'simple role' or elt.text == u'role_ou1')
@@ -446,7 +438,7 @@ def test_manager_many_ou(app, superuser, admin, simple_role, role_ou1, admin_ou1
         response.form.set('search-internals', True)
         response = response.form.submit()
         q = response.pyquery.remove_namespaces()
-        assert len(q('table tbody tr')) == 6
+        assert len(q('table tbody tr')) == 7
         for elt in q('table tbody td.name a'):
             assert 'Manager' in elt.text
 
@@ -493,9 +485,9 @@ def test_manager_many_ou(app, superuser, admin, simple_role, role_ou1, admin_ou1
         response.form.set('search-internals', True)
         response = response.form.submit()
         q = response.pyquery.remove_namespaces()
-        assert len(q('table tbody tr')) == 3
+        assert len(q('table tbody tr')) == 4
         names = {elt.text for elt in q('table tbody td.name a')}
-        assert names == {'Roles - OU1', 'Users - OU1', 'role_ou1'}
+        assert names == {'Roles - OU1', 'Users - OU1', 'Services - OU1', 'role_ou1'}
 
         # test role listing
         response = app.get('/manage/roles/')
@@ -514,9 +506,9 @@ def test_manager_many_ou(app, superuser, admin, simple_role, role_ou1, admin_ou1
         response.form.set('search-internals', True)
         response = response.form.submit()
         q = response.pyquery.remove_namespaces()
-        assert len(q('table tbody tr')) == 3
+        assert len(q('table tbody tr')) == 4
         names = {elt.text for elt in q('table tbody td.name a')}
-        assert names == {'Roles - OU1', 'Users - OU1', 'role_ou1'}
+        assert names == {'Roles - OU1', 'Users - OU1', 'Services - OU1', 'role_ou1'}
 
     test_user_listing_ou_admin(admin_ou1)
 
-- 
2.23.0

