Skip to content

Commit

Permalink
fix: clone application fixes for attachments and status change (hl-15…
Browse files Browse the repository at this point in the history
…11) (#3445)

* fix: generate cloned image as it would be uploaded

* fix: status change to handling would fail when pay subsidy not_granted and apprenticeship off
  • Loading branch information
sirtawast authored Oct 29, 2024
1 parent 6105923 commit dad6a9d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ def _validate_apprenticeship_program(
return
if (
pay_subsidy_granted == PaySubsidyGranted.NOT_GRANTED
and apprenticeship_program is not None
and apprenticeship_program not in [None, False]
):
raise serializers.ValidationError(
{
Expand Down
27 changes: 19 additions & 8 deletions backend/benefit/applications/services/clone_application.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from io import BytesIO

from django.core.files.uploadedfile import InMemoryUploadedFile
from PIL import Image

from applications.enums import ApplicationStatus, ApplicationStep
from applications.models import (
Application,
Expand All @@ -8,7 +13,6 @@
)
from calculator.models import Calculation
from companies.models import Company
from helsinkibenefit.settings import MEDIA_ROOT


def clone_application_based_on_other(
Expand Down Expand Up @@ -107,22 +111,29 @@ def _clone_handler_data(application_base, cloned_application):
application_base.additional_pay_subsidy_percent
)

# Create fake image to be used as attachment's body
from PIL import Image

attachment_name = f"test-application-{cloned_application.id}"
temp_image = Image.new("RGB", (1, 1))
temp_image = Image.new("RGB", (1, 1), 0xFFFFFF)
temp_image_io = BytesIO()
temp_image.save(
temp_image_io,
format="PNG",
fp=f"{MEDIA_ROOT}/{attachment_name}.png",
)
attachment_name = f"test-application-{cloned_application.id}.png"

file_in_memory_upload = InMemoryUploadedFile(
temp_image_io,
None,
attachment_name,
"image/png",
len(temp_image_io.getvalue()),
None,
)

# Mimick the attachments by retaining attachment type
for base_attachment in application_base.attachments.all():
Attachment.objects.create(
attachment_type=base_attachment.attachment_type,
application=cloned_application,
attachment_file=f"{attachment_name}.png",
attachment_file=file_in_memory_upload,
content_type="image/png",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ def test_submit_application_without_de_minimis_aid(
(PaySubsidyGranted.GRANTED_AGED, False, 200, 200),
(PaySubsidyGranted.GRANTED_AGED, None, 200, 400),
(PaySubsidyGranted.NOT_GRANTED, None, 200, 200),
(PaySubsidyGranted.NOT_GRANTED, False, 200, 400),
(PaySubsidyGranted.NOT_GRANTED, False, 200, 200),
(PaySubsidyGranted.NOT_GRANTED, True, 200, 400),
],
)
Expand Down

0 comments on commit dad6a9d

Please sign in to comment.