adding unit test for uploading file to model program aggregation folder
@@ -94,6 +94,36 @@ def test_create_aggregation_from_folder(composite_resource, mock_irods):
assert mp_aggregation.dataset_name == new_folder
+@pytest.mark.django_db(transaction=True)
+def test_upload_file_to_aggregation_folder(composite_resource, mock_irods):
+ """test that when we upload a file to a model program aggregation folder that file becomes part of the
+ aggregation"""
+
+ res, user = composite_resource
+ file_path = 'pytest/assets/generic_file.txt'
+ new_folder = 'mp_folder'
+ ResourceFile.create_folder(res, new_folder)
+ file_to_upload = UploadedFile(file=open(file_path, 'rb'),
+ name=os.path.basename(file_path))
+
+ add_file_to_resource(res, file_to_upload, folder=new_folder, check_target_folder=True)
+ assert res.files.count() == 1
+ # set folder to model program aggregation type
+ ModelProgramLogicalFile.set_file_type(resource=res, user=user, folder_path=new_folder)
+ assert ModelProgramLogicalFile.objects.count() == 1
+ mp_aggregation = ModelProgramLogicalFile.objects.first()
+ assert mp_aggregation.files.count() == 1
+ assert mp_aggregation.folder == new_folder
+ assert mp_aggregation.dataset_name == new_folder
+ # add another file to the model program aggregation folder
+ file_path = 'pytest/assets/logan.vrt'
+ file_to_upload = UploadedFile(file=open(file_path, 'rb'),
+ name=os.path.basename(file_path))
+ add_file_to_resource(res, file_to_upload, folder=new_folder, check_target_folder=True)
+ assert res.files.count() == 2
+ for res_file in res.files.all():
+ assert res_file.has_logical_file
+
@pytest.mark.django_db(transaction=True)
def test_create_aggregation_from_folder_failure(composite_resource, mock_irods):
"""test that we can't create a model program aggregation from a folder that does not contain any resource file"""
