def test_listing_requests_returns_invites(self):
        author = create_random_default_user('regular_user')
        user = create_random_default_user('random_user')
        peer_reviewer = create_random_default_user('peer_reviewer')

        # Create review request
        review_request_for_author = create_peer_review_request(
            requested_by_user=author,
            organization=Organization.objects.get(id=self.org['id']),
            title='Some random post title',
            body='some text',
        )

        # Invite user
        self.client.force_authenticate(self.moderator)
        invite_response = self.client.post(
            "/api/peer_review_invites/invite/", {
                'recipient': peer_reviewer.id,
                'peer_review_request': review_request_for_author.id,
            })

        # Fetch list
        list_response = self.client.get("/api/peer_review_requests/")

        self.assertEqual(len(list_response.data['results'][0]['invites']), 1)
    def test_different_users_can_open_multiple_claims_for_same_author(self):
        claiming_user1 = create_random_default_user('claiming_user')
        claiming_user2 = create_random_default_user('claiming_user')

        paper = create_paper(
            title='some title',
            uploaded_by=None,
        )

        self.client.force_authenticate(claiming_user1)
        response = self.client.post(
            "/api/author_claim_case/", {
                "case_type": "PAPER_CLAIM",
                "creator": claiming_user1.id,
                "requestor": claiming_user1.id,
                "provided_email": "*****@*****.**",
                "target_paper_id": paper.id,
                "target_author_name": "random author",
            })

        self.client.force_authenticate(claiming_user2)
        response = self.client.post(
            "/api/author_claim_case/", {
                "case_type": "PAPER_CLAIM",
                "creator": claiming_user2.id,
                "requestor": claiming_user2.id,
                "provided_email": "*****@*****.**",
                "target_paper_id": paper.id,
                "target_author_name": "random author",
            })

        self.assertEqual(response.status_code, 201)
    def test_creating_thread_notifies_hypothesis_creator(self):
        creator = create_random_default_user('Creator')
        thread_creator = create_random_default_user('ThreadCreator')
        hypothesis = create_hypothesis(created_by=creator)

        thread = create_thread(hypothesis=hypothesis, created_by=thread_creator)
        self.assertTrue(creator in thread.users_to_notify)
 def test_thread_users_to_notify_includes_paper_authors(self):
     user_1 = create_random_default_user('Amy')
     user_2 = create_random_default_user('Bamy')
     self.paper.authors.add(user_1.author_profile)
     self.paper.authors.add(user_2.author_profile)
     self.assertTrue(user_1 in self.thread.users_to_notify)
     self.assertTrue(user_2 in self.thread.users_to_notify)
    def non_author_cannot_update_post(self):
        author = create_random_default_user('author')
        nonauthor = create_random_default_user('nonauthor')
        hub = create_hub()

        self.client.force_authenticate(author)

        doc_response = self.client.post(
            "/api/researchhub_posts/", {
                "document_type": "DISCUSSION",
                "created_by": author.id,
                "full_src": "body",
                "is_public": True,
                "renderable_text": "body",
                "title": "title",
                "hubs": [hub.id],
            })

        self.client.force_authenticate(nonauthor)
        updated_response = self.client.post(
            "/api/researchhub_posts/", {
                "post_id": doc_response.data["id"],
                "title": "updated title",
                "document_type": "DISCUSSION",
                "created_by": author.id,
                "full_src": "body",
                "is_public": True,
                "renderable_text": "body",
                "hubs": [hub.id],
            })

        self.assertEqual(updated_response.status_code, 403)
