def create_raw_upload_image_session( *, images: List[str], delete_file=False, user=None, linked_task=None, ) -> Tuple[RawImageUploadSession, Dict[str, RawImageFile]]: creator = user or UserFactory(email="*****@*****.**") upload_session = RawImageUploadSession(creator=creator) uploaded_images = {} for image in images: staged_file = create_file_from_filepath(RESOURCE_PATH / image) image = RawImageFile.objects.create( upload_session=upload_session, filename=staged_file.name, staged_file_id=staged_file.uuid, ) uploaded_images[staged_file.name] = image if delete_file: StagedAjaxFile( uploaded_images["image10x10x10.zraw"].staged_file_id).delete() upload_session.save() with capture_on_commit_callbacks(execute=True): upload_session.process_images(linked_task=linked_task) return upload_session, uploaded_images
def create_raw_upload_image_session( images: List[str], delete_file=False, imageset=None, annotationset=None ) -> Tuple[RawImageUploadSession, Dict[str, RawImageFile]]: upload_session = RawImageUploadSession(imageset=imageset, annotationset=annotationset) uploaded_images = {} for image in images: staged_file = create_file_from_filepath(RESOURCE_PATH / image) image = RawImageFile.objects.create( upload_session=upload_session, filename=staged_file.name, staged_file_id=staged_file.uuid, ) uploaded_images[staged_file.name] = image if delete_file: StagedAjaxFile( uploaded_images["image10x10x10.zraw"].staged_file_id).delete() upload_session.save() return upload_session, uploaded_images
def create_raw_upload_image_session( images: List[str], delete_file=False, imageset=None, annotationset=None ) -> Tuple[RawImageUploadSession, Dict[str, RawImageFile]]: upload_session = RawImageUploadSession( imageset=imageset, annotationset=annotationset ) uploaded_images = {} for image in images: staged_file = create_file_from_filepath(RESOURCE_PATH / image) image = RawImageFile.objects.create( upload_session=upload_session, filename=staged_file.name, staged_file_id=staged_file.uuid, ) uploaded_images[staged_file.name] = image if delete_file: StagedAjaxFile( uploaded_images["image10x10x10.zraw"].staged_file_id ).delete() upload_session.save() return upload_session, uploaded_images
def test_upload_some_images(client: Client, ChallengeSet, settings): # Override the celery settings settings.task_eager_propagates = (True, ) settings.task_always_eager = (True, ) settings.broker_url = ("memory://", ) settings.backend = "memory" response = client.get("/cases/uploads/") assert response.status_code != 200 staff_user = UserFactory(is_staff=True) assert client.login(username=staff_user.username, password=SUPER_SECURE_TEST_PASSWORD) response = client.get("/cases/uploads/") assert response.status_code == 200 file1 = create_file_from_filepath(RESOURCE_PATH / "image10x10x10.mha") response = client.post("/cases/uploads/", data={"files": f"{file1.uuid}"}) assert response.status_code == 302 redirect_match = re.search(r"/cases/uploads/(?P<uuid>[^/]+)/?$", response["Location"]) assert redirect_match is not None assert RawImageUploadSession.objects.filter( pk=UUID(redirect_match.group("uuid"))).exists() response = client.get(response["Location"]) assert response.status_code == 200
def test_upload_some_images(client: Client, challenge_set, settings): # Override the celery settings settings.task_eager_propagates = (True, ) settings.task_always_eager = (True, ) user = UserFactory() # Use reader studies as this uses UploadRawImagesForm rs = ReaderStudyFactory() rs.add_editor(user) response = get_view_for_user( client=client, viewname="reader-studies:add-images", user=user, reverse_kwargs={"slug": rs.slug}, ) assert response.status_code == 200 assert rs.images.count() == 0 assert RawImageUploadSession.objects.count() == 0 file1 = create_file_from_filepath(RESOURCE_PATH / "image10x10x10.mha") with capture_on_commit_callbacks(execute=True): response = get_view_for_user( data={"files": f"{file1.uuid}"}, client=client, viewname="reader-studies:add-images", user=user, reverse_kwargs={"slug": rs.slug}, method=client.post, ) assert response.status_code == 302 assert rs.images.count() == 1 sessions = RawImageUploadSession.objects.all() assert len(sessions) == 1 response = get_view_for_user(url=sessions[0].get_absolute_url(), client=client, user=user) assert response.status_code == 200 response = get_view_for_user( url=sessions[0].get_absolute_url(), client=client, user=UserFactory(is_staff=True), ) assert response.status_code == 403