示例#1
0
    def test_edit_single_shortreview(self):
        """
            Test editing single shortreview
        """

        self.initialize()

        # set up Shortreview
        obj = Object.objects.get(id=self.film.id)
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.kind = ShortReview.REVIEW
        shortreview.object = obj
        shortreview.save()
        shortreview.rating.rating = 10
        shortreview.rating.save()

        # testing if shortreview was saved
        sr = ShortReview.objects.get(object=obj)

        self.failUnlessEqual(sr.review_text, "sialala bumcyk cyk")

        sr.review_text = "Lorem ipsum"
        sr.save()

        # testing if short review was edited successfully
        sr = ShortReview.objects.get(object=obj)
        self.failUnlessEqual(sr.review_text, "Lorem ipsum")
        self.failUnlessEqual(sr.rating.rating, 10)
示例#2
0
    def test_saving_single_shortreview(self):
        """
           Test saving single shortreview
        """

        self.initialize()

        # set up Shortreview
        obj = Object.objects.get(id=self.film.id)
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.kind = ShortReview.REVIEW
        shortreview.object = obj
        shortreview.rating = self.rating
        shortreview.save()

        # testing if shortreview was saved
        sr = ShortReview.objects.get(object=obj)
        
        self.failUnlessEqual(sr.user, shortreview.user)
        self.failUnlessEqual(sr.review_text, "sialala bumcyk cyk")
        self.failUnlessEqual(sr.status, Object.PUBLIC_STATUS)
        self.failUnlessEqual(sr.type, Object.TYPE_SHORT_REVIEW)
        self.failUnlessEqual(sr.kind, ShortReview.REVIEW)
        self.failUnlessEqual(sr.rating.rating, 8)
        self.failUnlessEqual(sr.object, obj)
示例#3
0
    def test_delete_single_shortreview(self):
        """
            Test deleting single shortreview
        """

        self.initialize()

        # set up Shortreview
        obj = Object.objects.get(id=self.film.id)
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.kind = ShortReview.REVIEW
        shortreview.object = obj
        shortreview.save()

        # there should be one short review
        self.failUnlessEqual(ShortReview.objects.all().count(), 1)

        sr = ShortReview.objects.get(object=obj)

        # deleting shortreview
        sr.delete()

        # there should be zero short reviews
        self.failUnlessEqual(ShortReview.objects.all().count(), 0)
示例#4
0
def _show_dashboard(request):
    """
        Show dashboard for logged in user
    """
    from film20.useractivity.useractivity_helper import ajax_activity_pager, \
        ajax_select_template

    filter = None
    user = request.user
    profile = user.get_profile()

    # handle wall post form
    if request.method == "POST":
        form = WallForm(request.POST)
        if form.is_valid():
            sr = ShortReview(kind=ShortReview.WALLPOST,
                             user=user,
                             review_text=form.cleaned_data['text'],
                             type=ShortReview.TYPE_SHORT_REVIEW)
            sr.save()
    form = WallForm()

    activities = UserActivity.objects.wall_filter(request)

    activities = ajax_activity_pager(request, activities)

    data = {
        'activities': activities,
        'profile': profile,
        'form': form,
        'filter': filter,
    }

    return render(request, ajax_select_template(request,
                                                templates['DASHBOARD']), data)
def save_rating(film, user, score=None, review=None, overwrite=False):
    """
        Saves a single rating to database
    """
    rated = False
    if score:
        score = int(float(score))
        link = film.parent.permalink
        rated = rating_helper.rate(user, score, film_id=film.id, overwrite=overwrite, check_if_exists=True, _send_notice=False)

    if review and len(review) < ShortReview._meta.get_field('review_text').max_length:
        try:
            sr = ShortReview.all_objects.get(kind=ShortReview.REVIEW,
                                             object=film, user=user,
                                             LANG=settings.LANGUAGE_CODE)
            logger.info("review fetched from db: updating for user_id %s, object %s" % (str(user.id), str(film.id)))
        except ShortReview.DoesNotExist:
            sr = ShortReview(type=ShortReview.TYPE_SHORT_REVIEW,
                             kind=ShortReview.REVIEW, permalink='FIXME',
                             status=1, version=1, object=film, user=user,
                             LANG=settings.LANGUAGE_CODE)
            logger.info("review doesn't exist, creating with user_id: %s, object %s" % (str(user.id), str(film.id)))

        if not sr.review_text or overwrite:
            sr.review_text = review
            try:
                sr.save()
                logger.info("review saved")
            except Exception, e:
                logger.error("review not saved, exception caught: " + str(e))
