From ee9509b003196a1b7258da9b8b4218acd7dc8339 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 13 Dec 2022 16:15:14 +0100 Subject: [PATCH] tests: simplify checks on roles for authentic's hobo-deploy (#72354) We check the presence of loaded roles and for automatic we check a mininal number of them are present. --- tests_authentic/test_hobo_deploy.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tests_authentic/test_hobo_deploy.py b/tests_authentic/test_hobo_deploy.py index 2a6beb7..fff9160 100644 --- a/tests_authentic/test_hobo_deploy.py +++ b/tests_authentic/test_hobo_deploy.py @@ -454,7 +454,16 @@ def test_hobo_deploy(monkeypatch, tenant_base, mocker, skeleton_dir, tmp_path): # Two services loaded roles.json, so there must be 6 roles associated # to their "ou" excluding their superuser role, 4 admin roles for users, # roles, services and authenticators, and 2 loaded roles, petite enfance and état-civil - assert Role.objects.filter(ou__isnull=False, service__isnull=True).count() == 12 + # + # 2 loaded roles * 2 ous + ou_roles = Role.objects.filter(ou__isnull=False, service__isnull=True) + loaded_roles = ou_roles.filter(name__in=['Service petite enfance', 'Service état-civil']) + assert loaded_roles.count() == 4 + assert len(set(loaded_roles.values_list('ou_id'))) == 2 + # at least 8 administrators roles in 2 ous + admin_roles = ou_roles.exclude(name__in=['Service petite enfance', 'Service état-civil']) + assert admin_roles.count() > 8 + assert len(set(admin_roles.values_list('ou_id'))) == 2 for service_id in {s['service-id'] for s in other_services}: same_services = [s for s in other_services if s['service-id'] == service_id] for i, service in enumerate(same_services): @@ -500,19 +509,8 @@ def test_hobo_deploy(monkeypatch, tenant_base, mocker, skeleton_dir, tmp_path): == 1 ) if service.get('template_name'): - assert Role.objects.filter(ou=provider.ou, service__isnull=True).count() == 6 - assert ( - Role.objects.filter( - ou=provider.ou, service__isnull=True, name='Service petite enfance' - ).count() - == 1 - ) - assert ( - Role.objects.filter( - ou=provider.ou, service__isnull=True, name='Service état-civil' - ).count() - == 1 - ) + assert loaded_roles.filter(ou=provider.ou).count() == 2 + assert admin_roles.filter(ou=provider.ou).count() > 4 with mock.patch('hobo.agent.authentic2.provisionning.notify_agents') as mock_notify, mock.patch( 'hobo.agent.authentic2.management.commands.hobo_deploy.sleep', wraps=time.sleep -- 2.37.2