Ejemplo n.º 1
0
    def setUp(self):
        # create 2 users
        self.user1 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='user1_first',
            last_name='user1_last',
            superuser=False,
            groups=[]
        )

        self.user2 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='user2_first',
            last_name='user2_last',
            superuser=False,
            groups=[]
        )

        # create a resource
        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user1,
            'My Test Resource'
        )

        # create comment1 from user 2
        self.comment_1 = hydroshare.comment_on_resource(self.res.short_id,
                                                        "comment1 by user2",
                                                        user=self.user2)

        # create comment2 to reply comment 1 from user 1
        self.comment_2 = hydroshare.comment_on_resource(self.res.short_id,
                                                        "comment2 to reply comment1 by user1",
                                                        user=self.user1,
                                                        in_reply_to=self.comment_1.pk)

        # create comment3 from user 2 to reply comment 2 from user 2
        self.comment_3 = hydroshare.comment_on_resource(self.res.short_id,
                                                        "comment3 to reply comment 2 by user2",
                                                        user=self.user2,
                                                        in_reply_to=self.comment_2.pk)
Ejemplo n.º 2
0
    def setUp(self):
        # create 2 users
        self.user1 = hydroshare.create_account('*****@*****.**',
                                               username='******',
                                               first_name='user1_first',
                                               last_name='user1_last',
                                               superuser=False,
                                               groups=[])

        self.user2 = hydroshare.create_account('*****@*****.**',
                                               username='******',
                                               first_name='user2_first',
                                               last_name='user2_last',
                                               superuser=False,
                                               groups=[])

        # create a resource
        self.res = hydroshare.create_resource('GenericResource', self.user1,
                                              'My Test Resource')

        # create comment from user 2
        self.comment = hydroshare.comment_on_resource(self.res.short_id,
                                                      "comment by user2",
                                                      user=self.user2)

        # endorse resource
        self.endorse1_res = hydroshare.endorse_resource(
            self.res.short_id, self.user2)
        self.endorse2_res = hydroshare.endorse_resource(
            self.res.short_id, self.user1)

        # endorse comment
        self.endorse1_com = hydroshare.endorse_comment(self.comment.id,
                                                       self.res.short_id,
                                                       self.user1)
        self.endorse2_com = hydroshare.endorse_comment(self.comment.id,
                                                       self.res.short_id,
                                                       self.user2)
Ejemplo n.º 3
0
    def setUp(self):
        # create 2 users
        self.user1 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='user1_first',
            last_name='user1_last',
            superuser=False,
            groups=[]
        )

        self.user2 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='user2_first',
            last_name='user2_last',
            superuser=False,
            groups=[]
        )

        # create a resource
        self.res = hydroshare.create_resource(
            'GenericResource',
            self.user1,
            'My Test Resource'
        )

        # create comment from user 2
        self.comment = hydroshare.comment_on_resource(self.res.short_id, "comment by user2", user=self.user2)

        # endorse resource
        self.endorse1_res = hydroshare.endorse_resource(self.res.short_id, self.user2)
        self.endorse2_res = hydroshare.endorse_resource(self.res.short_id, self.user1)

        # endorse comment
        self.endorse1_com = hydroshare.endorse_comment(self.comment.id, self.res.short_id, self.user1)
        self.endorse2_com = hydroshare.endorse_comment(self.comment.id, self.res.short_id, self.user2)