示例#6
0
    def test_edit_single_shortreview(self):
        """
            Test editing single shortreview
        """

        self.initialize()

        # set up Shortreview
        obj = Object.objects.get(id=self.film.id)
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.kind = ShortReview.REVIEW
        shortreview.object = obj
        shortreview.save()
        shortreview.rating.rating = 10
        shortreview.rating.save()

        # testing if shortreview was saved
        sr = ShortReview.objects.get(object=obj)

        self.failUnlessEqual(sr.review_text, "sialala bumcyk cyk")

        sr.review_text = "Lorem ipsum"
        sr.save()

        # testing if short review was edited successfully
        sr = ShortReview.objects.get(object=obj)
        self.failUnlessEqual(sr.review_text, "Lorem ipsum")
        self.failUnlessEqual(sr.rating.rating, 10)
示例#7
0
    def test_delete_single_shortreview(self):
        """
            Test deleting single shortreview
        """

        self.initialize()

        # set up Shortreview
        obj = Object.objects.get(id=self.film.id)
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.kind = ShortReview.REVIEW
        shortreview.object = obj
        shortreview.save()

        # there should be one short review
        self.failUnlessEqual(ShortReview.objects.all().count(), 1)

        sr = ShortReview.objects.get(object=obj)

        # deleting shortreview
        sr.delete()

        # there should be zero short reviews
        self.failUnlessEqual(ShortReview.objects.all().count(), 0)
示例#8
0
    def test_notifications(self):

        mail.outbox = []

        wallpost = ShortReview()
        wallpost.user = self.user1
        wallpost.review_text = "lorem ipsum @user,@b_as sid at ble"
        wallpost.status = Object.PUBLIC_STATUS
        wallpost.kind = ShortReview.WALLPOST
        wallpost.type = Object.TYPE_SHORT_REVIEW
        wallpost.save()

        self.assertEqual(len(mail.outbox), 2)
        self.assertTrue(wallpost.get_absolute_url() in mail.outbox[0].body)

        print mail.outbox[0].body

        mail.outbox = []

        comment = ThreadedComment.objects.create_for_object(
            wallpost,
            user=self.user2,
            ip_address='127.0.0.1',
            comment="test comment @root",
            status=ThreadedComment.PUBLIC_STATUS,
            type=ThreadedComment.TYPE_COMMENT)

        self.assertEqual(len(mail.outbox), 1)
        self.assertTrue(comment.get_absolute_url() in mail.outbox[0].body)

        print mail.outbox[0].body

        mail.outbox = []

        post = Post()
        post.title = "Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.lead = "lorem-ipsuam @root"
        post.body = "siala lala tralala @b_as"
        post.user = self.user1
        post.status = Object.PUBLIC_STATUS
        post.type = Object.TYPE_POST
        post.save()

        self.assertEqual(len(mail.outbox), 2)
        self.assertTrue(post.get_absolute_url() in mail.outbox[0].body)

        print mail.outbox[0].body
示例#9
0
    def test_show_wall_post_ok(self):
        """
            Test show_wall_post - article exist!
        """
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = ShortReview.PUBLIC_STATUS
        shortreview.type = ShortReview.TYPE_SHORT_REVIEW
        shortreview.kind = ShortReview.REVIEW
        shortreview.save()

        response = self.client.get(shortreview.get_absolute_url())

        self.failUnlessEqual(response.status_code, 200)
        self.assertEqual(response.context['activity'].content,
                         "sialala bumcyk cyk")
示例#10
0
    def test_show_wall_post_ok(self):
        """
            Test show_wall_post - article exist!
        """
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = ShortReview.PUBLIC_STATUS
        shortreview.type = ShortReview.TYPE_SHORT_REVIEW
        shortreview.kind = ShortReview.REVIEW
        shortreview.save()

        response = self.client.get(shortreview.get_absolute_url())

        self.failUnlessEqual(response.status_code, 200)
        self.assertEqual(response.context["activity"].content, "sialala bumcyk cyk")
