From dec41cbbd201e6cf853b0e100c3509ccf6e0f433 Mon Sep 17 00:00:00 2001 From: "Akihiko (Aki) Kuroda" <16141898+akihikokuroda@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:30:44 -0500 Subject: [PATCH] Add `public` flag in Program (#1181) * add RuntimeJob table Signed-off-by: Akihiko Kuroda --- gateway/api/migrations/0015_program_public.py | 18 ++++++++++ gateway/api/models.py | 1 + gateway/api/v1/serializers.py | 1 + gateway/tests/api/test_v1_program.py | 34 +++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 gateway/api/migrations/0015_program_public.py diff --git a/gateway/api/migrations/0015_program_public.py b/gateway/api/migrations/0015_program_public.py new file mode 100644 index 000000000..2d42004c6 --- /dev/null +++ b/gateway/api/migrations/0015_program_public.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.2 on 2024-01-21 14:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("api", "0014_runtimejob"), + ] + + operations = [ + migrations.AddField( + model_name="program", + name="public", + field=models.BooleanField(default=False), + ), + ] diff --git a/gateway/api/models.py b/gateway/api/models.py index 768d8d1c9..b1e8da84d 100644 --- a/gateway/api/models.py +++ b/gateway/api/models.py @@ -69,6 +69,7 @@ class Program(ExportModelOperationsMixin("program"), models.Model): settings.AUTH_USER_MODEL, on_delete=models.CASCADE, ) + public = models.BooleanField(null=False, default=False) arguments = models.TextField(null=False, blank=True, default="{}") env_vars = models.TextField(null=False, blank=True, default="{}") diff --git a/gateway/api/v1/serializers.py b/gateway/api/v1/serializers.py index b19c337eb..28f76066d 100644 --- a/gateway/api/v1/serializers.py +++ b/gateway/api/v1/serializers.py @@ -17,6 +17,7 @@ class Meta(serializers.ProgramSerializer.Meta): "artifact", "dependencies", "arguments", + "public", ] diff --git a/gateway/tests/api/test_v1_program.py b/gateway/tests/api/test_v1_program.py index 757ce7e30..0af333288 100644 --- a/gateway/tests/api/test_v1_program.py +++ b/gateway/tests/api/test_v1_program.py @@ -81,3 +81,37 @@ def test_run_existing(self): self.assertEqual(job.config.max_workers, 5) self.assertEqual(job.config.workers, None) self.assertEqual(job.config.auto_scaling, True) + + def test_public(self): + """Tests public flag.""" + auth = reverse("rest_login") + response = self.client.post( + auth, {"username": "test_user", "password": "123"}, format="json" + ) + token = response.data.get("access") + self.client.credentials(HTTP_AUTHORIZATION="Bearer " + token) + + programs_response = self.client.get( + "/api/v1/programs/1a7947f9-6ae8-4e3d-ac1e-e7d608deec82/", + format="json", + ) + print(programs_response.json()) + public = programs_response.json()["public"] + self.assertEqual(public, False) + + programs_response = self.client.patch( + "/api/v1/programs/1a7947f9-6ae8-4e3d-ac1e-e7d608deec82/", + data={ + "public": True, + }, + format="json", + ) + self.assertEqual(programs_response.status_code, status.HTTP_200_OK) + + programs_response = self.client.get( + "/api/v1/programs/1a7947f9-6ae8-4e3d-ac1e-e7d608deec82/", + format="json", + ) + print(programs_response.json()) + public = programs_response.json()["public"] + self.assertEqual(public, True)