Ejemplo n.º 4
0
    def test_comment_on_resource(self):
        # create a user to be used for creating the resource
        user_creator = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[])

        user_commenter_1 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Commenter_1_FirstName',
            last_name='Commenter_1_LastName',
            superuser=False,
            groups=[])
        user_commenter_2 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Commenter_2_FirstName',
            last_name='Commenter_2_LastName',
            superuser=False,
            groups=[])

        user_commenter_3 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Commenter_3_FirstName',
            last_name='Commenter_3_LastName',
            superuser=False,
            groups=[])
        # create a resource
        new_resource = hydroshare.create_resource('GenericResource',
                                                  user_creator,
                                                  'My Test Resource')

        new_resource_2 = hydroshare.create_resource('GenericResource',
                                                    user_creator,
                                                    'My Test Resource 2')

        # test at this point we have no comments
        comments_count = ThreadedComment.objects.all().count()
        self.assertEqual(comments_count, 0)

        comment_text = "comment by commenter_1"
        # this is the api we are testing
        comment = hydroshare.comment_on_resource(new_resource.short_id,
                                                 comment_text,
                                                 user=user_commenter_1)
        # test at this point we have one comment
        comments_count = ThreadedComment.objects.all().count()
        self.assertEqual(comments_count, 1)
        self.assertEqual(comment.content_object, new_resource)
        self.assertEqual(comment.user, user_commenter_1)
        self.assertEqual(comment.comment, comment_text)
        # test this the lead comment
        self.assertEqual(comment.replied_to, None)

        # let the commenter-2 reply to the comment by commenter-1
        comment_text = "reply comment by commenter_2"
        # this is the api we are testing
        reply_comment = hydroshare.comment_on_resource(new_resource.short_id,
                                                       comment_text,
                                                       user=user_commenter_2,
                                                       in_reply_to=comment.id)
        # test at this point we have 2 comment
        comments_count = ThreadedComment.objects.all().count()
        self.assertEqual(comments_count, 2)
        self.assertEqual(reply_comment.content_object, new_resource)
        self.assertEqual(reply_comment.user, user_commenter_2)
        self.assertEqual(reply_comment.comment, comment_text)
        self.assertEqual(reply_comment.replied_to, comment)
        self.assertTrue(reply_comment.submit_date > comment.submit_date, True)
        # test this the lead comment
        self.assertEqual(comment.replied_to, None)

        # test that we can reply to the same comment twice
        comment_text = "reply comment by commenter_3"
        reply_comment = hydroshare.comment_on_resource(new_resource.short_id,
                                                       comment_text,
                                                       user=user_commenter_3,
                                                       in_reply_to=comment.id)
        # test at this point we have 3 comment
        comments_count = ThreadedComment.objects.all().count()
        self.assertEqual(comments_count, 3)
        self.assertEqual(reply_comment.content_object, new_resource)
        self.assertEqual(reply_comment.user, user_commenter_3)
        self.assertEqual(reply_comment.comment, comment_text)
        self.assertEqual(reply_comment.replied_to, comment)
        self.assertTrue(reply_comment.submit_date > comment.submit_date, True)
        # test this the lead comment
        self.assertEqual(comment.replied_to, None)

        # test that the same user can comment on the same resource more than once
        comment_text = "another comment by commenter_1"
        comment = hydroshare.comment_on_resource(new_resource.short_id,
                                                 comment_text,
                                                 user=user_commenter_1)
        # test at this point we have 4 comment
        comments_count = ThreadedComment.objects.all().count()
        self.assertEqual(comments_count, 4)
        self.assertEqual(comment.content_object, new_resource)
        self.assertEqual(comment.user, user_commenter_1)
        self.assertEqual(comment.comment, comment_text)
        # test this the lead comment
        self.assertEqual(comment.replied_to, None)

        # test that one can't reply to his/her own comment
        comment_text = "reply to my own comment by commenter_1"
        self.assertRaises(
            ValueError,
            lambda: hydroshare.comment_on_resource(new_resource.short_id,
                                                   comment_text,
                                                   user=user_commenter_1,
                                                   in_reply_to=comment.id))

        # test that reply_to comment must exists for the given resource otherwise it raises value error
        self.assertRaises(
            ValueError,
            lambda: hydroshare.comment_on_resource(new_resource_2.short_id,
                                                   comment_text,
                                                   user=user_commenter_2,
                                                   in_reply_to=comment.id))
