Beispiel #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 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)
    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)
    def test_endorse_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_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'
        )

        # this is the api call we are testing
        rating = hydroshare.endorse_resource(new_resource.short_id, user_rater_1)
        self.assertEqual(rating.content_object, new_resource)
        self.assertEqual(rating.user, user_rater_1)
        self.assertEqual(rating.value, 1)
        # test that we have only one rating object for the given resource and given rater
        ratings = Rating.objects.filter(object_pk=new_resource.id, user=user_rater_1)
        self.assertEqual(len(ratings), 1)

        # test that a specific user can rate/endorse a resource only once
        rating = hydroshare.endorse_resource(new_resource.short_id, user_rater_1)
        self.assertEqual(rating.value, 1)
        ratings = Rating.objects.filter(object_pk=new_resource.id, user=user_rater_1)
        self.assertEqual(len(ratings), 1)
        self.assertEqual(ratings[0].value, 1)

        # test that a 2nd user can rate the same resource
        rating = hydroshare.endorse_resource(new_resource.short_id, user_rater_2)
        self.assertEqual(rating.content_object, new_resource)
        self.assertEqual(rating.user, user_rater_2)
        self.assertEqual(rating.value, 1)

        # test that we have two rating object for the given resource
        ratings = Rating.objects.filter(object_pk=new_resource.id)
        self.assertEqual(len(ratings), 2)

        # test removing endorsement
        # this is the api call we are testing
        hydroshare.endorse_resource(new_resource.short_id, user_rater_1, endorse=False)
        # test that we have no rating object for the given resource and given rater
        ratings = Rating.objects.filter(object_pk=new_resource.id, user=user_rater_1)
        self.assertEqual(len(ratings), 0)
Beispiel #4
0
    def test_endorse_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_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')

        # this is the api call we are testing
        rating = hydroshare.endorse_resource(new_resource.short_id,
                                             user_rater_1)
        self.assertEqual(rating.content_object, new_resource)
        self.assertEqual(rating.user, user_rater_1)
        self.assertEqual(rating.value, 1)
        # test that we have only one rating object for the given resource and given rater
        ratings = Rating.objects.filter(object_pk=new_resource.id,
                                        user=user_rater_1)
        self.assertEqual(len(ratings), 1)

        # test that a specific user can rate/endorse a resource only once
        rating = hydroshare.endorse_resource(new_resource.short_id,
                                             user_rater_1)
        self.assertEqual(rating.value, 1)
        ratings = Rating.objects.filter(object_pk=new_resource.id,
                                        user=user_rater_1)
        self.assertEqual(len(ratings), 1)
        self.assertEqual(ratings[0].value, 1)

        # test that a 2nd user can rate the same resource
        rating = hydroshare.endorse_resource(new_resource.short_id,
                                             user_rater_2)
        self.assertEqual(rating.content_object, new_resource)
        self.assertEqual(rating.user, user_rater_2)
        self.assertEqual(rating.value, 1)

        # test that we have two rating object for the given resource
        ratings = Rating.objects.filter(object_pk=new_resource.id)
        self.assertEqual(len(ratings), 2)

        # test removing endorsement
        # this is the api call we are testing
        hydroshare.endorse_resource(new_resource.short_id,
                                    user_rater_1,
                                    endorse=False)
        # test that we have no rating object for the given resource and given rater
        ratings = Rating.objects.filter(object_pk=new_resource.id,
                                        user=user_rater_1)
        self.assertEqual(len(ratings), 0)