Esempio n. 1
0
    def test_my_articles(self):
        """
           Test my_articles view 
        """
        self.initialize()

        self.client.login(username=self.u1.username, password='******')

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

        post1 = Post()
        post1.title = "Lorem ipsum2"
        post1.permalink = "lorem-ipsum"
        post1.body = "siala lala tralala"
        post1.user = self.u1
        post1.status = Post.DRAFT_STATUS
        post1.type = Post.TYPE_POST
        post1.save()

        response = self.client.get("/"+urls["ARTICLES"]+"/")
        self.failUnlessEqual(response.status_code, 200)
        self.assertEqual(len(response.context['object_list']), 1)
Esempio n. 2
0
    def test_updating_post_activity(self):
        """
            Test updating post activity
        """
        self.initialize()

        # set up post
        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()

        post.title = "Bum bum bum"
        post.permalink = "bum-bum-bum"
        post.body = "Lubuduubu lubu dubu niech zyje nam prezes naszego klubu!"
        post.status = Object.DRAFT_STATUS
        post.save()
        
        activity = UserActivity.objects.get(post=post)

        # testing if activity was updated properly
        self.failUnlessEqual(activity.title, "Bum bum bum")
        self.failUnlessEqual(activity.content, "Lubuduubu lubu dubu niech zyje nam prezes naszego klubu!")
        self.failUnlessEqual(activity.permalink, post.get_absolute_url())
        self.failUnlessEqual(activity.status, UserActivity.DRAFT_STATUS)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST)
        self.failUnlessEqual(activity.username, self.u1.username)
        self.failUnlessEqual(activity.film_title, self.film.title)
        self.failUnlessEqual(activity.film_permalink, self.film.permalink)
Esempio n. 3
0
    def test_my_articles(self):
        """
           Test my_articles view 
        """
        self.initialize()

        self.client.login(username=self.u1.username, password='******')

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

        post1 = Post()
        post1.title = "Lorem ipsum2"
        post1.permalink = "lorem-ipsum"
        post1.body = "siala lala tralala"
        post1.user = self.u1
        post1.status = Post.DRAFT_STATUS
        post1.type = Post.TYPE_POST
        post1.save()

        response = self.client.get("/" + urls["ARTICLES"] + "/")
        self.failUnlessEqual(response.status_code, 200)
        self.assertEqual(len(response.context['object_list']), 1)
Esempio n. 4
0
    def test_saving_post_activity(self):
        """
            Test saving post activity
        """
        self.initialize()

        # set up post
        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)
        # this method will call save_activity method and in this case create new activity
        post.save()

        activity = UserActivity.objects.get(post=post)

        # testing if activity was saved properly
        self.failUnlessEqual(activity.title, post.title)
        self.failUnlessEqual(activity.content, post.body)
        self.failUnlessEqual(activity.permalink, post.get_absolute_url())
        self.failUnlessEqual(activity.status, post.status)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST)
        self.failUnlessEqual(activity.username, self.u1.username)
        self.failUnlessEqual(activity.film_title, self.film.title)
        self.failUnlessEqual(activity.film_permalink, self.film.permalink)
Esempio n. 5
0
    def test_deleting_post_activity(self):
        """
            Test deleting post activity
        """

        self.initialize()
        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()

        act = UserActivity.objects.get(post=post)

        self.failUnlessEqual(act.status, UserActivity.PUBLIC_STATUS)

        post.status = Object.DELETED_STATUS
        post.save()

        act = UserActivity.objects.get(post=post)
        self.failUnlessEqual(act.status, UserActivity.DELETED_STATUS)
Esempio n. 6
0
    def test_deleting_post_activity(self):
        """
            Test deleting post activity
        """

        self.initialize()
        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()

        act = UserActivity.objects.get(post=post)

        self.failUnlessEqual(act.status, UserActivity.PUBLIC_STATUS)

        post.status = Object.DELETED_STATUS
        post.save()

        act = UserActivity.objects.get(post=post)
        self.failUnlessEqual(act.status, UserActivity.DELETED_STATUS)
