Exemple #1
0
class test_commentModel(unittest.TestCase):

    # to test behaivours in the comment model

    def setUp(self):
        self.user_Me = User( username = '******', password = '******', email = '*****@*****.**')
        self.new_post = Post(title = 'test', content = 'testing is important',user_id =  1, category = 'music',author='eve')
        self.new_comment =  Comment(name='name', email= '*****@*****.**',content="content", post_id = 1)

    def test_check_instance_variables(self):
        self.assertEquals(self.new_comment.name, 'name')
        self.assertEquals(self.new_comment.email, '*****@*****.**' )
        self.assertEquals(self.new_comment.content, 'content')
        self.assertEquals(self.new_comment.post_id, 1)
       

    def tearDown(self):
        Comment.query.delete()
        Post.query.delete()
    
    def test_save_Comment(self):
        self.new_comment.save_comment()
        self.assertTrue(len(Comment.query.all()),1)

    def test_delete_Comment(self):
        self.new_comment.delete_comment()
        self.assertTrue(len(Comment.query.all()),0)
Exemple #2
0
class test_comment(unittest.TestCase):
    def setUp(self):
        self.new_user = User(username='******',
                             email='*****@*****.**',
                             password='******')
        self.new_comment = Comment(title='Great', body='Even greater')

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

    def test_instance(self):

        self.assertTrue(isinstance(self.new_comment, Comment))

    def test_save_comment(self):

        self.new_comment.save_comment()
        self.assertEqual(len(Comment.query.all()), 1)

    def test_delete_comment(self):

        self.new_comment.save_comment()
        self.assertEqual(len(Comment.query.all()), 1)
        self.new_comment.delete_comment()
        self.assertEqual(len(Comment.query.all()), 0)
Exemple #3
0
class TestComment(unittest.TestCase):
    """
    Class for testing User properties and methods. Inherits from unittest.TestCase
    """
    def setUp(self):
        """
        Runs before each test
        """
        db.create_all()

        self.blogpost = Blogpost(title="How to Start a Blog")
        self.comment = Comment(full_name="Jane Doe", email = "*****@*****.**", comment="Can't wait to start my own!", blogpost_id = 1)

        db.session.add_all([self.blogpost, self.comment])
        db.session.commit()

    def tearDown(self):
        """
        Runs after each test
        """
        db.session.commit()
        db.drop_all()

    def test_comment_instance(self):
        """
        Class to check if instance of Subscriber is created and committed to database
        """
        comment = Comment.query.first()

        self.assertEqual(comment.full_name, "Jane Doe")
        self.assertEqual(comment.email, "*****@*****.**")
        self.assertEqual(comment.comment, "Can't wait to start my own!")
        self.assertEqual(comment.blogpost_id, 1)



    def test_delete_comment(self):
        """
        Test to check if delete_comment method removes comment from database
        """

        self.comment.delete_comment()

        self.assertFalse(Comment.query.first())
Exemple #4
0
class test_commentModel(unittest.TestCase):

    # to test behaivours in the comment model

    def setUp(self, User):
        self.user_Me = User(firstname='Herrm',
                            secondname='Mere',
                            username='******',
                            password='******',
                            email='*****@*****.**')
        self.new_post = Post(title='test',
                             content='testing is important',
                             user_id=1,
                             category='interview',
                             author='Me')
        self.new_comment = Comment(name='name',
                                   email='*****@*****.**',
                                   content="content",
                                   post_id=1)

    def test_check_instance_variables(self):
        self.assertEquals(self.new_comment.name, 'name')
        self.assertEquals(self.new_comment.email, '*****@*****.**')
        self.assertEquals(self.new_comment.content, 'content')
        self.assertEquals(self.new_comment.post_id, 1)

    def tearDown(self):
        Comment.query.delete()
        Post.query.delete()

    def test_save_Comment(self):
        self.new_comment.save_comment()
        self.assertTrue(len(Comment.query.all()), 1)

    def test_delete_Comment(self):
        self.new_comment.delete_comment()
        self.assertTrue(len(Comment.query.all()), 0)