def test_workstation_list_view(client): w1, w2 = WorkstationFactory(), WorkstationFactory() user = UserFactory() response = get_view_for_user(viewname="workstations:list", client=client, user=user) assert w1.get_absolute_url() not in response.rendered_content assert w2.get_absolute_url() not in response.rendered_content w2.add_editor(user=user) response = get_view_for_user(viewname="workstations:list", client=client, user=user) assert w1.get_absolute_url() not in response.rendered_content assert w2.get_absolute_url() in response.rendered_content w1u = UserFactory() w1.add_user(user=w1u) response = get_view_for_user(viewname="workstations:list", client=client, user=w1u) assert w1.get_absolute_url() in response.rendered_content assert w2.get_absolute_url() not in response.rendered_content
def test_social_image_meta_tag(client, uploaded_image): creator = UserFactory() add_archive_perm = Permission.objects.get( codename=f"add_{Archive._meta.model_name}" ) creator.user_permissions.add(add_archive_perm) ws = WorkstationFactory() ws.add_user(user=creator) def create_archive(): return get_view_for_user( viewname="archives:create", client=client, method=client.post, data={ "title": "foo bar", "logo": uploaded_image(), "social_image": uploaded_image(), "workstation": ws.pk, }, follow=True, user=creator, ) response = create_archive() assert response.status_code == 200 archive = Archive.objects.get(title="foo bar") assert str(archive.social_image.x20.url) in response.content.decode()
def test_session_create(client): user = UserFactory() ws = WorkstationFactory() ws.add_user(user=user) # Create some workstations and pretend that they're ready WorkstationImageFactory(workstation=ws, ready=True) # Old WSI wsi_new = WorkstationImageFactory(workstation=ws, ready=True) WorkstationImageFactory(workstation=ws) # WSI not ready WorkstationImageFactory(ready=True) # Image for some other ws assert Session.objects.count() == 0 response = get_view_for_user( client=client, method=client.post, viewname="workstations:workstation-session-create", reverse_kwargs={"slug": ws.slug}, user=user, data={"region": "eu-central-1"}, ) assert response.status_code == 302 sessions = Session.objects.all() assert len(sessions) == 1 # Should select the most recent workstation assert sessions[0].workstation_image == wsi_new assert sessions[0].creator == user
def test_algorithm_create(client): # The algorithm creator should automatically get added to the editors group creator = get_algorithm_creator() ws = WorkstationFactory() def try_create_algorithm(): return get_view_for_user( viewname="algorithms:create", client=client, method=client.post, data={ "title": "foo bar", "logo": get_temporary_image(), "workstation": ws.pk, }, follow=True, user=creator, ) response = try_create_algorithm() assert "error_1_id_workstation" in response.rendered_content # The editor must have view permissions for the workstation to add it ws.add_user(user=creator) response = try_create_algorithm() assert "error_1_id_workstation" not in response.rendered_content assert response.status_code == 200 alg = Algorithm.objects.get(title="foo bar") assert alg.slug == "foo-bar" assert alg.is_editor(user=creator) assert not alg.is_user(user=creator)
def test_reader_study_create(client, uploaded_image): # The study creator should automatically get added to the editors group creator = get_rs_creator() ws = WorkstationFactory() def try_create_rs(allow_case_navigation): return get_view_for_user( viewname="reader-studies:create", client=client, method=client.post, data={ "title": "foo bar", "logo": uploaded_image(), "workstation": ws.pk, "allow_answer_modification": True, "allow_case_navigation": allow_case_navigation, }, follow=True, user=creator, ) response = try_create_rs(False) assert "error_1_id_workstation" in response.rendered_content # The editor must have view permissions for the workstation to add it ws.add_user(user=creator) response = try_create_rs(False) assert "error_1_id_workstation" not in response.rendered_content assert ( "`allow_case_navigation` must be checked if `allow_answer_modification` is" in response.rendered_content ) response = try_create_rs(True) assert "error_1_id_workstation" not in response.rendered_content assert ( "`allow_case_navigation` must be checked if `allow_answer_modification` is" not in response.rendered_content ) assert response.status_code == 200 rs = ReaderStudy.objects.get(title="foo bar") assert rs.slug == "foo-bar" assert rs.is_editor(user=creator) assert not rs.is_reader(user=creator) assert is_following(user=creator, obj=rs)
def test_algorithm_create(client, uploaded_image): # The algorithm creator should automatically get added to the editors group creator = get_algorithm_creator() VerificationFactory(user=creator, is_verified=True) ws = WorkstationFactory() ci = ComponentInterface.objects.get(slug="generic-medical-image") def try_create_algorithm(): return get_view_for_user( viewname="algorithms:create", client=client, method=client.post, data={ "title": "foo bar", "logo": uploaded_image(), "workstation": ws.pk, "credits_per_job": 1, "image_requires_gpu": False, "image_requires_memory_gb": 4, "inputs": [ci.pk], "outputs": [ComponentInterfaceFactory().pk], "contact_email": creator.email, "display_editors": True, "access_request_handling": AccessRequestHandlingOptions.MANUAL_REVIEW, "view_content": "{}", }, follow=True, user=creator, ) response = try_create_algorithm() assert "error_1_id_workstation" in response.rendered_content # The editor must have view permissions for the workstation to add it ws.add_user(user=creator) response = try_create_algorithm() assert "error_1_id_workstation" not in response.rendered_content assert response.status_code == 200 alg = Algorithm.objects.get(title="foo bar") assert alg.slug == "foo-bar" assert alg.is_editor(user=creator) assert not alg.is_user(user=creator) assert is_following(user=creator, obj=alg)
def test_archive_create(client, uploaded_image): # The archive creator should automatically get added to the editors group creator = UserFactory() add_archive_perm = Permission.objects.get( codename=f"add_{Archive._meta.model_name}" ) creator.user_permissions.add(add_archive_perm) ws = WorkstationFactory() def try_create_archive(): return get_view_for_user( viewname="archives:create", client=client, method=client.post, data={ "title": "foo bar", "logo": uploaded_image(), "workstation": ws.pk, "access_request_handling": AccessRequestHandlingOptions.MANUAL_REVIEW, "view_content": "{}", }, follow=True, user=creator, ) response = try_create_archive() assert "error_1_id_workstation" in response.rendered_content # The editor must have view permissions for the workstation to add it ws.add_user(user=creator) response = try_create_archive() assert "error_1_id_workstation" not in response.rendered_content assert response.status_code == 200 archive = Archive.objects.get(title="foo bar") assert archive.slug == "foo-bar" assert archive.is_editor(user=creator) assert not archive.is_user(user=creator) assert is_following(user=creator, obj=archive)
def test_reader_study_create(client, uploaded_image): # The study creator should automatically get added to the editors group creator = get_rs_creator() ws = WorkstationFactory() def try_create_rs( allow_case_navigation=False, shuffle_hanging_list=False, roll_over_answers_for_n_cases=0, ): return get_view_for_user( viewname="reader-studies:create", client=client, method=client.post, data={ "title": "foo bar", "logo": uploaded_image(), "workstation": ws.pk, "allow_answer_modification": True, "shuffle_hanging_list": shuffle_hanging_list, "allow_case_navigation": allow_case_navigation, "access_request_handling": AccessRequestHandlingOptions.MANUAL_REVIEW, "roll_over_answers_for_n_cases": roll_over_answers_for_n_cases, }, follow=True, user=creator, ) response = try_create_rs() assert "error_1_id_workstation" in response.rendered_content # The editor must have view permissions for the workstation to add it ws.add_user(user=creator) roll_over_error = "Rolling over answers should not be used together with case navigation or shuffling of the hanging list" for navigation, shuffle in [(True, True), (True, False), (False, True)]: response = try_create_rs( allow_case_navigation=navigation, shuffle_hanging_list=shuffle, roll_over_answers_for_n_cases=1, ) assert "error_1_id_workstation" not in response.rendered_content assert roll_over_error in response.rendered_content response = try_create_rs(roll_over_answers_for_n_cases=1) assert "error_1_id_workstation" not in response.rendered_content assert roll_over_error not in response.rendered_content assert response.status_code == 200 case_navigation_error = ( "Case navigation is required when answer modification is allowed" ) response = try_create_rs(allow_case_navigation=False) assert "error_1_id_workstation" not in response.rendered_content assert case_navigation_error in response.rendered_content response = try_create_rs(allow_case_navigation=True) assert "error_1_id_workstation" not in response.rendered_content assert case_navigation_error not in response.rendered_content assert response.status_code == 200 rs = ReaderStudy.objects.get(title="foo bar") assert rs.slug == "foo-bar" assert rs.is_editor(user=creator) assert not rs.is_reader(user=creator) assert is_following(user=creator, obj=rs)