Ejemplo n.º 5
0
    def test_endorse_comment(self):
        # create a user to be used for creating the resource
        user_creator = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[])
        user_commenter_1 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Commenter_1_FirstName',
            last_name='Commenter_1_LastName',
            superuser=False,
            groups=[])

        user_rater_1 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Rater_1_FirstName',
            last_name='Rater_1_LastName',
            superuser=False,
            groups=[])

        user_rater_2 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Rater_2_FirstName',
            last_name='Rater_2_LastName',
            superuser=False,
            groups=[])

        # create a resource
        new_resource = hydroshare.create_resource('GenericResource',
                                                  user_creator,
                                                  'My Test Resource')

        resource_2 = hydroshare.create_resource('GenericResource',
                                                user_creator,
                                                'My 2nd Test Resource')
        # first comment on resource
        comment_text = "comment by commenter_1"
        comment = hydroshare.comment_on_resource(new_resource.short_id,
                                                 comment_text,
                                                 user=user_commenter_1)

        # at this point there should not be any ratings for this new comment
        ratings = Rating.objects.filter(object_pk=comment.id)
        self.assertEqual(len(ratings), 0)

        # rate the comment - this is the api call we are testing
        rating = hydroshare.endorse_comment(comment.id, new_resource.short_id,
                                            user_rater_1)
        self.assertEqual(rating.content_object, comment)
        self.assertEqual(rating.user, user_rater_1)
        # test that the rating value is 1 (+1)
        self.assertEqual(rating.value, 1)

        # at this point there should be one ratings for this comment
        ratings = Rating.objects.filter(object_pk=comment.id)
        # test that the rating value is 1 (+1)
        self.assertEqual(len(ratings), 1)

        # test the user can't rate the same comment twice - no new rating object is created
        rating = hydroshare.endorse_comment(comment.id, new_resource.short_id,
                                            user_rater_1)
        self.assertEqual(rating.content_object, comment)
        self.assertEqual(rating.user, user_rater_1)
        # test that the rating value is 1 (+1)
        self.assertEqual(rating.value, 1)

        # at this point there should be one ratings for this comment
        ratings = Rating.objects.filter(object_pk=comment.id)
        self.assertEqual(len(ratings), 1)
        # test that the rating value is 1 (+1)
        self.assertEqual(ratings[0].value, 1)

        # rate the same comment by another user- this is the api call we are testing
        rating = hydroshare.endorse_comment(comment.id, new_resource.short_id,
                                            user_rater_2)
        self.assertEqual(rating.content_object, comment)
        self.assertEqual(rating.user, user_rater_2)
        # test that the rating value is 1 (+1)
        self.assertEqual(rating.value, 1)

        # at this point there should be two ratings for this comment
        ratings = Rating.objects.filter(object_pk=comment.id)
        self.assertEqual(len(ratings), 2)
        # test that the rating value is 1 (+1) for each of these ratings
        self.assertEqual(ratings[0].value, 1)
        self.assertEqual(ratings[1].value, 1)

        # test removing a rating from a comment
        hydroshare.endorse_comment(comment.id,
                                   new_resource.short_id,
                                   user_rater_2,
                                   endorse=False)

        # at this point there should be one ratings for this comment
        ratings = Rating.objects.filter(object_pk=comment.id)
        self.assertEqual(len(ratings), 1)
        # test that the rating value is 1 (+1)
        self.assertEqual(ratings[0].value, 1)

        # there should not be any ratings by user_rater_2 for this comment
        ratings = Rating.objects.filter(object_pk=comment.id,
                                        user=user_rater_2)
        self.assertEqual(len(ratings), 0)

        # test that ValueError exception raised if the comment does not exist for the specified resource
        self.assertRaises(
            ValueError, lambda: hydroshare.endorse_comment(
                comment.id, resource_2.short_id, user_rater_2))