示例#11
0
    def test_notifications( self ):
        
        mail.outbox = []

        wallpost = ShortReview()
        wallpost.user = self.user1
        wallpost.review_text = "lorem ipsum @user,@b_as sid at ble"
        wallpost.status = Object.PUBLIC_STATUS
        wallpost.kind = ShortReview.WALLPOST
        wallpost.type = Object.TYPE_SHORT_REVIEW
        wallpost.save()

        self.assertEqual( len( mail.outbox ), 2 )
        self.assertTrue( wallpost.get_absolute_url() in mail.outbox[0].body )
        
        print mail.outbox[0].body

        mail.outbox = []

        comment = ThreadedComment.objects.create_for_object( wallpost, user=self.user2, 
                                ip_address='127.0.0.1',comment="test comment @root",
                                status=ThreadedComment.PUBLIC_STATUS, type = ThreadedComment.TYPE_COMMENT )

        self.assertEqual( len( mail.outbox ), 1 )
        self.assertTrue( comment.get_absolute_url() in mail.outbox[0].body )
        
        print mail.outbox[0].body

        mail.outbox = []

        post = Post()
        post.title = "Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.lead = "lorem-ipsuam @root"
        post.body = "siala lala tralala @b_as"
        post.user = self.user1
        post.status = Object.PUBLIC_STATUS
        post.type = Object.TYPE_POST
        post.save()

        self.assertEqual( len( mail.outbox ), 2 )
        self.assertTrue( post.get_absolute_url() in mail.outbox[0].body )
        
        print mail.outbox[0].body
示例#12
0
    def test_saving_wall_post(self):
        """
            Test saving wall post
        """

        self.initialize()

        wallpost = ShortReview()
        wallpost.user = self.u1
        wallpost.review_text = "sialala bumcyk cyk"
        wallpost.status = Object.PUBLIC_STATUS
        wallpost.kind = ShortReview.WALLPOST
        wallpost.type = Object.TYPE_SHORT_REVIEW
        wallpost.save()

        permalink = 'http://%s.%s/%s/%s/' % (self.u1.username, settings.DOMAIN, urls['WALL'], wallpost.id)
        wp = ShortReview.objects.all()[0]

        self.failUnlessEqual(wp.get_absolute_url(), permalink)
        self.failUnlessEqual(wp.user, wallpost.user)
        self.failUnlessEqual(wp.review_text, "sialala bumcyk cyk")
        self.failUnlessEqual(wp.status, Object.PUBLIC_STATUS)
        self.failUnlessEqual(wp.type, Object.TYPE_SHORT_REVIEW)
示例#13
0
    def test_saving_wall_post(self):
        """
            Test saving wall post
        """

        self.initialize()

        wallpost = ShortReview()
        wallpost.user = self.u1
        wallpost.review_text = "sialala bumcyk cyk"
        wallpost.status = Object.PUBLIC_STATUS
        wallpost.kind = ShortReview.WALLPOST
        wallpost.type = Object.TYPE_SHORT_REVIEW
        wallpost.save()

        permalink = 'http://%s.%s/%s/%s/' % (self.u1.username, settings.DOMAIN, urls['WALL'], wallpost.id)
        wp = ShortReview.objects.all()[0]

        self.failUnlessEqual(wp.get_absolute_url(), permalink)
        self.failUnlessEqual(wp.user, wallpost.user)
        self.failUnlessEqual(wp.review_text, "sialala bumcyk cyk")
        self.failUnlessEqual(wp.status, Object.PUBLIC_STATUS)
        self.failUnlessEqual(wp.type, Object.TYPE_SHORT_REVIEW)
