From b9b4f85e669016652466a03c0d5b2c741844dc0b Mon Sep 17 00:00:00 2001 From: David <9059044+Tansito@users.noreply.github.com> Date: Fri, 26 Jul 2024 09:16:38 -0400 Subject: [PATCH] Fix functions assignment task (#1423) * Fix functions assignment task * Include a test taking into account this use case --- gateway/api/tasks/programs.py | 4 ++-- gateway/tests/api/tasks/test_tasks.py | 17 ++++++++++------- gateway/tests/fixtures/tasks_fixtures.json | 8 ++++++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/gateway/api/tasks/programs.py b/gateway/api/tasks/programs.py index 9a62e87b1..d16839be7 100644 --- a/gateway/api/tasks/programs.py +++ b/gateway/api/tasks/programs.py @@ -51,15 +51,15 @@ def assign_run_permission(): else: run_permission = Permission.objects.get(codename=RUN_PROGRAM_PERMISSION) + groups = [] for instance_title in instances_titles: - groups = [] group = Group.objects.filter(name=instance_title).first() if group is None: logger.warning("Group [%s] does not exist", instance_title) else: logger.info("Group [%s] does not exist", instance_title) group.permissions.add(run_permission) - groups.append(group) + groups.append(group) logger.info( "Program [%s] is going to be updated with [%s] groups", diff --git a/gateway/tests/api/tasks/test_tasks.py b/gateway/tests/api/tasks/test_tasks.py index f0b3d2dac..c8a943120 100644 --- a/gateway/tests/api/tasks/test_tasks.py +++ b/gateway/tests/api/tasks/test_tasks.py @@ -26,7 +26,7 @@ def test_assign_admin_group(self): PROVIDERS_CONFIGURATION='{"test_provider": {"admin_group": "runner", "registry": "docker.io/"}}' ) @override_settings( - FUNCTIONS_PERMISSIONS='{"function_provider": {"provider": "test_provider", "instances": ["runner"]}}' + FUNCTIONS_PERMISSIONS='{"function_provider": {"provider": "test_provider", "instances": ["runner", "manager"]}}' ) def test_assign_run_permission(self): providers.assign_admin_group() @@ -44,17 +44,20 @@ def test_assign_run_permission(self): "provider": "test_provider", }, ) - print(programs_response.content) self.assertEqual(programs_response.status_code, status.HTTP_200_OK) programs.assign_run_permission() program = Program.objects.get(title="function_provider") - self.assertEqual(len(program.instances.all()), 1) + self.assertEqual(len(program.instances.all()), 2) self.assertEqual(program.instances.all()[0].name, "runner") - - group = program.instances.all()[0] - self.assertEqual(len(group.permissions.all()), 2) + self.assertEqual(program.instances.all()[1].name, "manager") run_permission = models.Permission.objects.get(codename=RUN_PROGRAM_PERMISSION) - self.assertTrue(group.permissions.filter(id=run_permission.pk).exists()) + runner_group = program.instances.all()[0] + self.assertEqual(len(runner_group.permissions.all()), 2) + self.assertTrue(runner_group.permissions.filter(id=run_permission.pk).exists()) + + manager_group = program.instances.all()[1] + self.assertEqual(len(manager_group.permissions.all()), 2) + self.assertTrue(manager_group.permissions.filter(id=run_permission.pk).exists()) diff --git a/gateway/tests/fixtures/tasks_fixtures.json b/gateway/tests/fixtures/tasks_fixtures.json index 69c407321..1a3191285 100644 --- a/gateway/tests/fixtures/tasks_fixtures.json +++ b/gateway/tests/fixtures/tasks_fixtures.json @@ -19,6 +19,14 @@ "name": "runner", "permissions": [60] } + }, + { + "model": "auth.group", + "pk": 101, + "fields": { + "name": "manager", + "permissions": [60] + } } ] \ No newline at end of file