Ejemplo n.º 6
0
    def test_comment_on_resource(self):
        # create a user to be used for creating the resource
        user_creator = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Creator_FirstName',
            last_name='Creator_LastName',
            superuser=False,
            groups=[]
        )

        user_commenter_1 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Commenter_1_FirstName',
            last_name='Commenter_1_LastName',
            superuser=False,
            groups=[]
        )
        user_commenter_2 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Commenter_2_FirstName',
            last_name='Commenter_2_LastName',
            superuser=False,
            groups=[]
        )

        user_commenter_3 = hydroshare.create_account(
            '*****@*****.**',
            username='******',
            first_name='Commenter_3_FirstName',
            last_name='Commenter_3_LastName',
            superuser=False,
            groups=[]
        )
        # create a resource
        new_resource = hydroshare.create_resource(
            'GenericResource',
            user_creator,
            'My Test Resource'
        )

        new_resource_2 = hydroshare.create_resource(
            'GenericResource',
            user_creator,
            'My Test Resource 2'
        )

        # test at this point we have no comments
        comments_count = ThreadedComment.objects.all().count()
        self.assertEqual(comments_count, 0)

        comment_text = "comment by commenter_1"
        # this is the api we are testing
        comment = hydroshare.comment_on_resource(new_resource.short_id, comment_text, user=user_commenter_1)
        # test at this point we have one comment
        comments_count = ThreadedComment.objects.all().count()
        self.assertEqual(comments_count, 1)
        self.assertEqual(comment.content_object, new_resource)
        self.assertEqual(comment.user, user_commenter_1)
        self.assertEqual(comment.comment, comment_text)
        # test this the lead comment
        self.assertEqual(comment.replied_to, None)

        # let the commenter-2 reply to the comment by commenter-1
        comment_text = "reply comment by commenter_2"
        # this is the api we are testing
        reply_comment = hydroshare.comment_on_resource(new_resource.short_id, comment_text, user=user_commenter_2, in_reply_to=comment.id)
        # test at this point we have 2 comment
        comments_count = ThreadedComment.objects.all().count()
        self.assertEqual(comments_count, 2)
        self.assertEqual(reply_comment.content_object, new_resource)
        self.assertEqual(reply_comment.user, user_commenter_2)
        self.assertEqual(reply_comment.comment, comment_text)
        self.assertEqual(reply_comment.replied_to, comment)
        self.assertTrue( reply_comment.submit_date > comment.submit_date, True)
        # test this the lead comment
        self.assertEqual(comment.replied_to, None)

        # test that we can reply to the same comment twice
        comment_text = "reply comment by commenter_3"
        reply_comment = hydroshare.comment_on_resource(new_resource.short_id, comment_text, user=user_commenter_3, in_reply_to=comment.id)
        # test at this point we have 3 comment
        comments_count = ThreadedComment.objects.all().count()
        self.assertEqual(comments_count, 3)
        self.assertEqual(reply_comment.content_object, new_resource)
        self.assertEqual(reply_comment.user, user_commenter_3)
        self.assertEqual(reply_comment.comment, comment_text)
        self.assertEqual(reply_comment.replied_to, comment)
        self.assertTrue( reply_comment.submit_date > comment.submit_date, True)
        # test this the lead comment
        self.assertEqual(comment.replied_to, None)

        # test that the same user can comment on the same resource more than once
        comment_text = "another comment by commenter_1"
        comment = hydroshare.comment_on_resource(new_resource.short_id, comment_text, user=user_commenter_1)
        # test at this point we have 4 comment
        comments_count = ThreadedComment.objects.all().count()
        self.assertEqual(comments_count, 4)
        self.assertEqual(comment.content_object, new_resource)
        self.assertEqual(comment.user, user_commenter_1)
        self.assertEqual(comment.comment, comment_text)
        # test this the lead comment
        self.assertEqual(comment.replied_to, None)

        # test that one can't reply to his/her own comment
        comment_text = "reply to my own comment by commenter_1"
        self.assertRaises(ValueError, lambda : hydroshare.comment_on_resource(new_resource.short_id, comment_text, user=user_commenter_1, in_reply_to=comment.id))

        # test that reply_to comment must exists for the given resource otherwise it raises value error
        self.assertRaises(ValueError, lambda : hydroshare.comment_on_resource(new_resource_2.short_id, comment_text, user=user_commenter_2, in_reply_to=comment.id))