Skip to content

Commit

Permalink
Fix functions assignment task (#1423)
Browse files Browse the repository at this point in the history
* Fix functions assignment task

* Include a test taking into account this use case
  • Loading branch information
Tansito authored Jul 26, 2024
1 parent 3c1fff4 commit b9b4f85
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions gateway/api/tasks/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 10 additions & 7 deletions gateway/tests/api/tasks/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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())
8 changes: 8 additions & 0 deletions gateway/tests/fixtures/tasks_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
"name": "runner",
"permissions": [60]
}
},
{
"model": "auth.group",
"pk": 101,
"fields": {
"name": "manager",
"permissions": [60]
}
}
]

0 comments on commit b9b4f85

Please sign in to comment.