示例#14
0
def save_rating(film, user, score=None, review=None, overwrite=False):
    """
        Saves a single rating to database
    """
    #f = lambda title, year: title if not year else title+" ("+str(year)+")"
    rated = False
    if score:
        score = int(float(score))
        link = film.parent.permalink
        try:
            rating = Rating.objects.get( parent = film,
                                               user = user, 
                                               type=Rating.TYPE_FILM)                
            if rating.rating:
                #movies_already_rated_list.append(film)
                #movies_already_rated = movies_already_rated + "; " + f(film.title, film.release_year)
                rated = True
            else:
                rating.first_rated = datetime.now()
        except Rating.DoesNotExist:
            rating = Rating.objects.create(user =user,
                        parent = film, 
                        film = film,
                        type = Rating.TYPE_FILM,
                        first_rated = datetime.now()
                    )
            
        if not rating.rating or overwrite:
            rating.rating = score
            rating.normalized = score
            rating.last_rated = datetime.now()
            rating.save()
            #movies_rated = movies_rated + "; " + f(film.title, film.release_year)
            #movies_rated_list.append(film)            
            
    if review and len(review)<ShortReview._meta.get_field('review_text').max_length:                
        # added hardcoding the short review language to EN
        try:
            sr = ShortReview.all_objects.get(
                kind = ShortReview.REVIEW,
                object=film, 
                user=user,
                LANG=settings.LANGUAGE_CODE)
            print "got review from db, updating for user_id=" + str(user.id) + ", object=" + str(film.id)
            # TODO: this delete is a hack for some stupid thing that makes it not work when simply updating 
            # (it tries to insert a new review in save() method)
            # CURRENTLY DISABLED (updates to short reviews won't be saved)
            # sr.delete()
            
        except ShortReview.DoesNotExist:            
            sr = ShortReview(                                 
                type = ShortReview.TYPE_SHORT_REVIEW,
                kind = ShortReview.REVIEW,
                permalink = 'FIXME',
                status = 1,
                version = 1, 
                object=film,
                user=user,
                LANG=settings.LANGUAGE_CODE,
            )
            print "review does not exist, creating with user_id=" + str(user.id) + ", object=" + str(film.id)

        if not sr.review_text or overwrite:
            sr.review_text = review
            try:
                sr.save()
                print "review saved"
            except Exception, e:
                print "review not saved, exception caught: " + str(e)
示例#15
0
    def handle_edit_short_review(self, user, the_form, object):
        """
        Handles the short_review editing form.
        """
        logger.debug("Editing short review")
        is_valid = the_form.is_valid()
        
        if is_valid:       
            logger.debug("Editing short review - form valid!")
            review_text = the_form.cleaned_data['review_text']
            object_id = the_form.cleaned_data['object_id']
            edit_id = the_form.cleaned_data['edit_id']
            
            # if object is not passed, get object from DB
            if object==None:
                try: 
                    object = Object.objects.get(id=object_id)
                except Object.DoesNotExist:     
                    logger.error("Object of id = %s does not exists. Error!" % object_id)
                    return False       

            # delete
            if the_form.is_empty():
                # delete the short review
                try:
                    # edit existing short review
                    sr = self.get_short_review(
                        object = object,
                        user = user
                    )
                    logger.debug("ShortReview exists, deleting...")
                    sr.delete()
                    logger.debug("Short review deleted!")
                except ShortReview.DoesNotExist:
                    logger.error("Trying to delete a short review that does not exist!")
                    return False
            # edit / add
            else:
# TODO: REMOVE CODE BELOW
#                try:
#                    # edit existing short review
#                    logger.info((object, type(object), user, type(user)))
#                    sr = self.get_short_review(
#                        object = object,
#                        user = user
#                    )
#                    logger.debug("ShortReview exists, editing...")
#                    sr.review_text = review_text
#                    sr.save()
#                except ShortReview.DoesNotExist:
#                    # add new short review
#                    logger.debug("ShortReview does not exist, adding...")

                sr = ShortReview(
                    type = ShortReview.TYPE_SHORT_REVIEW,
                    permalink = 'FIXME',
                    status = 1,
                    version = 1,
                    kind = ShortReview.REVIEW,
                    object=object,
                    user=user,
                    review_text = review_text,
                )
                sr.save()
                
            logger.debug("Short review saved: " + review_text)
        else:
            logger.debug("Editing short review - form invalid!")
            
        return is_valid and sr
