def test_algorithm_image_create_link_view(client): alg = AlgorithmFactory() expected_url = reverse( "algorithms:image-create", kwargs={"slug": alg.slug} ) user = UserFactory() alg.add_user(user) response = get_view_for_user( viewname="algorithms:detail", reverse_kwargs={"slug": alg.slug}, client=client, user=user, ) assert response.status_code == 200 assert expected_url not in response.rendered_content alg.add_editor(user) response = get_view_for_user( viewname="algorithms:detail", reverse_kwargs={"slug": alg.slug}, client=client, user=user, ) assert response.status_code == 200 assert expected_url in response.rendered_content
def test_algorithm_job_update_status(): alg = AlgorithmFactory() user = UserFactory() editor = UserFactory() alg.add_user(user) alg.add_editor(editor) ai = AlgorithmImageFactory(algorithm=alg) job = AlgorithmJobFactory(algorithm_image=ai, creator=user) for status, _ in Job.STATUS_CHOICES: job.update_status(status=status) job.refresh_from_db() assert job.status == status remaining_recipients = {user.email, editor.email} for email in mail.outbox: remaining_recipients -= set(email.to) assert ( email.subject == f"[{Site.objects.get_current().domain.lower()}] [{alg.title.lower()}] Job Failed" ) assert ( f"Unfortunately your job for algorithm '{alg.title}' failed with an error" in email.body) assert remaining_recipients == set()
def test_algorithm_permission_request_notification_for_admins_only(client): base_object = AlgorithmFactory() editor = UserFactory() user = UserFactory() participant = UserFactory() base_object.add_editor(editor) base_object.add_user(participant) # create an algorithm job follow for participant follow(user=participant, obj=base_object, flag="job-active") permission_create_url = reverse( "algorithms:permission-request-create", kwargs={"slug": base_object.slug}, ) # Create the permission request _ = get_view_for_user( client=client, user=user, url=permission_create_url, method=client.post, ) assert Notification.objects.count() == 1 assert Notification.objects.get().user == editor
class TwoAlgorithms: def __init__(self): self.creator = get_algorithm_creator() self.alg1, self.alg2 = AlgorithmFactory(), AlgorithmFactory() self.editor1, self.user1, self.editor2, self.user2 = ( UserFactory(), UserFactory(), UserFactory(), UserFactory(), ) self.alg1.add_editor(user=self.editor1) self.alg2.add_editor(user=self.editor2) self.alg1.add_user(user=self.user1) self.alg2.add_user(user=self.user2) self.u = UserFactory()
def test_publication_object_visibilty(client, mocker): user1 = UserFactory() user2 = UserFactory() alg = AlgorithmFactory() alg.add_user(user1) assert user1.has_perm("view_algorithm", alg) assert not user2.has_perm("view_algorithm", alg) mocker.patch("grandchallenge.publications.utils.get_doi_csl", return_value=TEST_CSL) # create publication _ = get_view_for_user( viewname="publications:create", client=client, method=client.post, data={"identifier": TEST_DOI}, user=user1, ) # add publication to algorithm alg.publications.add(Publication.objects.get()) alg.save() response = get_view_for_user( viewname="publications:list", client=client, method=client.get, user=user1, ) assert response.status_code == 200 assert alg.title in response.rendered_content response = get_view_for_user( viewname="publications:list", client=client, method=client.get, user=user2, ) assert response.status_code == 200 assert alg.title not in response.rendered_content
def test_algorithm_list_view(client): alg1, alg2 = AlgorithmFactory(), AlgorithmFactory() user = UserFactory() alg1.add_user(user) alg2.add_user(user) response = get_view_for_user( viewname="algorithms:list", client=client, user=user ) assert alg1.get_absolute_url() in response.rendered_content assert alg2.get_absolute_url() in response.rendered_content alg1.remove_user(user) response = get_view_for_user( viewname="algorithms:list", client=client, user=user ) assert alg1.get_absolute_url() not in response.rendered_content assert alg2.get_absolute_url() in response.rendered_content