diff --git a/app/grandchallenge/components/tasks.py b/app/grandchallenge/components/tasks.py index 634c838cdd..2b74381ff3 100644 --- a/app/grandchallenge/components/tasks.py +++ b/app/grandchallenge/components/tasks.py @@ -1288,6 +1288,7 @@ def add_file_to_object( civ.full_clean() civ.save() user_upload.copy_object(to_field=civ.file) + user_upload.delete() except ValidationError as e: error_handler.handle_error( interface=interface, diff --git a/app/tests/algorithms_tests/test_api.py b/app/tests/algorithms_tests/test_api.py index 7478f75081..2a3a229ff0 100644 --- a/app/tests/algorithms_tests/test_api.py +++ b/app/tests/algorithms_tests/test_api.py @@ -15,6 +15,7 @@ ComponentInterfaceValue, InterfaceKindChoices, ) +from grandchallenge.uploads.models import UserUpload from tests.algorithms_tests.factories import ( AlgorithmImageFactory, AlgorithmJobFactory, @@ -211,6 +212,10 @@ def test_create_job_with_multiple_new_inputs( assert job.time_limit == 600 assert job.inputs.count() == 6 + assert not UserUpload.objects.filter( + pk=algorithm_with_multiple_inputs.file_upload.pk + ).exists() + assert sorted( [ int.pk diff --git a/app/tests/algorithms_tests/test_views.py b/app/tests/algorithms_tests/test_views.py index 8c28348bf4..10b5af9317 100644 --- a/app/tests/algorithms_tests/test_views.py +++ b/app/tests/algorithms_tests/test_views.py @@ -26,6 +26,7 @@ ) from grandchallenge.components.schemas import GPUTypeChoices from grandchallenge.subdomains.utils import reverse +from grandchallenge.uploads.models import UserUpload from tests.algorithms_tests.factories import ( AlgorithmFactory, AlgorithmImageFactory, @@ -969,6 +970,7 @@ def test_create_job_with_json_file( file.name.split("/")[-1] in Job.objects.get().inputs.first().file.name ) + assert not UserUpload.objects.filter(pk=upload.pk).exists() @pytest.mark.django_db @@ -1196,6 +1198,10 @@ def test_create_job_with_multiple_new_inputs( assert job.time_limit == 600 assert job.inputs.count() == 6 + assert not UserUpload.objects.filter( + pk=algorithm_with_multiple_inputs.file_upload.pk + ).exists() + assert sorted( [ int.pk diff --git a/app/tests/archives_tests/test_views.py b/app/tests/archives_tests/test_views.py index 0a1a309fa1..9ce54d9653 100644 --- a/app/tests/archives_tests/test_views.py +++ b/app/tests/archives_tests/test_views.py @@ -16,6 +16,7 @@ from grandchallenge.components.models import ComponentInterface, InterfaceKind from grandchallenge.notifications.models import Notification from grandchallenge.subdomains.utils import reverse +from grandchallenge.uploads.models import UserUpload from tests.algorithms_tests.factories import AlgorithmJobFactory, Job from tests.archives_tests.factories import ( ArchiveFactory, @@ -448,6 +449,7 @@ def test_api_archive_item_add_and_update_non_image_file( assert item.values.count() == 1 civ = item.values.get() assert civ.interface.slug == ci.slug + assert not UserUpload.objects.filter(pk=upload.pk).exists() # partial update civ upload2 = create_upload_from_file( @@ -481,6 +483,7 @@ def test_api_archive_item_add_and_update_non_image_file( new_civ = item.values.get() assert new_civ.interface.slug == ci.slug assert new_civ != civ + assert not UserUpload.objects.filter(pk=upload2.pk).exists() @pytest.mark.django_db @@ -638,6 +641,7 @@ def test_api_archive_item_add_and_update_json_file( assert item.values.count() == 1 civ = item.values.get() assert civ.interface.slug == ci.slug + assert not UserUpload.objects.filter(pk=upload.pk).exists() # update civ with tempfile.NamedTemporaryFile(mode="w+", suffix=".json") as file: @@ -673,6 +677,7 @@ def test_api_archive_item_add_and_update_json_file( new_civ = item.values.get() assert new_civ.interface.slug == ci.slug assert new_civ != civ + assert not UserUpload.objects.filter(pk=upload2.pk).exists() @pytest.mark.django_db @@ -933,6 +938,7 @@ def test_archive_item_add_file( ) }, ) + assert not UserUpload.objects.filter(pk=upload.pk).exists() assert response.status_code == 302 assert "test" in ArchiveItem.objects.get().values.first().file.name @@ -976,6 +982,7 @@ def test_archive_item_add_json_file( ) assert response.status_code == 302 assert file.name.split("/")[-1] in item.values.first().file.name + assert not UserUpload.objects.filter(pk=upload.pk).exists() item2 = ArchiveItemFactory(archive=archive) civ = ComponentInterfaceValueFactory( @@ -1174,6 +1181,7 @@ def test_archive_item_create_view( assert ai2.values.get(interface=ci_img2).image == image assert ai2.values.get(interface=ci_json).file.read() == b'{"foo": "bar"}' assert ai2.values.get(interface=ci_json2).value == {"some": "content"} + assert not UserUpload.objects.filter(pk=upload.pk).exists() @pytest.mark.django_db diff --git a/app/tests/components_tests/test_tasks.py b/app/tests/components_tests/test_tasks.py index 9b65196d77..a202d1de39 100644 --- a/app/tests/components_tests/test_tasks.py +++ b/app/tests/components_tests/test_tasks.py @@ -33,6 +33,7 @@ from grandchallenge.core.celery import _retry, acks_late_micro_short_task from grandchallenge.notifications.models import Notification from grandchallenge.reader_studies.models import InteractiveAlgorithmChoices +from grandchallenge.uploads.models import UserUpload from tests.algorithms_tests.factories import ( AlgorithmFactory, AlgorithmImageFactory, @@ -536,6 +537,7 @@ def test_add_file_to_object( linked_task=linked_task, ) + assert not UserUpload.objects.filter(pk=us.pk).exists() assert ComponentInterfaceValue.objects.filter(interface=ci).count() == 1 assert "some_async_task" in str(callbacks) diff --git a/app/tests/reader_studies_tests/test_views.py b/app/tests/reader_studies_tests/test_views.py index e8fb23b58d..7acb584906 100644 --- a/app/tests/reader_studies_tests/test_views.py +++ b/app/tests/reader_studies_tests/test_views.py @@ -17,6 +17,7 @@ Question, ) from grandchallenge.subdomains.utils import reverse +from grandchallenge.uploads.models import UserUpload from tests.cases_tests import RESOURCE_PATH from tests.components_tests.factories import ( ComponentInterfaceFactory, @@ -568,6 +569,7 @@ def do_update(): user=user, method=client.post, ) + assert not UserUpload.objects.filter(pk=upload.pk).exists() assert response.status_code == 302 assert response.headers["HX-Redirect"] == reverse( "reader-studies:display_sets", kwargs={"slug": rs.slug}