示例#1
0
 def test_continue_url(self):
     post = Post(status=PostStatus.published, slug='test-post')
     self.assertEqual(post.continue_url, None)
     post.pub_date = datetime.date(2012, 4, 3)
     expected = '/blog/2012/04/03/test-post#{}'.format(
         self.app.config['POST_CONTINUE_LINK_FRAGMENT'])
     self.assertEqual(post.continue_url, expected)
示例#2
0
    def create_post(self, user, commit=True, **kwargs):
        default_fields = {
            'author': user,
            'title': u'My First Post',
            'slug': u'my-first-post',
            'body': u'Post body'
        }
        default_fields.update(kwargs)
        post = Post(**default_fields)

        if post.status == PostStatus.published and post.pub_date is None:
            post.pub_date = utc_now()

        db.session.add(post)
        if commit:
            db.session.commit()
        return post
示例#3
0
    def create_post(self, create_user=True, **kwargs):
        post_data = {
            'title': 'First Tiger on the Moon',
            'slug': 'first-tiger-moon',
            'body': 'The contents.'
        }

        if 'author' not in kwargs:
            user = User(email='*****@*****.**', short_name='Ryan')
            db.session.add(user)
            post_data['author'] = user

        post_data.update(kwargs)
        post = Post(**post_data)

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

        return post
示例#4
0
def add_post():
    form = PostForm(request.form)

    if form.validate_on_submit():
        status = PostStatus.from_string(form.status.data)

        post = Post(author=current_user,
                    title=form.title.data,
                    slug=form.slug.data,
                    body=form.body.data,
                    status=status,
                    tags=form.tags.data)

        if status == PostStatus.published:
            post.pub_date = utc_now()

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

        message = u'Post "{}" successfully added.'.format(form.title.data)
        flash(message, 'success')
        return redirect(url_for('.view_posts'))

    return render_template('blog/post_add.html', form=form)
示例#5
0
    def test_preview(self):
        post = Post(body=u'test <!-- preview -->')
        self.assertEqual(post.preview, u'test...')

        post = Post(body=u'test ')
        self.assertEqual(post.preview, u'test')
示例#6
0
 def test_url(self):
     post = Post(status=PostStatus.published, slug='test-post')
     self.assertEqual(post.url, None)
     post.pub_date = datetime.date(2012, 4, 3)
     self.assertEqual(post.url, '/blog/2012/04/03/test-post')
示例#7
0
 def test_is_published(self):
     post = Post(status=PostStatus.published)
     self.assertTrue(post.is_published)
示例#8
0
 def test_post_tags_converted_to_comma_separated_string(self):
     post = Post(tags=[Tag('green'), Tag('blue')])
     form = PostForm(obj=post)
     self.assertEqual(form.tags._value(), 'green, blue')