示例#16
0
    def test_planet_tag(self):
        # --- Initialize ---
        self.initialize()
        helper_without_tags = PlanetTagHelper()
        helper_with_tags = PlanetTagHelper(tag='comedy')
        recom_helper = RecomHelper()
        user_activity_helper = UserActivityHelper()

        # --- setup followers ---
        self.u1.followers.follow(self.u2)
        self.u1.followers.follow(self.u3)
        self.u1.followers.follow(self.u4)

        # similar users
        from film20.recommendations.bot_helper import do_create_comparators
        self.films_for_comparator()
        do_create_comparators()

        friends_list = recom_helper.get_following_ids_as_list(self.u1)
        friends_without_activities = helper_without_tags.planet_tag_friends(
            friends_list)
        self.assertEquals(len(friends_without_activities), 0)

        similar_users_list = user_activity_helper.get_similar_users_list(
            request)
        similar_users_without_tags = helper_without_tags.planet_tag_similar_users(
            similar_users_list)
        self.assertEquals(len(similar_users_without_tags), 0)

        notes_without_tags = helper_without_tags.planet_tag_notes()
        self.assertEquals(len(notes_without_tags), 0)

        all_planet_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_planet_activities), 0)

        # --- setup User activities ---
        post = Post()
        post.title = "Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.body = "siala lala tralala"
        post.user = self.u1
        post.status = Object.PUBLIC_STATUS
        post.type = Object.TYPE_POST
        post.save()
        post.related_film.add(self.film)
        post.save()

        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 1)

        post = Post()
        post.title = "Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.body = "siala lala tralala"
        post.user = self.u1
        post.status = Object.PUBLIC_STATUS
        post.type = Object.TYPE_POST
        post.save()
        post.related_film.add(self.film1)
        post.save()

        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 2)

        obj = Object.objects.get(id=self.film2.id)
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.object = obj
        shortreview.kind = ShortReview.REVIEW
        shortreview.save()

        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 3)

        # Activities with 'comedy' tag
        all_activities_with_tags = helper_with_tags.planet_tag_all()
        self.assertEquals(len(all_activities_with_tags), 1)

        # --- setup followers activities ---
        post = Post()
        post.title = "#1 Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.body = "siala lala tralala"
        post.user = self.u2
        post.status = Object.PUBLIC_STATUS
        post.type = Object.TYPE_POST
        post.save()
        post.related_film.add(self.film)
        post.save()

        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 4)

        post = Post()
        post.title = "#2 Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.body = "siala lala tralala"
        post.user = self.u3
        post.status = Object.PUBLIC_STATUS
        post.type = Object.TYPE_POST
        post.save()
        post.related_film.add(self.film1)
        post.save()

        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 5)

        obj = Object.objects.get(id=self.film2.id)
        shortreview = ShortReview()
        shortreview.user = self.u4
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.object = obj
        shortreview.kind = ShortReview.REVIEW
        shortreview.save()

        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 6)

        activities_with_tags = helper_with_tags.planet_tag_all()
        self.assertEquals(len(activities_with_tags), 2)

        all_friends_activities = helper_without_tags.planet_tag_friends(
            friends_list)
        self.assertEquals(len(all_friends_activities), 3)
        friends_activities_with_tag = helper_with_tags.planet_tag_friends(
            friends_list)
        self.assertEquals(len(friends_activities_with_tag), 1)

        # --- Check notes ---
        all_planet_notes = helper_without_tags.planet_tag_notes()
        self.assertEquals(len(all_planet_notes), 4)

        # Post notes with 'comedy' tag
        notes_activities_with_tag = helper_with_tags.planet_tag_notes()
        self.assertEquals(len(notes_activities_with_tag), 2)

        similar_users_activities = helper_without_tags.planet_tag_similar_users(
            similar_users_list)
        self.assertEquals(len(similar_users_activities), 2)

        users_with_tags = helper_with_tags.planet_tag_similar_users(
            similar_users_list)
        self.assertEquals(len(users_with_tags), 1)

        activities = UserActivity.objects.all()