Esempio n. 7
0
    def test_saving_post_activity(self):
        """
            Test saving post activity
        """
        self.initialize()

        # set up post
        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)
        # this method will call save_activity method and in this case create new activity
        post.save()

        activity = UserActivity.objects.get(post=post)

        # testing if activity was saved properly
        self.failUnlessEqual(activity.title, post.title)
        self.failUnlessEqual(activity.content, post.body)
        self.failUnlessEqual(activity.permalink, post.get_absolute_url())
        self.failUnlessEqual(activity.status, post.status)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST)
        self.failUnlessEqual(activity.username, self.u1.username)
        self.failUnlessEqual(activity.film_title, self.film.title)
        self.failUnlessEqual(activity.film_permalink, self.film.permalink)
Esempio n. 8
0
    def test_saving_draft_post_activity(self):
        """
           Test saving draft activity
           Make sure that activity is not created for draft posts
        """

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

        self.failUnlessEqual(UserActivity.objects.all().count(), 1) # now we want to create an activity each time
        act = UserActivity.objects.get(post=post)
        self.failUnlessEqual(act.status, UserActivity.DRAFT_STATUS)

        post.status = Post.PUBLIC_STATUS
        post.save()
        self.failUnlessEqual(UserActivity.objects.all().count(), 1)
        act = UserActivity.objects.get(post=post)
        self.failUnlessEqual(act.status, UserActivity.PUBLIC_STATUS)

        post.status = Post.DRAFT_STATUS
        post.save()
        self.failUnlessEqual(UserActivity.objects.all().count(), 1)
        act = UserActivity.objects.get(post=post)
        self.failUnlessEqual(act.status, UserActivity.DRAFT_STATUS)
Esempio n. 9
0
    def test_saving_comment_activity(self):
        """
            Test saving comment activity
        """
        self.initialize()

        # set up post for commenting
        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()

        comment = ThreadedComment()
        comment.user = self.u1
        comment.comment = "Lorem ipsum"
        comment.content_object = post
        comment.status = Object.PUBLIC_STATUS
        comment.type = Object.TYPE_COMMENT
        comment.permalink = "COMMENT"
        comment.save()

        activity = UserActivity.objects.get(comment=comment)

        # testing if activity was saved properly
        self.failUnlessEqual(activity.title,
                             comment.content_object.get_comment_title())
        self.failUnlessEqual(activity.content, comment.comment)
        if settings.ENSURE_OLD_STYLE_PERMALINKS:
            self.failUnlessEqual(
                activity.permalink,
                comment.content_object.get_absolute_url_old_style() + "#" +
                str(comment.id))
        else:
            self.failUnlessEqual(
                activity.permalink,
                comment.content_object.get_absolute_url() + "#" +
                str(comment.id))
        self.failUnlessEqual(activity.status, comment.status)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_COMMENT)
        self.failUnlessEqual(activity.username, self.u1.username)

        #planet_tag_helper without tag = 1 comment
        pth = PlanetTagHelper()
        comments = pth.planet_tag_comments()
        self.assertEquals(len(comments), 1)

        #planet_tag_helper with tag 'comedy' = 0 comment
        #no assigned films to comment
        pth_tags = PlanetTagHelper(tag='comedy')
        comments = pth_tags.planet_tag_comments()
        self.assertEquals(len(comments), 0)