Esempio n. 6
0
    def test_UNINVITED_user_cannot_decline_invite(self):
        author = create_random_default_user('regular_user')
        user = create_random_default_user('random_user')
        peer_reviewer = create_random_default_user('peer_reviewer')

        review_request_for_author = create_peer_review_request(
            requested_by_user=author,
            organization=Organization.objects.get(id=self.org['id']),
            title='Some random post title',
            body='some text',
        )

        self.client.force_authenticate(self.moderator)
        invite_response = self.client.post("/api/peer_review_invites/invite/",{
            'recipient': peer_reviewer.id,
            'peer_review_request': review_request_for_author.id,
        })

        self.client.force_authenticate(user)
        response = self.client.post(f'/api/peer_review_invites/{invite_response.data["id"]}/decline/')

        self.assertEqual(
            response.status_code,
            403
        )
    def test_non_author_cannot_edit_hypothesis(self):
        author = create_random_default_user('author')
        non_author = create_random_default_user('non_author')
        hub = create_hub()

        self.client.force_authenticate(author)

        doc_response = self.client.post(
            "/api/hypothesis/", {
                "document_type": "HYPOTHESIS",
                "created_by": author.id,
                "full_src": "body",
                "is_public": True,
                "renderable_text": "body",
                "title": "title",
                "hubs": [hub.id],
            })

        self.client.force_authenticate(non_author)

        updated_response = self.client.post(
            f"/api/hypothesis/{doc_response.data['id']}/upsert/", {
                "hypothesis_id": doc_response.data["id"],
                "title": "updated title",
                "document_type": "HYPOTHESIS",
                "full_src": "updated body",
                "renderable_text": "body",
            })
        self.assertEqual(updated_response.status_code, 403)
    def test_create_summary_increases_rep_below_200_by_1_in_new_user(self):
        user = create_random_default_user('Lavender')
        create_summary('', user, self.paper.id)

        user.refresh_from_db()
        self.assertEqual(user.reputation, self.start_rep + 1)

        old_user = create_random_default_user('Brown')
        old_user.date_joined = timezone.now() - timedelta(
            days=NEW_USER_BONUS_DAYS_LIMIT)
        old_user.save()
        create_summary('', old_user, self.paper.id)

        old_user.refresh_from_db()
        self.assertEqual(old_user.reputation + self.sign_up_bonus,
                         self.start_rep)

        rich_user = create_random_default_user('Muggle')
        rich_user.reputation = 200
        rich_user.save()
        rich_user.refresh_from_db()
        create_summary('', rich_user, self.paper.id)

        rich_user.refresh_from_db()
        self.assertEqual(rich_user.reputation, 200)
    def test_moderator_can_restore_doc(self):
        author = create_random_default_user('author')
        mod = create_random_default_user('mod', moderator=True)
        hub = create_hub()

        self.client.force_authenticate(author)

        doc_response = self.client.post(
            "/api/researchhub_posts/", {
                "document_type": "DISCUSSION",
                "created_by": author.id,
                "full_src": "body",
                "is_public": True,
                "renderable_text": "body",
                "title": "title",
                "hubs": [hub.id],
            })

        delete_response = self.client.delete(
            f"/api/researchhub_unified_documents/{doc_response.data['unified_document_id']}/censor/"
        )

        self.client.force_authenticate(mod)
        restore_response = self.client.patch(
            f"/api/researchhub_unified_documents/{doc_response.data['unified_document_id']}/restore/"
        )
        self.assertEqual(restore_response.data['is_removed'], False)
