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.
This commit is contained in:
Benjamin Dauvergne 2022-12-13 16:15:14 +01:00
parent c2aed1b25d
commit ee9509b003
1 changed files with 12 additions and 14 deletions

View File

@ -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