Esempio n. 10
0
    def test_saving_comment_activity(self):
        """
            Test saving comment activity
        """
        self.initialize()

        # set up post for commenting
        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()

        comment = ThreadedComment()
        comment.user = self.u1
        comment.comment = "Lorem ipsum"
        comment.content_object = post
        comment.status = Object.PUBLIC_STATUS
        comment.type = Object.TYPE_COMMENT
        comment.permalink = "COMMENT"
        comment.save()

        activity = UserActivity.objects.get(comment=comment)

        # testing if activity was saved properly
        self.failUnlessEqual(activity.title, comment.content_object.get_comment_title())
        self.failUnlessEqual(activity.content, comment.comment)
        if settings.ENSURE_OLD_STYLE_PERMALINKS:
            self.failUnlessEqual(
                activity.permalink, comment.content_object.get_absolute_url_old_style() + "#" + str(comment.id)
            )
        else:
            self.failUnlessEqual(activity.permalink, comment.content_object.get_absolute_url() + "#" + str(comment.id))
        self.failUnlessEqual(activity.status, comment.status)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_COMMENT)
        self.failUnlessEqual(activity.username, self.u1.username)

        # planet_tag_helper without tag = 1 comment
        pth = PlanetTagHelper()
        comments = pth.planet_tag_comments()
        self.assertEquals(len(comments), 1)

        # planet_tag_helper with tag 'comedy' = 0 comment
        # no assigned films to comment
        pth_tags = PlanetTagHelper(tag="comedy")
        comments = pth_tags.planet_tag_comments()
        self.assertEquals(len(comments), 0)
Esempio n. 11
0
    def test_updating_relatedfilm_post_activity(self):
        """
            Test updating film fields in post activity when related films
            are removed from post
        """
        self.initialize()
        self.client.login(username='******', password='******')

        # set up post
        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()

        activity = UserActivity.objects.get(post=post)

        # testing if activity was saved properly
        self.failUnlessEqual(activity.title, "Lorem ipsum")
        self.failUnlessEqual(activity.content, "siala lala tralala")
        self.failUnlessEqual(activity.permalink, post.get_absolute_url())
        self.failUnlessEqual(activity.status, UserActivity.PUBLIC_STATUS)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST)
        self.failUnlessEqual(activity.username, self.u1.username)
        self.failUnlessEqual(activity.film is None, False)
        self.failUnlessEqual(activity.film_permalink, self.film.permalink)
        self.failUnlessEqual(activity.film_title, self.film.title)

        # update post
        post.title = "New title"
        post.body = "Lorem ipsum! Lorem ipsum! Lorem ipsum!"
        post.related_film = []
        post.save()
        activity = UserActivity.objects.get(post=post)

        # testing if activity was updated properly
        self.failUnlessEqual(activity.title, "New title")
        self.failUnlessEqual(activity.content,
                             "Lorem ipsum! Lorem ipsum! Lorem ipsum!")
        self.failUnlessEqual(activity.permalink, post.get_absolute_url())
        self.failUnlessEqual(activity.status, UserActivity.PUBLIC_STATUS)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST)
        self.failUnlessEqual(activity.username, self.u1.username)
        self.failUnlessEqual(activity.film is None, True)
        self.failUnlessEqual(activity.film_permalink, None)
        self.failUnlessEqual(activity.film_title, None)
Esempio n. 12
0
    def test_updating_comment_activity(self):
        """
            Test updating comment activity
        """

        self.initialize()

        # set up post for commenting
        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()

        comment = ThreadedComment()
        comment.user = self.u1
        comment.comment = "Lorem ipsum"
        comment.content_object = post
        comment.status = Object.PUBLIC_STATUS
        comment.type = Object.TYPE_COMMENT
        comment.permalink = "COMMENT"
        comment.save()

        comment.comment = "siala lala tralala"
        comment.status = Object.DELETED_STATUS
        comment.save()
        activity = UserActivity.objects.get(comment=comment)

        # testing if activity was updated properly
        self.failUnlessEqual(activity.title,
                             comment.content_object.get_comment_title())
        self.failUnlessEqual(activity.content, "siala lala tralala")
        if settings.ENSURE_OLD_STYLE_PERMALINKS:
            self.failUnlessEqual(
                activity.permalink,
                comment.content_object.get_absolute_url_old_style() + "#" +
                str(comment.id))
        else:
            self.failUnlessEqual(
                activity.permalink,
                comment.content_object.get_absolute_url() + "#" +
                str(comment.id))
        self.failUnlessEqual(activity.status, UserActivity.DELETED_STATUS)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_COMMENT)
        self.failUnlessEqual(activity.username, self.u1.username)
