Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo 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)
Exemplo n.º 5
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)
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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)
Exemplo n.º 9
0
class ThreadedCommentTestCase(TestCase):

    u1 = None
    film = None

    def initialize(self):
        self.clean_data()

        # set up users
        self.u1 = User.objects.create_user('michuk',
                                           '*****@*****.**',
                                           'secret')
        self.u1.save()

        # set up post
        self.post = Post()
        self.post.title = "Lorem ipsum"
        self.post.body = "Sialalala tralalal!"
        self.post.type = Object.TYPE_POST
        self.post.permalink = "lorem-ipsum"
        self.post.status = Post.PUBLIC_STATUS
        self.post.user = self.u1
        self.post.save()

    def clean_data(self):
        User.objects.all().delete()
        Post.objects.all().delete()
        Blog.objects.all().delete()
        ThreadedComment.objects.all().delete()

    def test_comments(self):

        self.initialize()

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

        # take url for new comment
        comment_form_url = get_comment_url(self.post)

        data = {
            'comment': "Tralala bum bum bum",
            'next': self.post.get_absolute_url()
        }

        # send data
        response = self.client.post(
            comment_form_url,
            data,
        )

        # if success there should be one comment in db
        self.failUnlessEqual(len(ThreadedComment.objects.all()), 1)

        comment = ThreadedComment.objects.get(user=self.u1)

        # try to delete comment
        delete_comment_url = "/" + urls["DELETE_COMMENT"] + '/' + str(
            comment.id) + "/"

        response = self.client.get(delete_comment_url, )

    @unittest.skip("comment delete view not available yet")
    def test_comment_delete(self):

        self.initialize()

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

        # take url for new comment
        comment_form_url = get_comment_url(self.post)

        data = {
            'comment': "Tralala bum bum bum",
            'next': self.post.get_absolute_url()
        }

        # send data
        response = self.client.post(
            comment_form_url,
            data,
        )

        # if success there should be one comment in db
        self.failUnlessEqual(len(ThreadedComment.objects.all()), 1)

        comment = ThreadedComment.objects.get(user=self.u1)

        # try to delete comment
        delete_comment_url = "/" + urls["DELETE_COMMENT"] + '/' + str(
            comment.id) + "/"

        response = self.client.get(delete_comment_url, )

        comment = ThreadedComment.objects.get(user=self.u1)
        # comment in db should have DELETED_STATUS

        self.failUnlessEqual(comment.status, Object.DELETED_STATUS)

    def test_comments_ajax(self):

        self.initialize()

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

        # url for new comment
        comment_form_url = get_comment_url(self.post)

        comment_form_url += 'json/'

        data = {
            'comment': "Tralala bum bum bum",
        }

        # sending using ajax
        response = self.client.post(comment_form_url,
                                    data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        # if everything is ok - response code should be 200
        self.failUnlessEqual(response.status_code, 200)
Exemplo n.º 10
0
class ThreadedCommentTestCase(TestCase):

    u1 = None
    film = None

    def initialize(self):
        self.clean_data()

        # set up users
        self.u1= User.objects.create_user('michuk', '*****@*****.**', 'secret')
        self.u1.save()

        # set up post
        self.post = Post()
        self.post.title = "Lorem ipsum"
        self.post.body = "Sialalala tralalal!"
        self.post.type = Object.TYPE_POST
        self.post.permalink = "lorem-ipsum"
        self.post.status = Post.PUBLIC_STATUS
        self.post.user = self.u1
        self.post.save()

    def clean_data(self):
        User.objects.all().delete()
        Post.objects.all().delete()
        Blog.objects.all().delete()
        ThreadedComment.objects.all().delete()

    def test_comments(self):

        self.initialize()

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

        # take url for new comment
        comment_form_url = get_comment_url(self.post)

        data = {
            'comment' : "Tralala bum bum bum",
            'next' : self.post.get_absolute_url()
        }

        # send data
        response = self.client.post(
                        comment_form_url,
                        data,
                        )

        # if success there should be one comment in db
        self.failUnlessEqual(len(ThreadedComment.objects.all()), 1)

        comment = ThreadedComment.objects.get(user=self.u1)

        # try to delete comment
        delete_comment_url = "/"+urls["DELETE_COMMENT"]+'/'+str(comment.id)+"/"

        response = self.client.get(
                        delete_comment_url,
                )
    
    @unittest.skip("comment delete view not available yet")
    def test_comment_delete(self):

        self.initialize()

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

        # take url for new comment
        comment_form_url = get_comment_url(self.post)

        data = {
            'comment' : "Tralala bum bum bum",
            'next' : self.post.get_absolute_url()
        }

        # send data
        response = self.client.post(
                        comment_form_url,
                        data,
                        )

        # if success there should be one comment in db
        self.failUnlessEqual(len(ThreadedComment.objects.all()), 1)

        comment = ThreadedComment.objects.get(user=self.u1)

        # try to delete comment
        delete_comment_url = "/"+urls["DELETE_COMMENT"]+'/'+str(comment.id)+"/"

        response = self.client.get(
                        delete_comment_url,
                )

        comment = ThreadedComment.objects.get(user=self.u1)
        # comment in db should have DELETED_STATUS
        
        self.failUnlessEqual(comment.status, Object.DELETED_STATUS)


    def test_comments_ajax(self):

        self.initialize()

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

        # url for new comment
        comment_form_url = get_comment_url(self.post)

        comment_form_url += 'json/'

        data = {
            'comment' : "Tralala bum bum bum",
        }

        # sending using ajax
        response = self.client.post(
                        comment_form_url,
                        data,
                        HTTP_X_REQUESTED_WITH='XMLHttpRequest'
                        )

        # if everything is ok - response code should be 200
        self.failUnlessEqual(response.status_code, 200)