示例#17
0
    def test_planet_tag(self):
        # --- Initialize ---
        self.initialize()
        helper_without_tags = PlanetTagHelper()
        helper_with_tags = PlanetTagHelper(tag='comedy')
        recom_helper = RecomHelper()
        user_activity_helper = UserActivityHelper()

        # --- setup followers ---
        self.u1.followers.follow(self.u2)
        self.u1.followers.follow(self.u3)
        self.u1.followers.follow(self.u4)

        # similar users
        from film20.recommendations.bot_helper import do_create_comparators
        self.films_for_comparator()
        do_create_comparators()

        friends_list = recom_helper.get_following_ids_as_list(self.u1)
        friends_without_activities = helper_without_tags.planet_tag_friends(friends_list)
        self.assertEquals(len(friends_without_activities), 0)
        
        similar_users_list = user_activity_helper.get_similar_users_list(request)
        similar_users_without_tags = helper_without_tags.planet_tag_similar_users(similar_users_list)
        self.assertEquals(len(similar_users_without_tags), 0)

        notes_without_tags = helper_without_tags.planet_tag_notes()
        self.assertEquals(len(notes_without_tags), 0)

        all_planet_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_planet_activities), 0)

        # --- setup User activities ---
        post = Post()
        post.title = "Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.body = "siala lala tralala"
        post.user = self.u1
        post.status = Object.PUBLIC_STATUS
        post.type = Object.TYPE_POST
        post.save()
        post.related_film.add(self.film)
        post.save()
        
        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 1)
        
        post = Post()
        post.title = "Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.body = "siala lala tralala"
        post.user = self.u1
        post.status = Object.PUBLIC_STATUS
        post.type = Object.TYPE_POST
        post.save()
        post.related_film.add(self.film1)
        post.save()
        
        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 2)
                
        obj = Object.objects.get(id=self.film2.id)
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.object = obj
        shortreview.kind = ShortReview.REVIEW
        shortreview.save()

        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 3)
        
        # Activities with 'comedy' tag
        all_activities_with_tags = helper_with_tags.planet_tag_all()
        self.assertEquals(len(all_activities_with_tags), 1)

        # --- setup followers activities ---
        post = Post()
        post.title = "#1 Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.body = "siala lala tralala"
        post.user = self.u2
        post.status = Object.PUBLIC_STATUS
        post.type = Object.TYPE_POST
        post.save()
        post.related_film.add(self.film)
        post.save()

        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 4)

        post = Post()
        post.title = "#2 Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.body = "siala lala tralala"
        post.user = self.u3
        post.status = Object.PUBLIC_STATUS
        post.type = Object.TYPE_POST
        post.save()
        post.related_film.add(self.film1)
        post.save()

        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 5)

        obj = Object.objects.get(id=self.film2.id)
        shortreview = ShortReview()
        shortreview.user = self.u4
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.object = obj
        shortreview.kind = ShortReview.REVIEW
        shortreview.save()

        all_activities = helper_without_tags.planet_tag_all()
        self.assertEquals(len(all_activities), 6)

        activities_with_tags = helper_with_tags.planet_tag_all()
        self.assertEquals(len(activities_with_tags), 2)

        all_friends_activities = helper_without_tags.planet_tag_friends(friends_list)
        self.assertEquals(len(all_friends_activities), 3)
        friends_activities_with_tag = helper_with_tags.planet_tag_friends(friends_list)
        self.assertEquals(len(friends_activities_with_tag), 1)

        # --- Check notes ---
        all_planet_notes = helper_without_tags.planet_tag_notes()
        self.assertEquals(len(all_planet_notes), 4)

        # Post notes with 'comedy' tag
        notes_activities_with_tag = helper_with_tags.planet_tag_notes()
        self.assertEquals(len(notes_activities_with_tag), 2)

        similar_users_activities = helper_without_tags.planet_tag_similar_users(similar_users_list)
        self.assertEquals(len(similar_users_activities), 2)

        users_with_tags = helper_with_tags.planet_tag_similar_users(similar_users_list)
        self.assertEquals(len(users_with_tags), 1)
        
        activities = UserActivity.objects.all() 
示例#18
0
    def test_updating_shortreview_activity(self):
        """
           Test updating shortreview activity
        """

        self.initialize()

        # set up Shortreview
        obj = Object.objects.get(id=self.film.id)
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.object = obj
        shortreview.kind = ShortReview.REVIEW
        shortreview.save()

        shortreview = ShortReview.objects.get(id=shortreview.id)
        shortreview.review_text = "Lorem ipsum"
        shortreview.status = Object.DELETED_STATUS
        shortreview.save()

        activity = UserActivity.objects.get(short_review=shortreview)
        
        # testing if activity was updated properly
        self.failUnlessEqual(activity.title, shortreview.get_title())
        self.failUnlessEqual(activity.content, "Lorem ipsum")
        self.failUnlessEqual(activity.permalink, shortreview.get_absolute_url())
        self.failUnlessEqual(activity.status, UserActivity.DELETED_STATUS)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_SHORT_REVIEW)
        self.failUnlessEqual(activity.username, self.u1.username)
        self.failUnlessEqual(activity.film_title, self.film.title)
        self.failUnlessEqual(activity.film_permalink, self.film.permalink)
