Projet

Général

Profil

0001-tests-simplify-checks-on-roles-for-authentic-s-hobo-.patch

Benjamin Dauvergne, 13 décembre 2022 16:16

Télécharger (3,03 ko)

Voir les différences:

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(-)
tests_authentic/test_hobo_deploy.py
454 454
        # Two services loaded roles.json, so there must be 6 roles associated
455 455
        # to their "ou" excluding their superuser role, 4 admin roles for users,
456 456
        # roles, services and authenticators, and 2 loaded roles, petite enfance and état-civil
457
        assert Role.objects.filter(ou__isnull=False, service__isnull=True).count() == 12
457
        #
458
        # 2 loaded roles * 2 ous
459
        ou_roles = Role.objects.filter(ou__isnull=False, service__isnull=True)
460
        loaded_roles = ou_roles.filter(name__in=['Service petite enfance', 'Service état-civil'])
461
        assert loaded_roles.count() == 4
462
        assert len(set(loaded_roles.values_list('ou_id'))) == 2
463
        # at least 8 administrators roles in 2 ous
464
        admin_roles = ou_roles.exclude(name__in=['Service petite enfance', 'Service état-civil'])
465
        assert admin_roles.count() > 8
466
        assert len(set(admin_roles.values_list('ou_id'))) == 2
458 467
        for service_id in {s['service-id'] for s in other_services}:
459 468
            same_services = [s for s in other_services if s['service-id'] == service_id]
460 469
            for i, service in enumerate(same_services):
......
500 509
                    == 1
501 510
                )
502 511
                if service.get('template_name'):
503
                    assert Role.objects.filter(ou=provider.ou, service__isnull=True).count() == 6
504
                    assert (
505
                        Role.objects.filter(
506
                            ou=provider.ou, service__isnull=True, name='Service petite enfance'
507
                        ).count()
508
                        == 1
509
                    )
510
                    assert (
511
                        Role.objects.filter(
512
                            ou=provider.ou, service__isnull=True, name='Service état-civil'
513
                        ).count()
514
                        == 1
515
                    )
512
                    assert loaded_roles.filter(ou=provider.ou).count() == 2
513
                    assert admin_roles.filter(ou=provider.ou).count() > 4
516 514

  
517 515
    with mock.patch('hobo.agent.authentic2.provisionning.notify_agents') as mock_notify, mock.patch(
518 516
        'hobo.agent.authentic2.management.commands.hobo_deploy.sleep', wraps=time.sleep
519
-