Esempio n. 13
0
    def test_updating_relatedfilm_post_activity(self):
        """
            Test updating film fields in post activity when related films
            are removed from post
        """
        self.initialize()
        self.client.login(username='******', password='******')
        
        # set up post
        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()

        activity = UserActivity.objects.get(post=post)

        # testing if activity was saved properly
        self.failUnlessEqual(activity.title, "Lorem ipsum")
        self.failUnlessEqual(activity.content, "siala lala tralala")
        self.failUnlessEqual(activity.permalink, post.get_absolute_url())
        self.failUnlessEqual(activity.status, UserActivity.PUBLIC_STATUS)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST)
        self.failUnlessEqual(activity.username, self.u1.username)
        self.failUnlessEqual(activity.film is None, False)
        self.failUnlessEqual(activity.film_permalink, self.film.permalink)
        self.failUnlessEqual(activity.film_title, self.film.title)

        # update post
        post.title = "New title"
        post.body = "Lorem ipsum! Lorem ipsum! Lorem ipsum!"
        post.related_film = []
        post.save()
        activity = UserActivity.objects.get(post=post)

        # testing if activity was updated properly
        self.failUnlessEqual(activity.title, "New title")
        self.failUnlessEqual(activity.content, "Lorem ipsum! Lorem ipsum! Lorem ipsum!")
        self.failUnlessEqual(activity.permalink, post.get_absolute_url())
        self.failUnlessEqual(activity.status, UserActivity.PUBLIC_STATUS)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST)
        self.failUnlessEqual(activity.username, self.u1.username)
        self.failUnlessEqual(activity.film is None, True)
        self.failUnlessEqual(activity.film_permalink, None)
        self.failUnlessEqual(activity.film_title, None)
Esempio n. 14
0
    def test_all_for_user(self):
        """
           Test all_for_user manager
        """
        post = Post()
        post.title = "Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.body = "siala lala tralala"
        post.user = self.u1
        post.status = Post.PUBLIC_STATUS
        post.type = Post.TYPE_POST
        post.save()

        post1 = Post()
        post1.title = "Lorem ipsum2"
        post1.permalink = "lorem-ipsum"
        post1.body = "siala lala tralala"
        post1.user = self.u1
        post1.status = Post.DRAFT_STATUS
        post1.type = Post.TYPE_POST
        post1.save()

        self.assertEqual(Post.objects.all_for_user(self.u1).count(), 2)
Esempio n. 15
0
    def test_public_for_user(self):
        """
            Test public_for_user manager
        """
        post = Post()
        post.title = "Lorem ipsum"
        post.permalink = "lorem-ipsum"
        post.body = "siala lala tralala"
        post.user = self.u1
        post.status = Post.PUBLIC_STATUS
        post.type = Post.TYPE_POST
        post.save()

        post1 = Post()
        post1.title = "Lorem ipsum2"
        post1.permalink = "lorem-ipsum"
        post1.body = "siala lala tralala"
        post1.user = self.u1
        post1.status = Post.DRAFT_STATUS
        post1.type = Post.TYPE_POST
        post1.save()

        self.assertEqual(Post.objects.public_for_user(self.u1).count(), 1)
Esempio n. 16
0
    def test_updating_post_activity(self):
        """
            Test updating post activity
        """
        self.initialize()

        # set up post
        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()

        post.title = "Bum bum bum"
        post.permalink = "bum-bum-bum"
        post.body = "Lubuduubu lubu dubu niech zyje nam prezes naszego klubu!"
        post.status = Object.DRAFT_STATUS
        post.save()

        activity = UserActivity.objects.get(post=post)

        # testing if activity was updated properly
        self.failUnlessEqual(activity.title, "Bum bum bum")
        self.failUnlessEqual(
            activity.content,
            "Lubuduubu lubu dubu niech zyje nam prezes naszego klubu!")
        self.failUnlessEqual(activity.permalink, post.get_absolute_url())
        self.failUnlessEqual(activity.status, UserActivity.DRAFT_STATUS)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_POST)
        self.failUnlessEqual(activity.username, self.u1.username)
        self.failUnlessEqual(activity.film_title, self.film.title)
        self.failUnlessEqual(activity.film_permalink, self.film.permalink)