示例#19
0
    def test_updating_shortreview_activity(self):
        """
           Test updating shortreview activity
        """

        self.initialize()

        # set up Shortreview
        obj = Object.objects.get(id=self.film.id)
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.object = obj
        shortreview.kind = ShortReview.REVIEW
        shortreview.save()

        shortreview = ShortReview.objects.get(id=shortreview.id)
        shortreview.review_text = "Lorem ipsum"
        shortreview.status = Object.DELETED_STATUS
        shortreview.save()

        activity = UserActivity.objects.get(short_review=shortreview)

        # testing if activity was updated properly
        self.failUnlessEqual(activity.title, shortreview.get_title())
        self.failUnlessEqual(activity.content, "Lorem ipsum")
        self.failUnlessEqual(activity.permalink,
                             shortreview.get_absolute_url())
        self.failUnlessEqual(activity.status, UserActivity.DELETED_STATUS)
        self.failUnlessEqual(activity.activity_type,
                             UserActivity.TYPE_SHORT_REVIEW)
        self.failUnlessEqual(activity.username, self.u1.username)
        self.failUnlessEqual(activity.film_title, self.film.title)
        self.failUnlessEqual(activity.film_permalink, self.film.permalink)
示例#20
0
    def test_saving_double_shortreviews(self):
        """
           Test saving two shortreviews about the same movie by the same user
        """

        self.initialize()

        # set up Shortreviews
        obj = Object.objects.get(id=self.film.id)
        shortreview1 = ShortReview()
        shortreview1.user = self.u1
        shortreview1.review_text = "sialala bumcyk cyk"
        shortreview1.status = Object.PUBLIC_STATUS
        shortreview1.type = Object.TYPE_SHORT_REVIEW
        shortreview1.kind = ShortReview.REVIEW
        shortreview1.object = obj
        shortreview1.rating = self.rating
        shortreview1.save()

        obj = Object.objects.get(id=self.film.id)
        shortreview2 = ShortReview()
        shortreview2.user = self.u1
        shortreview2.review_text = "Lorem ipsum lorem ipsum"
        shortreview2.status = Object.PUBLIC_STATUS
        shortreview2.type = Object.TYPE_SHORT_REVIEW
        shortreview2.kind = ShortReview.REVIEW
        shortreview2.object = obj
        shortreview2.rating = self.rating
        shortreview2.save()


        # testing if shortreview was saved
        sr = ShortReview.objects.filter(object=obj).order_by("created_at")

        self.failUnlessEqual(sr[0].user, shortreview1.user)
        self.failUnlessEqual(sr[0].review_text, "sialala bumcyk cyk")
        self.failUnlessEqual(sr[0].status, Object.PUBLIC_STATUS)
        self.failUnlessEqual(sr[0].type, Object.TYPE_SHORT_REVIEW)
        self.failUnlessEqual(sr[0].kind, ShortReview.REVIEW)
        self.failUnlessEqual(sr[0].rating.rating, 8)
        self.failUnlessEqual(sr[0].object, obj)

        self.failUnlessEqual(sr[1].user, shortreview1.user)
        self.failUnlessEqual(sr[1].review_text, "Lorem ipsum lorem ipsum")
        self.failUnlessEqual(sr[1].status, Object.PUBLIC_STATUS)
        self.failUnlessEqual(sr[1].type, Object.TYPE_SHORT_REVIEW)
        self.failUnlessEqual(sr[1].kind, ShortReview.REVIEW)
        self.failUnlessEqual(sr[1].rating.rating, 8)
        self.failUnlessEqual(sr[1].object, obj)
示例#21
0
    def test_saving_single_shortreview(self):
        """
           Test saving single shortreview
        """

        self.initialize()

        # set up Shortreview
        obj = Object.objects.get(id=self.film.id)
        shortreview = ShortReview()
        shortreview.user = self.u1
        shortreview.review_text = "sialala bumcyk cyk"
        shortreview.status = Object.PUBLIC_STATUS
        shortreview.type = Object.TYPE_SHORT_REVIEW
        shortreview.kind = ShortReview.REVIEW
        shortreview.object = obj
        shortreview.rating = self.rating
        shortreview.save()

        # testing if shortreview was saved
        sr = ShortReview.objects.get(object=obj)
        
        self.failUnlessEqual(sr.user, shortreview.user)
        self.failUnlessEqual(sr.review_text, "sialala bumcyk cyk")
        self.failUnlessEqual(sr.status, Object.PUBLIC_STATUS)
        self.failUnlessEqual(sr.type, Object.TYPE_SHORT_REVIEW)
        self.failUnlessEqual(sr.kind, ShortReview.REVIEW)
        self.failUnlessEqual(sr.rating.rating, 8)
        self.failUnlessEqual(sr.object, obj)
