Skip to content

Commit

Permalink
Add public flag in Program (#1181)
Browse files Browse the repository at this point in the history
* add RuntimeJob table

Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
  • Loading branch information
akihikokuroda authored Jan 25, 2024
1 parent 7d0c3c4 commit dec41cb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
18 changes: 18 additions & 0 deletions gateway/api/migrations/0015_program_public.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
1 change: 1 addition & 0 deletions gateway/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="{}")
Expand Down
1 change: 1 addition & 0 deletions gateway/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Meta(serializers.ProgramSerializer.Meta):
"artifact",
"dependencies",
"arguments",
"public",
]


Expand Down
34 changes: 34 additions & 0 deletions gateway/tests/api/test_v1_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit dec41cb

Please sign in to comment.