Esempio n. 17
0
    def test_edit_existing_post(self):
        """
            Case where user is trying to edit existing post 
        """
        self.client.login(username=self.u1.username, password='******')

        # set up post
        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)
        # this method will call save_activity method and in this case create new activity
        post.save()

        first_publish = post.publish
        # make sure published date is set
        self.failIf(first_publish is None)

        post.title = "Lorem ipsum! Lorem ipsum! Lorem ipsum!"
        post.save()

        # published date should not change after saving again
        self.failUnlessEqual(first_publish, post.publish)

        # make sure related activity also gets updated
        from film20.useractivity.models import UserActivity
        activity = UserActivity.objects.get(
            activity_type=UserActivity.TYPE_POST, post=post, user=post.user)

        post = Post.objects.get(permalink="lorem-ipsum")
        self.failUnlessEqual(post.title,
                             "Lorem ipsum! Lorem ipsum! Lorem ipsum!")
        self.failUnlessEqual(
            activity.slug, "/" + urls['SHOW_PROFILE'] + '/' +
            self.u1.username + '/' + urls['ARTICLE'] + "/lorem-ipsum/")

        # now revert ro draft and then republish
        post.status = Object.DRAFT_STATUS
        post.save()
        post.status = Object.PUBLIC_STATUS
        post.save()

        # published date should not change after republishing an article published before
        self.failUnlessEqual(first_publish, post.publish)
Esempio n. 18
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
Esempio n. 19
0
    def test_tagging( self ):
        """
            test posts tagging
        """

        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.tag_list = 'ww2,pl,lorem'
        post.save()

        self.assertEqual( UserActivity.objects.all_notes().tagged( 'ww2' ).count(), 1 )
Esempio n. 20
0
    def test_edit_existing_post(self):
        """
            Case where user is trying to edit existing post 
        """
        self.client.login(username=self.u1.username, password='******')

        # set up post
        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)
        # this method will call save_activity method and in this case create new activity
        post.save()
        
        first_publish = post.publish
        # make sure published date is set
        self.failIf(first_publish is None)

        post.title = "Lorem ipsum! Lorem ipsum! Lorem ipsum!"
        post.save()
        
        # published date should not change after saving again
        self.failUnlessEqual(first_publish, post.publish)

        # make sure related activity also gets updated
        from film20.useractivity.models import UserActivity
        activity = UserActivity.objects.get(activity_type = UserActivity.TYPE_POST, post = post, user = post.user)

        post = Post.objects.get(permalink="lorem-ipsum")
        self.failUnlessEqual(post.title, "Lorem ipsum! Lorem ipsum! Lorem ipsum!")
        self.failUnlessEqual(activity.slug, "/" + urls['SHOW_PROFILE'] + '/' + self.u1.username + '/' + urls['ARTICLE'] + "/lorem-ipsum/")


        # now revert ro draft and then republish
        post.status = Object.DRAFT_STATUS
        post.save()
        post.status = Object.PUBLIC_STATUS
        post.save()

        # published date should not change after republishing an article published before
        self.failUnlessEqual(first_publish, post.publish)
Esempio n. 21
0
    def test_tagging(self):
        """
            test posts tagging
        """

        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.tag_list = 'ww2,pl,lorem'
        post.save()

        self.assertEqual(
            UserActivity.objects.all_notes().tagged('ww2').count(), 1)