Esempio n. 10
0
    def test_non_author_cannot_delete_doc(self):
        author = create_random_default_user('author')
        non_author = create_random_default_user('non_author')
        hub = create_hub()

        self.client.force_authenticate(author)

        doc_response = self.client.post(
            f"/api/researchhub_posts/", {
                "document_type": "DISCUSSION",
                "created_by": author.id,
                "full_src": "body",
                "is_public": True,
                "renderable_text": "body",
                "title": "title",
                "hubs": [hub.id],
            })

        self.client.force_authenticate(non_author)

        response = self.client.delete(
            f"/api/researchhub_unified_documents/{doc_response.data['unified_document_id']}/censor/"
        )
        doc = ResearchhubUnifiedDocument.objects.get(
            id=doc_response.data['unified_document_id'])
        self.assertEqual(doc.is_removed, False)
    def test_flag_paper_increases_rep_by_1_after_3_flags(self):
        recipient_1 = create_random_default_user('Allister')
        recipient_2 = create_random_default_user('Allister2')
        recipient_3 = create_random_default_user('Allister3')
        late_user = create_random_default_user('late user')

        create_flag(paper=self.paper, created_by=recipient_1)
        self.assertEqual(recipient_1.reputation + self.sign_up_bonus,
                         self.start_rep)

        create_flag(paper=self.paper, created_by=recipient_2)
        self.assertEqual(recipient_1.reputation + self.sign_up_bonus,
                         self.start_rep)

        earned_rep = distributions.FlagPaper.amount

        create_flag(paper=self.paper, created_by=recipient_3)
        recipient_1.refresh_from_db()
        recipient_2.refresh_from_db()
        recipient_3.refresh_from_db()
        self.assertEqual(recipient_1.reputation, self.start_rep + earned_rep)
        self.assertEqual(recipient_2.reputation, self.start_rep + earned_rep)
        self.assertEqual(recipient_3.reputation, self.start_rep + earned_rep)

        create_flag(paper=self.paper, created_by=late_user)
        late_user.refresh_from_db()
        self.assertEqual(late_user.reputation, self.start_rep)
    def test_moderators_can_view_peer_review_request_details(self):
        author = create_random_default_user('regular_user')
        user = create_random_default_user('random_user')
        peer_reviewer = create_random_default_user('peer_reviewer')

        # Create review
        review_request_for_author = create_peer_review_request(
            requested_by_user=author,
            organization=Organization.objects.get(id=self.org['id']),
            title='Some random post title',
            body='some text',
        )

        # Invite user
        self.client.force_authenticate(self.moderator)
        invite_response = self.client.post(
            "/api/peer_review_invites/invite/", {
                'recipient': peer_reviewer.id,
                'peer_review_request': review_request_for_author.id,
            })

        # Decline invite
        self.client.force_authenticate(user)
        response = self.client.post(
            f'/api/peer_review_invites/{invite_response.data["id"]}/decline/')

        # Retrieve request + details
        self.client.force_authenticate(self.moderator)
        response = self.client.get(
            f'/api/peer_review_requests/{review_request_for_author.id}/')

        self.assertEqual(response.data['invites'][0]['id'],
                         invite_response.data['id'])
 def test_creating_comment_notifies_post_creator(self):
     creator = create_random_default_user('Creator')
     thread_creator = create_random_default_user('ThreadCreator')
     comment_creator = create_random_default_user('Commenter')
     post = create_post(created_by=creator)
     thread = create_thread(post=post, created_by=thread_creator)
     comment = create_comment(thread=thread, created_by=comment_creator)
     self.assertTrue(creator in comment.users_to_notify)
 def test_comment_creator_not_receive_notification_on_own_contribution(self):
     submitter = create_random_default_user('Submitter')
     thread_creator = create_random_default_user('ThreadCreator')
     comment_creator = create_random_default_user('Commenter')
     paper = create_paper(uploaded_by=submitter)
     thread = create_thread(paper=paper, created_by=thread_creator)
     comment = create_comment(thread=thread, created_by=comment_creator)
     self.assertFalse(comment_creator in comment.users_to_notify)
    def test_creating_thread_should_not_notify_thread_creator(self):
        submitter = create_random_default_user('Submitter')
        thread_creator = create_random_default_user('ThreadCreator')

        paper = create_paper(uploaded_by=submitter)
        thread = create_thread(paper=paper, created_by=submitter)

        self.assertTrue(thread_creator not in thread.users_to_notify)
    def test_submitter_who_also_creates_a_thread_should_not_receive_notifications(self):
        submitter = create_random_default_user('Submitter')
        thread_creator = create_random_default_user('ThreadCreator')

        paper = create_paper(uploaded_by=submitter)
        thread = create_thread(paper=paper, created_by=submitter)

        self.assertTrue(submitter not in thread.users_to_notify)
    def test_creating_comment_notifies_hypothesis_creator(self):
        creator = create_random_default_user('Creator')
        thread_creator = create_random_default_user('ThreadCreator')
        comment_creator = create_random_default_user('Commenter')
        hypothesis = create_hypothesis(created_by=creator)

        thread = create_thread(hypothesis=hypothesis, created_by=creator)
        comment = create_comment(thread=thread, created_by=comment_creator)
        self.assertTrue(creator in comment.users_to_notify)
    def test_creating_comment_should_not_notify_comment_creator(self):
        submitter = create_random_default_user('Submitter')
        thread_creator = create_random_default_user('ThreadCreator')
        comment_creator = create_random_default_user('Commenter')

        paper = create_paper(uploaded_by=submitter)
        thread = create_thread(paper=paper, created_by=thread_creator)
        comment = create_comment(thread=thread, created_by=comment_creator)

        self.assertTrue(comment_creator not in comment.users_to_notify)
        self.assertTrue(thread_creator in comment.users_to_notify)
    def setUp(self):
        self.user = create_random_default_user('Molly')
        self.recipient = create_random_default_user('Harry')
        self.paper = create_paper(title='Signal Test Paper')
        self.author = create_random_authenticated_user('Dumbledore')

        self.paper.authors.add(Author.objects.get(user=self.author))
        self.paper.save()

        self.sign_up_bonus = 25
        self.start_rep = 100 + self.sign_up_bonus
        self.new_user_create_rep = 1
        self.author_create_rep = (self.new_user_create_rep +
                                  distributions.CreateAuthoredPaper.amount)
    def test_creating_reply_should_not_email_unsubscribed_users(self):
        submitter = create_random_default_user('Submitter')
        thread_creator = create_random_default_user('ThreadCreator')
        comment_creator = create_random_default_user('Commenter')
        reply_creator = create_random_default_user('ReplyCreator')

        paper = create_paper(uploaded_by=submitter)
        thread = create_thread(paper=paper, created_by=thread_creator)
        comment = create_comment(thread=thread, created_by=comment_creator)
        reply = create_reply(parent=comment, created_by=reply_creator)
        comment_creator.emailrecipient.set_opted_out(True)

        self.assertTrue(thread_creator in reply.users_to_notify)
        self.assertTrue(comment_creator not in reply.users_to_notify)        
    def test_create_discussion_item_creates_action(self):
        user = create_random_default_user('rando')
        create_comment(created_by=user)

        user.refresh_from_db()
        actions = user.actions.all()
        self.assertEqual(len(actions), 1)
    def test_create_thread_increases_rep_by_1_in_new_user(self):
        user = create_random_default_user('Bellatrix')
        create_thread(created_by=user)

        user.refresh_from_db()
        self.assertEqual(user.reputation, self.start_rep + 1)

        old_user = create_random_default_user('Lestrange')
        old_user.date_joined = timezone.now() - timedelta(
            days=NEW_USER_BONUS_DAYS_LIMIT)
        old_user.save()
        create_reply(created_by=old_user)

        old_user.refresh_from_db()
        self.assertEqual(old_user.reputation + self.sign_up_bonus,
                         self.start_rep)
    def test_create_paper_uploaded_by_non_orcid_author_increases_rep_1(self):
        user = create_random_default_user('Ronald the Author')
        paper = create_paper(uploaded_by=user)
        paper.authors.add(user.author_profile)

        user.refresh_from_db()
        self.assertEqual(user.reputation, self.start_rep + 1)
