Beispiel #1
0
    def test_add_comment(self):

        response = self.client.get("/post/1/addcomment/")
        self.assert_401(response)

        user = User(username="******", email="*****@*****.**", password="******")

        db.session.add(user)
        db.session.commit()

        self.login(login="******", password="******")

        response = self.client.get("/post/1/addcomment/")
        self.assert_404(response)

        post = Post(author=user, title="test", link="http://reddit.com")

        db.session.add(post)
        db.session.commit()

        response = self.client.get("/post/%d/addcomment/" % post.id)
        self.assert_200(response)

        response = self.client.get("/post/%d/1/reply/" % post.id)

        with mail.record_messages() as outbox:
            response = self.client.post("/post/%d/addcomment/" % post.id, data={"comment": "testing"})

            assert len(outbox) == 0

        comment = Comment.query.first()

        self.assert_redirects(response, comment.url)

        # reply to this comment

        response = self.client.get("/post/%d/%d/reply/" % (post.id, comment.id))

        self.assert_200(response)

        with mail.record_messages() as outbox:
            response = self.client.post("/post/%d/%d/reply/" % (post.id, comment.id), data={"comment": "hello"})

            assert len(outbox) == 0

        assert Comment.query.count() == 2

        reply = Comment.query.filter(Comment.parent_id == comment.id).first()

        assert reply.comment == "hello"

        self.assert_redirects(response, reply.url)

        # another user

        user2 = User(username="******", email="*****@*****.**", password="******")

        db.session.add(user2)
        db.session.commit()

        self.login(login="******", password="******")

        with mail.record_messages() as outbox:
            response = self.client.post("/post/%d/addcomment/" % post.id, data={"comment": "testing"})

            assert len(outbox) == 0

        user.email_alerts = True
        db.session.add(user)
        db.session.commit()

        assert User.query.filter(User.email_alerts == True).count() == 1

        with mail.record_messages() as outbox:
            response = self.client.post("/post/%d/addcomment/" % post.id, data={"comment": "testing"})

            assert len(outbox) == 1

        with mail.record_messages() as outbox:
            response = self.client.post("/post/%d/%d/reply/" % (post.id, comment.id), data={"comment": "testing"})

            assert len(outbox) == 1

        # double check author doesn't receive own emails

        self.login(login="******", password="******")

        with mail.record_messages() as outbox:
            response = self.client.post("/post/%d/%d/reply/" % (post.id, comment.id), data={"comment": "hello"})

            assert len(outbox) == 0
Beispiel #2
0
    def test_add_comment(self):

        response = self.client.get("/post/1/addcomment/")
        self.assert_401(response)

        user = User(username="******",
                    email="*****@*****.**",
                    password="******")

        db.session.add(user)
        db.session.commit()

        self.login(login="******", password="******")

        response = self.client.get("/post/1/addcomment/")
        self.assert_404(response)

        post = Post(author=user,
                    title="test",
                    link="http://reddit.com")

        db.session.add(post)
        db.session.commit()
        

        response = self.client.get("/post/%d/addcomment/" % post.id)
        self.assert_200(response)

        response = self.client.get("/post/%d/1/reply/" % post.id)

        with mail.record_messages() as outbox:
            response = self.client.post("/post/%d/addcomment/" % post.id,
                data={"comment" : "testing"})
        
            assert len(outbox) == 0

        comment = Comment.query.first()

        self.assert_redirects(response, comment.url)

        # reply to this comment

        response = self.client.get("/post/%d/%d/reply/" % (post.id, comment.id))

        self.assert_200(response)
        
        with mail.record_messages() as outbox:
            response = self.client.post("/post/%d/%d/reply/" % (
                post.id, comment.id), data={'comment':'hello'})

            assert len(outbox) == 0

        assert Comment.query.count() == 2

        reply = Comment.query.filter(
            Comment.parent_id==comment.id).first()

        assert reply.comment == "hello"

        self.assert_redirects(response, reply.url)


        # another user

        user2 = User(username="******",
                     email="*****@*****.**",
                     password="******")

        db.session.add(user2)
        db.session.commit()

        self.login(login="******", password="******")

        with mail.record_messages() as outbox:
            response = self.client.post("/post/%d/addcomment/" % post.id,
                data={"comment" : "testing"})
        
            assert len(outbox) == 0

        user.email_alerts = True
        db.session.add(user)
        db.session.commit()

        assert User.query.filter(User.email_alerts==True).count() == 1

        with mail.record_messages() as outbox:
            response = self.client.post("/post/%d/addcomment/" % post.id,
                data={"comment" : "testing"})
        
            assert len(outbox) == 1


        with mail.record_messages() as outbox:
            response = self.client.post(
                "/post/%d/%d/reply/" % (post.id, comment.id),
                data={"comment" : "testing"})
        
            assert len(outbox) == 1

        # double check author doesn't receive own emails

        self.login(login="******", password="******")

        with mail.record_messages() as outbox:
            response = self.client.post("/post/%d/%d/reply/" % (
                post.id, comment.id), data={'comment':'hello'})

            assert len(outbox) == 0