mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-13 11:44:28 +00:00
Handle the multiple single file upload widget case (#195)
This commit is contained in:
parent
a404a2378d
commit
a986678869
@ -278,6 +278,9 @@ class ProcessInstanceService:
|
||||
for list_index, list_value in enumerate(value):
|
||||
if isinstance(list_value, str):
|
||||
yield (identifier, list_value, list_index)
|
||||
if isinstance(list_value, dict) and len(list_value) == 1:
|
||||
for v in list_value.values():
|
||||
yield (identifier, v, list_index)
|
||||
|
||||
@classmethod
|
||||
def file_data_models_for_data(
|
||||
@ -308,7 +311,11 @@ class ProcessInstanceService:
|
||||
if model.list_index is None:
|
||||
data[model.identifier] = digest_reference
|
||||
else:
|
||||
data[model.identifier][model.list_index] = digest_reference
|
||||
old_value = data[model.identifier][model.list_index]
|
||||
new_value: Any = digest_reference
|
||||
if isinstance(old_value, dict) and len(old_value) == 1:
|
||||
new_value = {k: digest_reference for k in old_value.keys()}
|
||||
data[model.identifier][model.list_index] = new_value
|
||||
|
||||
@classmethod
|
||||
def save_file_data_and_replace_with_digest_references(
|
||||
|
@ -89,7 +89,7 @@ class TestProcessInstanceService(BaseTest):
|
||||
self._check_sample_file_data_model("uploaded_files", 0, models[0])
|
||||
self._check_sample_file_data_model("uploaded_files", 1, models[1])
|
||||
|
||||
def test_can_create_file_data_models_for_fix_of_file_data_and_non_file_data_values(
|
||||
def test_can_create_file_data_models_for_mix_of_file_data_and_non_file_data_values(
|
||||
self,
|
||||
app: Flask,
|
||||
with_db_and_bpmn_file_cleanup: None,
|
||||
@ -122,6 +122,8 @@ class TestProcessInstanceService(BaseTest):
|
||||
) -> None:
|
||||
data = {
|
||||
"not_a_file": "just a value",
|
||||
"also_no_files": ["not a file", "also not a file"],
|
||||
"still_no_files": [{"key": "value"}],
|
||||
}
|
||||
models = ProcessInstanceService.file_data_models_for_data(data, 111)
|
||||
|
||||
@ -189,3 +191,25 @@ class TestProcessInstanceService(BaseTest):
|
||||
],
|
||||
"not_a_file3": "just a value3",
|
||||
}
|
||||
|
||||
def test_can_create_file_data_models_for_mulitple_single_file_data_values(
|
||||
self,
|
||||
app: Flask,
|
||||
with_db_and_bpmn_file_cleanup: None,
|
||||
with_super_admin_user: UserModel,
|
||||
) -> None:
|
||||
data = {
|
||||
"File": [
|
||||
{
|
||||
"supporting_files": self.SAMPLE_FILE_DATA,
|
||||
},
|
||||
{
|
||||
"supporting_files": self.SAMPLE_FILE_DATA,
|
||||
},
|
||||
],
|
||||
}
|
||||
models = ProcessInstanceService.file_data_models_for_data(data, 111)
|
||||
|
||||
assert len(models) == 2
|
||||
self._check_sample_file_data_model("File", 0, models[0])
|
||||
self._check_sample_file_data_model("File", 1, models[1])
|
||||
|
Loading…
x
Reference in New Issue
Block a user