示例#1
0
class PostsModelTest(unittest.TestCase):
    """
    """
    def setUp(self):
        self.user_James = User(username='******',
                               password='******',
                               email='*****@*****.**')
        self.new_post = Posts(title="You're testing",
                              blog='This the test of the century',
                              category="my-thoughts",
                              user=self.user_James)

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

    def test_check_instance_variables(self):
        self.assertEquals(self.new_post.title, "Youre testing")
        self.assertEquals(self.new_post.blog,
                          "This is the test of the century")
        self.assertEquals(self.new_post.category, "my-thoughts")
        self.assertEquals(self.new_post.user, self.user_James)

    def test_save_post(self):
        self.new_post.save_post()
        self.assertTrue(len(Posts.query.all()) > 0)
示例#2
0
class PitchModelTest(unittest.TestCase):
    def setUp(self):
        self.new_post = Posts(title="title", post="content")
        db.session.add(self.new_blog)
        db.session.commit()

    def tearDown(self):
        Posts.query.delete()
        db.session.commit()

    def test_save_blogs(self):
        self.new_post.save_post()
        self.assertTrue(len(Blog.query.all()) > 0)

    def test_check_instance_variables(self):
        self.assertEquals(self.new_blog.title, 'title')
        self.assertEquals(self.new_blog.post, 'content')
示例#3
0
class PostsModelTest(unittest.TestCase):

    def setUp(self):

        self.new_post = Posts(title='Terabyte', body='This is a new post',category='Technology')

    def test_instance(self):
        '''
        Test case to check if new_post is an instance of Posts class
        '''
        self.assertTrue( isinstance( self.new_post, Posts) )

    def test_save_post(self):
        '''
        Test case to check if a post is saved to the database
        '''
        self.new_post.save_post()

        self.assertTrue( len(Posts.query.all()) > 0 )
示例#4
0
def create_post():
    post_form = PostForm()
    user = current_user

    if user.user_type == 'Writer':
        if post_form.validate_on_submit():
            post = Posts(title=post_form.title.data,
                         category=post_form.category.data,
                         blog=post_form.post.data,
                         user=current_user)
            post.save_post()
            users = User.query.filter_by(user_type='User').all()
            for user in users:
                mail_message("New Post has arrived",
                             "email/new_post",
                             user.email,
                             user=user)
            return redirect(url_for('main.writer'))
    else:
        return "This page is for only writers"

    return render_template('createpost.html', post_form=post_form)
示例#5
0
class PostModelTest(unittest.TestCase):
    def setUp(self):
        self.user_denno = User(user_name="denno", password="******")
        self.new_post = Posts(title='a',
                              post='b',
                              category='d',
                              posts=self.user_denno)

    def test_instance(self):
        self.assertEqual(self.new_post.title, 'a')
        self.assertEqual(self.new_post.post, 'b')
        self.assertEqual(self.new_post.category, 'd')

    def test_save_post(self):
        self.new_post.save_post()
        self.assertTrue(len(Posts.query.all()) > 0)

    def test_get_post_by_id(self):

        self.new_post.save_post()
        got_post = Posts.get_post(1)
        self.assertTrue(len(got_post) > 0)