示例#22
0
    def handle_edit_short_review(self, user, the_form, object):
        """
        Handles the short_review editing form.
        """
        logger.debug("Editing short review")
        is_valid = the_form.is_valid()

        if is_valid:
            logger.debug("Editing short review - form valid!")
            review_text = the_form.cleaned_data['review_text']
            object_id = the_form.cleaned_data['object_id']
            edit_id = the_form.cleaned_data['edit_id']

            # if object is not passed, get object from DB
            if object == None:
                try:
                    object = Object.objects.get(id=object_id)
                except Object.DoesNotExist:
                    logger.error("Object of id = %s does not exists. Error!" %
                                 object_id)
                    return False

            # delete
            if the_form.is_empty():
                # delete the short review
                try:
                    # edit existing short review
                    sr = self.get_short_review(object=object, user=user)
                    logger.debug("ShortReview exists, deleting...")
                    sr.delete()
                    logger.debug("Short review deleted!")
                except ShortReview.DoesNotExist:
                    logger.error(
                        "Trying to delete a short review that does not exist!")
                    return False
            # edit / add
            else:
                # TODO: REMOVE CODE BELOW
                #                try:
                #                    # edit existing short review
                #                    logger.info((object, type(object), user, type(user)))
                #                    sr = self.get_short_review(
                #                        object = object,
                #                        user = user
                #                    )
                #                    logger.debug("ShortReview exists, editing...")
                #                    sr.review_text = review_text
                #                    sr.save()
                #                except ShortReview.DoesNotExist:
                #                    # add new short review
                #                    logger.debug("ShortReview does not exist, adding...")

                sr = ShortReview(
                    type=ShortReview.TYPE_SHORT_REVIEW,
                    permalink='FIXME',
                    status=1,
                    version=1,
                    kind=ShortReview.REVIEW,
                    object=object,
                    user=user,
                    review_text=review_text,
                )
                sr.save()

            logger.debug("Short review saved: " + review_text)
        else:
            logger.debug("Editing short review - form invalid!")

        return is_valid and sr
示例#23
0
    def test_saving_double_shortreviews(self):
        """
           Test saving two shortreviews about the same movie by the same user
        """

        self.initialize()

        # set up Shortreviews
        obj = Object.objects.get(id=self.film.id)
        shortreview1 = ShortReview()
        shortreview1.user = self.u1
        shortreview1.review_text = "sialala bumcyk cyk"
        shortreview1.status = Object.PUBLIC_STATUS
        shortreview1.type = Object.TYPE_SHORT_REVIEW
        shortreview1.kind = ShortReview.REVIEW
        shortreview1.object = obj
        shortreview1.rating = self.rating
        shortreview1.save()

        obj = Object.objects.get(id=self.film.id)
        shortreview2 = ShortReview()
        shortreview2.user = self.u1
        shortreview2.review_text = "Lorem ipsum lorem ipsum"
        shortreview2.status = Object.PUBLIC_STATUS
        shortreview2.type = Object.TYPE_SHORT_REVIEW
        shortreview2.kind = ShortReview.REVIEW
        shortreview2.object = obj
        shortreview2.rating = self.rating
        shortreview2.save()


        # testing if shortreview was saved
        sr = ShortReview.objects.filter(object=obj).order_by("created_at")

        self.failUnlessEqual(sr[0].user, shortreview1.user)
        self.failUnlessEqual(sr[0].review_text, "sialala bumcyk cyk")
        self.failUnlessEqual(sr[0].status, Object.PUBLIC_STATUS)
        self.failUnlessEqual(sr[0].type, Object.TYPE_SHORT_REVIEW)
        self.failUnlessEqual(sr[0].kind, ShortReview.REVIEW)
        self.failUnlessEqual(sr[0].rating.rating, 8)
        self.failUnlessEqual(sr[0].object, obj)

        self.failUnlessEqual(sr[1].user, shortreview1.user)
        self.failUnlessEqual(sr[1].review_text, "Lorem ipsum lorem ipsum")
        self.failUnlessEqual(sr[1].status, Object.PUBLIC_STATUS)
        self.failUnlessEqual(sr[1].type, Object.TYPE_SHORT_REVIEW)
        self.failUnlessEqual(sr[1].kind, ShortReview.REVIEW)
        self.failUnlessEqual(sr[1].rating.rating, 8)
        self.failUnlessEqual(sr[1].object, obj)