Skip to content

Commit

Permalink
None description shouldnt be updated (#1508)
Browse files Browse the repository at this point in the history
* description shouldnt be updated

* linter
  • Loading branch information
korgan00 authored Oct 9, 2024
1 parent 69c350b commit a8c4489
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gateway/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ def update(self, instance, validated_data):
instance.artifact = validated_data.get("artifact")
instance.author = validated_data.get("author")
instance.image = validated_data.get("image")
instance.description = validated_data.get("description")

description = validated_data.get("description")
if description is not None:
instance.description = description

instance.save()
return instance

Expand Down
46 changes: 46 additions & 0 deletions gateway/tests/api/test_v1_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,49 @@ def test_get_jobs(self):
)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_upload_private_function_update_without_description(self):
"""Tests upload end-point authorized."""

fake_file = ContentFile(b"print('Hello World')")
fake_file.name = "test_run.tar"

user = models.User.objects.get(username="test_user")
self.client.force_authenticate(user=user)
programs_response = self.client.post(
"/api/v1/programs/upload/",
data={
"title": "Program",
"entrypoint": "test_user_2_program.py",
"dependencies": "[]",
"artifact": fake_file,
},
)

self.assertEqual(programs_response.status_code, status.HTTP_200_OK)
self.assertEqual(
programs_response.data.get("description"), "Program description test"
)

def test_upload_private_function_update_description(self):
"""Tests upload end-point authorized."""

fake_file = ContentFile(b"print('Hello World')")
fake_file.name = "test_run.tar"

user = models.User.objects.get(username="test_user")
self.client.force_authenticate(user=user)
description = "New program description test"
programs_response = self.client.post(
"/api/v1/programs/upload/",
data={
"title": "Program",
"entrypoint": "test_user_2_program.py",
"description": description,
"dependencies": "[]",
"artifact": fake_file,
},
)

self.assertEqual(programs_response.status_code, status.HTTP_200_OK)
self.assertEqual(programs_response.data.get("description"), description)
45 changes: 45 additions & 0 deletions gateway/tests/api/test_v1_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,48 @@ def test_upload_program_serializer_blocked_dependency(self):

serializer = UploadProgramSerializer(data=data)
self.assertFalse(serializer.is_valid())

def test_upload_program_serializer_updates_program_without_description(self):
path_to_resource_artifact = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"..",
"resources",
"artifact.tar",
)
file_data = File(open(path_to_resource_artifact, "rb"))
upload_file = SimpleUploadedFile(
"artifact.tar", file_data.read(), content_type="multipart/form-data"
)

user = models.User.objects.get(username="test_user")

title = "Hello world"
entrypoint = "pattern.py"
arguments = "{}"
dependencies = "[]"
description = "This is my old description"

data = {}
data["title"] = title
data["entrypoint"] = entrypoint
data["arguments"] = arguments
data["dependencies"] = dependencies
data["description"] = description
data["artifact"] = upload_file

serializer = UploadProgramSerializer(data=data)
serializer.is_valid()
program: Program = serializer.save(author=user)
self.assertEqual(description, program.description)

data_without_description = {}
data_without_description["title"] = title
data_without_description["entrypoint"] = entrypoint
data_without_description["arguments"] = arguments
data_without_description["dependencies"] = dependencies
data_without_description["artifact"] = upload_file

serializer_2 = UploadProgramSerializer(program, data=data_without_description)
serializer_2.is_valid()
program_2: Program = serializer_2.save(author=user)
self.assertEqual(description, program_2.description)
1 change: 1 addition & 0 deletions gateway/tests/fixtures/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"fields": {
"created": "2023-02-01T15:30:43.281796Z",
"title": "Program",
"description": "Program description test",
"entrypoint": "program.py",
"artifact": "path",
"author": 1,
Expand Down

0 comments on commit a8c4489

Please sign in to comment.