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)
示例#2
0
 def test_actions_route_responds_with_all_actions(self):
     user = create_random_authenticated_user('action_oriented_user')
     create_comment(created_by=user)
     response = self.get_actions_response(user)
     count = '"count":1'
     self.assertContains(response, count)
     content_type = '"content_type":"comment"'
     self.assertContains(response, content_type)
    def test_create_comment_ONLY_increases_rep_under_200_new_user(self):
        user = create_random_default_user('Winky')
        create_comment(created_by=user)

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

        user.reputation = 200
        user.save()
        create_comment(created_by=user)

        user.refresh_from_db()
        self.assertEqual(user.reputation, 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_multiple_reputation_distributions(self):
        thread = create_thread(created_by=self.recipient)
        current_rep = self.start_rep + self.new_user_create_rep

        self.recipient.refresh_from_db()
        self.assertEqual(self.recipient.reputation, current_rep)

        comment = create_comment(thread=thread, created_by=self.recipient)
        comment_vote = upvote_discussion(comment, self.user)
        current_rep = current_rep + 1 + self.new_user_create_rep

        self.recipient.refresh_from_db()
        self.assertEqual(self.recipient.reputation, current_rep)

        update_to_downvote(comment_vote)
        current_rep = current_rep - 1

        self.recipient.refresh_from_db()
        self.assertEqual(self.recipient.reputation, current_rep)

        reply = create_reply(parent=comment, created_by=self.recipient)
        reply_vote = downvote_discussion(reply, self.user)
        current_rep = current_rep - 1 + self.new_user_create_rep

        self.recipient.refresh_from_db()
        self.assertEqual(self.recipient.reputation, current_rep)

        update_to_upvote(reply_vote)
        current_rep += 1

        self.recipient.refresh_from_db()
        self.assertEqual(self.recipient.reputation, current_rep)
    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)
    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_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)
    def test_comment_flagged_decreases_rep_by_2(self):
        recipient = create_random_default_user('Ed')
        comment = create_comment(created_by=recipient)
        flag_discussion(comment, self.user)

        recipient.refresh_from_db()
        self.assertEqual(recipient.reputation,
                         self.start_rep + self.new_user_create_rep - 2)
 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_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_create_comment_increases_rep_by_1_in_new_user(self):
        user = create_random_default_user('Ludo')
        create_comment(created_by=user)

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

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

        old_user.refresh_from_db()
        # Add bonus here because this amount is added by a signal and gets
        # wiped with refresh from db
        self.assertEqual(old_user.reputation + self.sign_up_bonus,
                         self.start_rep)
    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.base_url = '/api/'
        self.user = create_random_authenticated_user('discussion_views')
        self.paper = create_paper(uploaded_by=self.user)
        self.thread = create_thread(paper=self.paper, created_by=self.user)
        self.comment = create_comment(thread=self.thread, created_by=self.user)
        self.reply = create_reply(parent=self.comment, created_by=self.user)
        self.trouble_maker = create_random_authenticated_user('trouble_maker')
        self.author = create_random_authenticated_user('author')

        self.paper.authors.add(Author.objects.get(user=self.author))
        self.paper.save()
 def setUp(self):
     SEED = 'discussion'
     self.random_generator = random.Random(SEED)
     self.user = create_random_authenticated_user('Tom Marvolo Riddle')
     self.recipient = create_random_authenticated_user('Harry James Potter')
     self.paper = create_paper(title='The Half Blood Prince',
                               uploaded_by=self.recipient)
     self.thread = create_thread(paper=self.paper,
                                 created_by=self.recipient)
     self.comment = create_comment(thread=self.thread,
                                   created_by=self.recipient)
     self.reply = create_reply(parent=self.comment,
                               created_by=self.recipient)
    def test_comment_by_paper_non_orcid_author_upvoted_increases_rep_1(self):
        recipient = create_random_default_user('Winky the Author')

        paper = create_paper()
        paper.authors.add(recipient.author_profile)

        thread = create_thread(paper=paper)
        comment = create_comment(thread=thread, created_by=recipient)

        upvote_discussion(comment, self.user)

        recipient.refresh_from_db()
        self.assertEqual(recipient.reputation,
                         self.start_rep + self.new_user_create_rep + 1)
    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 setUp(self):
        SEED = 'discussion'
        self.random_generator = random.Random(SEED)
        self.base_url = '/api/'
        self.user = create_random_authenticated_user('discussion_permissions')
        self.paper = create_paper(uploaded_by=self.user)
        self.thread = create_thread(paper=self.paper, created_by=self.user)
        self.comment = create_comment(thread=self.thread, created_by=self.user)
        self.reply = create_reply(parent=self.comment, created_by=self.user)
        self.trouble_maker = create_random_authenticated_user('trouble_maker')
        self.author = create_random_authenticated_user('author')
        self.moderator = create_random_authenticated_user('moderator')

        self.add_paper_author(Author.objects.get(user=self.author))
        self.add_paper_moderator(self.moderator)
    def test_reply_upvoted_increases_rep_1_created_by_non_orcid_author(self):
        recipient = create_random_default_user('George the Author')

        paper = create_paper()
        paper.authors.add(recipient.author_profile)

        thread = create_thread(paper=paper)
        comment = create_comment(thread=thread)
        reply = create_reply(parent=comment, created_by=recipient)

        upvote_discussion(reply, self.user)

        earned_rep = (distributions.ReplyUpvoted.amount)

        recipient.refresh_from_db()
        self.assertEqual(recipient.reputation, self.start_rep + earned_rep)
    def test_comment_by_paper_orcid_author_upvoted_increases_rep_5(self):
        recipient = create_random_default_user('Winky the ORCID Author')
        social = create_social_account(OrcidProvider.id, recipient)
        recipient.author_profile.orcid_id = social.uid
        recipient.author_profile.save()

        paper = create_paper()
        paper.authors.add(recipient.author_profile)

        thread = create_thread(paper=paper)
        comment = create_comment(thread=thread, created_by=recipient)

        upvote_discussion(comment, self.user)

        recipient.refresh_from_db()
        self.assertEqual(recipient.reputation,
                         self.start_rep + self.new_user_create_rep + 5)
    def test_reply_upvoted_increases_rep_5_created_by_paper_orcid_author(self):
        recipient = create_random_default_user('George the Author')
        social = create_social_account(OrcidProvider.id, recipient)
        recipient.author_profile.orcid_id = social.uid
        recipient.author_profile.save()

        paper = create_paper()
        paper.authors.add(recipient.author_profile)

        thread = create_thread(paper=paper)
        comment = create_comment(thread=thread)
        reply = create_reply(parent=comment, created_by=recipient)

        upvote_discussion(reply, self.user)

        earned_rep = 0

        recipient.refresh_from_db()
        self.assertEqual(recipient.reputation, self.start_rep + earned_rep)
 def test_can_NOT_endorse_comment_if_not_author_or_moderator(self):
     comment = create_comment(text='N', thread=self.thread)
     response = self.get_comment_endorsement_post_response(
         self.user, comment)
     self.assertEqual(response.status_code, 403)
 def test_moderator_can_endorse_comment(self):
     comment = create_comment(text='M', thread=self.thread)
     response = self.get_comment_endorsement_post_response(
         self.moderator, comment)
     self.assertContains(response, comment.id, status_code=201)
 def test_reply_users_to_notify_includes_comment_creator(self):
     user = create_random_default_user('Iamy')
     comment = create_comment(created_by=user)
     reply = create_reply(parent=comment)
     self.assertTrue(user in reply.users_to_notify)
 def test_comment_users_to_notify_exlcudes_comment_creator(self):
     user = create_random_default_user('Famy')
     comment = create_comment(thread=self.thread, created_by=user)
     self.assertFalse(user in comment.users_to_notify)
 def test_comment_users_to_notify_includes_thread_creator(self):
     user = create_random_default_user('Eamy')
     thread = create_thread(created_by=user)
     comment = create_comment(thread=thread)
     self.assertTrue(user in comment.users_to_notify)
 def setUp(self):
     self.paper = create_paper()
     self.thread = create_thread(paper=self.paper)
     self.comment = create_comment(thread=self.thread)
     self.reply = create_reply(parent=self.comment)