<reponame>3xistentialcrisis/Blog
import unittest
from app.models import Comment, Blog, User
from app import db


class CommentModelTest(unittest.TestCase):
    def setUp(self):
        self.new_comment = Comment(id=1, comment='Test comment', user=self.user_karanja, blog_id=self.new_blog)

    def tearDown(self):
        Blog.query.delete()
        User.query.delete()

    def test_check_instance_variables(self):
        self.assertEquals(self.new_comment.comment, 'Test comment')
        self.assertEquals(self.new_comment.user, self.user_karanja)
        self.assertEquals(self.new_comment.blog_id, self.new_blog)


class CommentModelTest(unittest.TestCase):
    def setUp(self):
        self.user_ciku = User(username='ciku', password='<PASSWORD>', email='<EMAIL>')
        self.new_blog = Blog(id=1, title='Test', content='test blog', user_id=self.user_ciku.id)
        self.new_comment = Comment(id=1, comment='test comment', user_id=self.user_ciku.id,
                                   blog_id=self.new_blog.id)

    def tearDown(self):
        Blog.query.delete()
        User.query.delete()
        Comment.query.delete()

    def test_check_instance_variables(self):
        self.assertEquals(self.new_comment.comment, 'test comment')
        self.assertEquals(self.new_comment.user_id, self.user_ciku.id)
        self.assertEquals(self.new_comment.blog_id, self.new_blog.id)

    def test_save_comment(self):
        self.new_comment.save()
        self.assertTrue(len(Comment.query.all()) > 0)

    def test_get_comment(self):
        self.new_comment.save()
        got_comment = Comment.get_comment(1)
        self.assertTrue(got_comment is not None)
import unittest
from app.models import Comment, Blog, User
from app import db


class CommentModelTest(unittest.TestCase):
    def setUp(self):
        self.new_comment = Comment(id=1, comment='Test comment', user=self.user_karanja, blog_id=self.new_blog)

    def tearDown(self):
        Blog.query.delete()
        User.query.delete()

    def test_check_instance_variables(self):
        self.assertEquals(self.new_comment.comment, 'Test comment')
        self.assertEquals(self.new_comment.user, self.user_karanja)
        self.assertEquals(self.new_comment.blog_id, self.new_blog)


class CommentModelTest(unittest.TestCase):
    def setUp(self):
        self.user_ciku = User(username='ciku', password='<PASSWORD>', email='<EMAIL>')
        self.new_blog = Blog(id=1, title='Test', content='test blog', user_id=self.user_ciku.id)
        self.new_comment = Comment(id=1, comment='test comment', user_id=self.user_ciku.id,
                                   blog_id=self.new_blog.id)

    def tearDown(self):
        Blog.query.delete()
        User.query.delete()
        Comment.query.delete()

    def test_check_instance_variables(self):
        self.assertEquals(self.new_comment.comment, 'test comment')
        self.assertEquals(self.new_comment.user_id, self.user_ciku.id)
        self.assertEquals(self.new_comment.blog_id, self.new_blog.id)

    def test_save_comment(self):
        self.new_comment.save()
        self.assertTrue(len(Comment.query.all()) > 0)

    def test_get_comment(self):
        self.new_comment.save()
        got_comment = Comment.get_comment(1)
        self.assertTrue(got_comment is not None)