Esempio n. 24
0
    def test_close_claim_does_not_require_paper_to_be_set(self):
        moderator = create_moderator(first_name='moderator',
                                     last_name='moderator')
        claiming_user = create_random_default_user('claiming_user')
        self.client.force_authenticate(claiming_user)

        paper = create_paper(
            title='some title',
            uploaded_by=None,
        )

        # Update Claim status
        claim = AuthorClaimCase.objects.create(
            case_type="PAPER_CLAIM",
            status="OPEN",
            creator=claiming_user,
            requestor=claiming_user,
            provided_email="*****@*****.**",
        )

        # Close claim
        self.client.force_authenticate(moderator)
        response = self.client.post("/api/author_claim_case/moderator/", {
            "case_id": claim.id,
            "notify_user": False,
            "update_status": 'DENIED',
        })

        self.assertEqual(response.status_code, 200)
 def test_creating_reply_notifies_paper_submitter(self):
     submitter = create_random_default_user('Submitter')
     paper = create_paper(uploaded_by=submitter)
     thread = create_thread(paper=paper)
     comment = create_comment(thread=thread)
     reply = create_reply(parent=comment)
     self.assertTrue(submitter in reply.users_to_notify)
    def test_comment_endorsed_increases_rep_by_15(self):
        recipient = create_random_default_user('Malfoy')
        comment = create_comment(created_by=recipient)
        endorse_discussion(comment, self.author)

        recipient.refresh_from_db()
        self.assertEqual(recipient.reputation,
                         self.start_rep + self.new_user_create_rep + 15)
