Skip to content

Commit

Permalink
🧪 [#4689] Added regression test for file uploads in repeating groups
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Jan 30, 2025
1 parent 934bb7a commit 2ed958c
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
interactions:
- request:
body: '{"informatieobjecttype": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7",
"bronorganisatie": "000000000", "creatiedatum": "2024-03-19", "titel": "Form
001", "auteur": "Aanvrager", "taal": "nld", "formaat": "application/ogg", "inhoud":
"Y29udGVudA==", "status": "definitief", "bestandsnaam": "foo-0.bin", "ontvangstdatum":
"2024-03-06", "beschrijving": "Bijgevoegd document", "indicatieGebruiksrecht":
false, "bestandsomvang": 7}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0X2NsaWVudF9pZCIsImlhdCI6MTcxMDg1NTYzNCwiY2xpZW50X2lkIjoidGVzdF9jbGllbnRfaWQiLCJ1c2VyX2lkIjoiIiwidXNlcl9yZXByZXNlbnRhdGlvbiI6IiJ9.NJjZEPSwh9eGzntjwUB7rFAiaq_5DqYgVylWuKdtdMA
Connection:
- keep-alive
Content-Length:
- '479'
Content-Type:
- application/json
User-Agent:
- python-requests/2.32.2
method: POST
uri: http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten
response:
body:
string: '{"url":"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/db57bb11-cd3d-4a0e-8784-9ac308f5ab7b","identificatie":"DOCUMENT-2024-0000000094","bronorganisatie":"000000000","creatiedatum":"2024-03-19","titel":"Form
001","vertrouwelijkheidaanduiding":"openbaar","auteur":"Aanvrager","status":"definitief","formaat":"application/ogg","taal":"nld","versie":1,"beginRegistratie":"2025-01-29T13:43:03.815170Z","bestandsnaam":"foo-0.bin","inhoud":"http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/db57bb11-cd3d-4a0e-8784-9ac308f5ab7b/download?versie=1","bestandsomvang":7,"link":"","beschrijving":"Bijgevoegd
document","ontvangstdatum":"2024-03-06","verzenddatum":null,"indicatieGebruiksrecht":false,"verschijningsvorm":"","ondertekening":{"soort":"","datum":null},"integriteit":{"algoritme":"","waarde":"","datum":null},"informatieobjecttype":"http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7","locked":false,"bestandsdelen":[],"trefwoorden":[],"lock":""}'
headers:
API-version:
- 1.4.2
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '1035'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Location:
- http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/db57bb11-cd3d-4a0e-8784-9ac308f5ab7b
Referrer-Policy:
- same-origin
Vary:
- origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
status:
code: 201
message: Created
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Token 171be5abaf41e7856b423ad513df1ef8f867ff48
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.2
method: GET
uri: http://localhost:8001/api/v2/objecttypes/8faed0fa-7864-4409-aa6d-533a37616a9e
response:
body:
string: '{"url":"http://objecttypes-web:8000/api/v2/objecttypes/8faed0fa-7864-4409-aa6d-533a37616a9e","uuid":"8faed0fa-7864-4409-aa6d-533a37616a9e","name":"Accepts
everything","namePlural":"Accepts everything","description":"","dataClassification":"open","maintainerOrganization":"","maintainerDepartment":"","contactPerson":"","contactEmail":"","source":"","updateFrequency":"unknown","providerOrganization":"","documentationUrl":"","labels":{},"createdAt":"2024-07-22","modifiedAt":"2024-07-22","allowGeometry":true,"versions":["http://objecttypes-web:8000/api/v2/objecttypes/8faed0fa-7864-4409-aa6d-533a37616a9e/versions/1"]}'
headers:
Allow:
- GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Connection:
- keep-alive
Content-Length:
- '619'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 29 Jan 2025 13:43:03 GMT
Referrer-Policy:
- same-origin
Server:
- nginx/1.27.3
Vary:
- origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
status:
code: 200
message: OK
- request:
body: '{"type": "http://objecttypes-web:8000/api/v2/objecttypes/8faed0fa-7864-4409-aa6d-533a37616a9e",
"record": {"typeVersion": 1, "data": {"repeatingGroup": ["http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/db57bb11-cd3d-4a0e-8784-9ac308f5ab7b"]},
"startAt": "2024-03-19"}}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Token 7657474c3d75f56ae0abd0d1bf7994b09964dca9
Connection:
- keep-alive
Content-Crs:
- EPSG:4326
Content-Length:
- '290'
Content-Type:
- application/json
User-Agent:
- python-requests/2.32.2
method: POST
uri: http://localhost:8002/api/v2/objects
response:
body:
string: '{"url":"http://objects-web:8000/api/v2/objects/75f65dae-4711-4bb6-95cf-513b709ec401","uuid":"75f65dae-4711-4bb6-95cf-513b709ec401","type":"http://objecttypes-web:8000/api/v2/objecttypes/8faed0fa-7864-4409-aa6d-533a37616a9e","record":{"index":1,"typeVersion":1,"data":{"repeatingGroup":["http://localhost:8003/documenten/api/v1/enkelvoudiginformatieobjecten/db57bb11-cd3d-4a0e-8784-9ac308f5ab7b"]},"geometry":null,"startAt":"2024-03-19","endAt":null,"registrationAt":"2025-01-29","correctionFor":null,"correctedBy":null}}'
headers:
Allow:
- GET, POST, HEAD, OPTIONS
Connection:
- keep-alive
Content-Crs:
- EPSG:4326
Content-Length:
- '520'
Content-Type:
- application/json
Cross-Origin-Opener-Policy:
- same-origin
Date:
- Wed, 29 Jan 2025 13:43:03 GMT
Location:
- http://localhost:8002/api/v2/objects/75f65dae-4711-4bb6-95cf-513b709ec401
Referrer-Policy:
- same-origin
Server:
- nginx/1.27.3
Vary:
- origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
status:
code: 201
message: Created
version: 1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from openforms.authentication.service import AuthAttribute
from openforms.contrib.objects_api.tests.factories import ObjectsAPIGroupConfigFactory
from openforms.formio.tests.factories import SubmittedFileFactory
from openforms.payments.constants import PaymentStatus
from openforms.payments.tests.factories import SubmissionPaymentFactory
from openforms.submissions.tests.factories import (
Expand Down Expand Up @@ -398,6 +399,91 @@ def test_submission_with_file_components_container_variable(self):
self.assertIsInstance(result["record"]["data"]["multiple_files"], list)
self.assertEqual(len(result["record"]["data"]["multiple_files"]), 2)

@tag("gh-4689")
def test_submission_with_editgrid_with_nested_files(self):
formio_upload = SubmittedFileFactory.build()
submission = SubmissionFactory.from_components(
[
{
"key": "repeatingGroup",
"type": "editgrid",
"label": "Repeating group",
"components": [
{
"key": "email",
"type": "email",
"label": "Email",
},
{
"key": "file",
"type": "file",
"multiple": False,
},
],
},
],
submitted_data={
"repeatingGroup": [
{
"email": "info@example.com",
"file": formio_upload,
}
],
},
completed=True,
)
submission_step = submission.steps[0]
attachment = SubmissionFileAttachmentFactory.create(
submission_step=submission_step,
form_key="repeatingGroup",
file_name=formio_upload["originalName"],
original_name=formio_upload["originalName"],
_component_configuration_path="components.0.components.1",
_component_data_path="repeatingGroup.0.file",
)

v2_options: RegistrationOptionsV2 = {
"version": 2,
"objects_api_group": self.objects_api_group,
# See the docker compose fixtures for more info on these values:
"objecttype": UUID("8faed0fa-7864-4409-aa6d-533a37616a9e"),
"objecttype_version": 1,
"upload_submission_csv": False,
"update_existing_object": False,
"auth_attribute_path": [],
"informatieobjecttype_attachment": "http://localhost:8003/catalogi/api/v1/informatieobjecttypen/531f6c1a-97f7-478c-85f0-67d2f23661c7",
"organisatie_rsin": "000000000",
"variables_mapping": [
{
"variable_key": "repeatingGroup",
"target_path": ["repeatingGroup"],
},
],
"iot_attachment": "",
"iot_submission_csv": "",
"iot_submission_report": "",
}

plugin = ObjectsAPIRegistration(PLUGIN_IDENTIFIER)

# Run the registration
result = plugin.register_submission(submission, v2_options)
assert result is not None

objects_api_attachment = (
attachment.objectsapisubmissionattachment_set.get() # pyright: ignore[reportAttributeAccessIssue]
)
record_data = result["record"]["data"]
expected = {
"repeatingGroup": [
{
"email": "info@example.com",
"file": objects_api_attachment.document_url,
}
],
}
self.assertEqual(record_data, expected)

def test_submission_with_empty_optional_file(self):
submission = SubmissionFactory.from_components(
[
Expand Down

0 comments on commit 2ed958c

Please sign in to comment.