Esempio n. 22
0
    def test_updating_comment_activity(self):
        """
            Test updating comment activity
        """

        self.initialize()

        # set up post for commenting
        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()

        comment = ThreadedComment()
        comment.user = self.u1
        comment.comment = "Lorem ipsum"
        comment.content_object = post
        comment.status = Object.PUBLIC_STATUS
        comment.type = Object.TYPE_COMMENT
        comment.permalink = "COMMENT"
        comment.save()

        comment.comment = "siala lala tralala"
        comment.status = Object.DELETED_STATUS
        comment.save()
        activity = UserActivity.objects.get(comment=comment)

        # testing if activity was updated properly
        self.failUnlessEqual(activity.title, comment.content_object.get_comment_title())
        self.failUnlessEqual(activity.content, "siala lala tralala")
        if settings.ENSURE_OLD_STYLE_PERMALINKS:
            self.failUnlessEqual(
                activity.permalink, comment.content_object.get_absolute_url_old_style() + "#" + str(comment.id)
            )
        else:
            self.failUnlessEqual(activity.permalink, comment.content_object.get_absolute_url() + "#" + str(comment.id))
        self.failUnlessEqual(activity.status, UserActivity.DELETED_STATUS)
        self.failUnlessEqual(activity.activity_type, UserActivity.TYPE_COMMENT)
        self.failUnlessEqual(activity.username, self.u1.username)
Esempio n. 23
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
Esempio n. 24
0
    def test_saving_draft_post_activity(self):
        """
           Test saving draft activity
           Make sure that activity is not created for draft posts
        """

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

        post_activities = UserActivity.objects.filter(
            activity_type=UserActivity.TYPE_POST)

        self.failUnlessEqual(post_activities.count(),
                             1)  # now we want to create an activity each time
        act = UserActivity.objects.get(post=post)
        self.failUnlessEqual(act.status, UserActivity.DRAFT_STATUS)

        post.status = Post.PUBLIC_STATUS
        post.save()
        self.failUnlessEqual(post_activities.count(), 1)
        act = UserActivity.objects.get(post=post)
        self.failUnlessEqual(act.status, UserActivity.PUBLIC_STATUS)

        post.status = Post.DRAFT_STATUS
        post.save()
        self.failUnlessEqual(post_activities.count(), 1)
        act = UserActivity.objects.get(post=post)
        self.failUnlessEqual(act.status, UserActivity.DRAFT_STATUS)
Esempio n. 25
0
    def test_cache_featured_review(self):
        """
        test cache invalidate for featured review
        """
        post = Post.objects.featured_review()
        self.assertEqual(post, None)

        post = Post()
        post.title = "first post"
        post.permalink = "first-post"
        post.body = "post first post"
        post.user = self.u1
        post.status = Post.PUBLIC_STATUS
        post.type = Post.TYPE_POST
        post.featured_note = True
        post.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'first-post')

        post1 = Post()
        post1.title = "second post"
        post1.permalink = "second-post"
        post1.body = "post second post"
        post1.user = self.u1
        post1.status = Post.PUBLIC_STATUS
        post1.type = Post.TYPE_POST
        post1.featured_note = True
        post1.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'second-post')

        post2 = Post()
        post2.title = "third post"
        post2.permalink = "third-post"
        post2.body = "post third post"
        post2.user = self.u1
        post2.status = Post.PUBLIC_STATUS
        post2.type = Post.TYPE_POST
        post2.featured_note = True
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'third-post')

        # change featured post status and check if cache is invalidated
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.DRAFT_STATUS
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'second-post')

        # republished post
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.PUBLIC_STATUS
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'third-post')
        self.assertEqual(Post.objects.recent_reviews().count(), 0)
Esempio n. 26
0
    def test_cache_recent_reviews(self):
        """
        test cache invalidate for recent reviews
        """
        posts = Post.objects.recent_reviews()
        self.assertEqual(len(posts), 0)

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

        posts = Post.objects.recent_reviews()
        self.assertEqual(posts.count(), 1)

        post1 = Post()
        post1.title = "Lorem ipsum2"
        post1.permalink = "lorem-ipsum2"
        post1.body = "siala lala tralala"
        post1.user = self.u1
        post1.status = Post.PUBLIC_STATUS
        post1.type = Post.TYPE_POST
        post1.is_published = True
        post1.save()

        posts = Post.objects.recent_reviews()
        featured = Post.objects.featured_review()
        self.assertEqual(posts.count(),2)
        self.assertEqual(featured, None)

        post2 = Post()
        post2.title = "third post"
        post2.permalink = "third-post"
        post2.body = "siala lala tralala"
        post2.user = self.u1
        post2.status = Post.PUBLIC_STATUS
        post2.type = Post.TYPE_POST
        post2.is_published = True
        post2.save()

        posts = Post.objects.recent_reviews()
        featured = Post.objects.featured_review()
        self.assertEqual(posts.count(),3)
        self.assertEqual(featured, None)

        # change featured post status and check if cache is invalidated
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.DRAFT_STATUS
        post2.save()

        posts = Post.objects.recent_reviews()
        featured = Post.objects.featured_review()
        self.assertEqual(posts.count(),2)
        self.assertEqual(featured, None)

        # republished post
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.PUBLIC_STATUS
        post2.save()

        posts = Post.objects.recent_reviews()
        featured = Post.objects.featured_review()
        self.assertEqual(posts.count(),3)
        self.assertEqual(featured, None)