Esempio n. 27
0
def create_endorsement(created_by=None, item=None):
    if created_by is None:
        created_by = create_random_default_user('endorser')
    if item is None:
        item = create_reply()
    endorsement = Endorsement(created_by=created_by, item=item)
    endorsement.save()
    return endorsement
Esempio n. 28
0
def create_flag(created_by, item, reason='Flag reason'):
    if created_by is None:
        created_by = create_random_default_user('flagger')
    if item is None:
        item = create_thread()
    flag = Flag(created_by=created_by, item=item, reason=reason)
    flag.save()
    return flag
    def test_creating_new_thread_notifies_paper_contributors(self):
        creator = create_random_default_user('Submitter')
        thread_contributor = create_random_default_user('thread_contributor')
        thread2_contributor = create_random_default_user('thread2_contributor')
        comment_contributor = create_random_default_user('comment_contributor')
        reply_contributor = create_random_default_user('reply_contributor')
        paper = create_paper(uploaded_by=creator)

        thread1 = create_thread(paper=paper, created_by=thread_contributor)
        thread2 = create_thread(paper=paper, created_by=thread2_contributor)
        comment = create_comment(thread=thread1, created_by=comment_contributor)
        comment2 = create_comment(thread=thread1, created_by=thread_contributor)
        reply = create_reply(parent=comment, created_by=reply_contributor)

        self.assertTrue(thread_contributor in thread2.users_to_notify)
        self.assertTrue(comment_contributor in thread2.users_to_notify)
        self.assertTrue(reply_contributor in thread2.users_to_notify)
    def test_creating_new_thread_notifies_hypothesis_contributors(self):
        creator = create_random_default_user('Submitter')
        thread_contributor = create_random_default_user('thread_contributor')
        thread2_contributor = create_random_default_user('thread2_contributor')
        comment_contributor = create_random_default_user('comment_contributor')
        reply_contributor = create_random_default_user('reply_contributor')
        hypothesis = create_hypothesis(created_by=creator)

        thread1 = create_thread(hypothesis=hypothesis, created_by=thread_contributor)
        thread2 = create_thread(hypothesis=hypothesis, created_by=thread2_contributor)
        comment = create_comment(thread=thread1, created_by=comment_contributor)
        comment2 = create_comment(thread=thread1, created_by=thread_contributor)
        reply = create_reply(parent=comment, created_by=reply_contributor)

        self.assertTrue(thread_contributor in thread2.users_to_notify)
        self.assertTrue(comment_contributor in thread2.users_to_notify)
        self.assertTrue(reply_contributor in thread2.users_to_notify)