Esempio n. 27
0
    def test_cache_featured_review(self):
        """
        test cache invalidate for featured review
        """
        post = Post.objects.featured_review()
        self.assertEqual(post, None)

        post = Post()
        post.title = "first post"
        post.permalink = "first-post"
        post.body = "post first post"
        post.user = self.u1
        post.status = Post.PUBLIC_STATUS
        post.type = Post.TYPE_POST
        post.featured_note = True
        post.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'first-post')

        post1 = Post()
        post1.title = "second post"
        post1.permalink = "second-post"
        post1.body = "post second post"
        post1.user = self.u1
        post1.status = Post.PUBLIC_STATUS
        post1.type = Post.TYPE_POST
        post1.featured_note = True
        post1.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'second-post')

        post2 = Post()
        post2.title = "third post"
        post2.permalink = "third-post"
        post2.body = "post third post"
        post2.user = self.u1
        post2.status = Post.PUBLIC_STATUS
        post2.type = Post.TYPE_POST
        post2.featured_note = True
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'third-post')

        # change featured post status and check if cache is invalidated
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.DRAFT_STATUS
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'second-post')

        # republished post
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.PUBLIC_STATUS
        post2.save()

        post = Post.objects.featured_review()
        self.assertEqual(post.permalink, u'third-post')
        self.assertEqual(Post.objects.recent_reviews().count(), 0)
Esempio n. 28
0
    def test_cache_recent_reviews(self):
        """
        test cache invalidate for recent reviews
        """
        posts = Post.objects.recent_reviews()
        self.assertEqual(len(posts), 0)

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

        posts = Post.objects.recent_reviews()
        self.assertEqual(posts.count(), 1)

        post1 = Post()
        post1.title = "Lorem ipsum2"
        post1.permalink = "lorem-ipsum2"
        post1.body = "siala lala tralala"
        post1.user = self.u1
        post1.status = Post.PUBLIC_STATUS
        post1.type = Post.TYPE_POST
        post1.is_published = True
        post1.save()

        posts = Post.objects.recent_reviews()
        featured = Post.objects.featured_review()
        self.assertEqual(posts.count(), 2)
        self.assertEqual(featured, None)

        post2 = Post()
        post2.title = "third post"
        post2.permalink = "third-post"
        post2.body = "siala lala tralala"
        post2.user = self.u1
        post2.status = Post.PUBLIC_STATUS
        post2.type = Post.TYPE_POST
        post2.is_published = True
        post2.save()

        posts = Post.objects.recent_reviews()
        featured = Post.objects.featured_review()
        self.assertEqual(posts.count(), 3)
        self.assertEqual(featured, None)

        # change featured post status and check if cache is invalidated
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.DRAFT_STATUS
        post2.save()

        posts = Post.objects.recent_reviews()
        featured = Post.objects.featured_review()
        self.assertEqual(posts.count(), 2)
        self.assertEqual(featured, None)

        # republished post
        post2 = Post.objects.get(title__iexact='third post')
        post2.status = Post.PUBLIC_STATUS
        post2.save()

        posts = Post.objects.recent_reviews()
        featured = Post.objects.featured_review()
        self.assertEqual(posts.count(), 3)
        self.assertEqual(featured, None)
Esempio n. 29
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() 
Esempio n. 30
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()