Skip to content

Commit

Permalink
Test post-page, demonstrates issue #12
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdavis committed May 25, 2013
1 parent 96291ac commit a4ddb54
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
5 changes: 5 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
from tornado.options import options as tornado_options
from tornado.testing import AsyncHTTPTestCase

# Patch Tornado with the Jade template loader
from tornado import template
from pyjade.ext.tornado import patch_tornado
patch_tornado()

sample_html = """
<h1>bar</h1>
<p>baz
Expand Down
28 changes: 23 additions & 5 deletions test/test_posts.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import datetime

from bs4 import BeautifulSoup
from tornado.options import options as tornado_options

from motor_blog.text import slugify
import test # Motor-Blog project's test/__init__.py.


class PostsTest(test.MotorBlogTest):
def test_new_post(self):
start = datetime.datetime.utcnow()
post_id = self.fetch_rpc(
def setUp(self):
super(PostsTest, self).setUp()
self.meta_description = 'description "with quotes" and \'single\''

def new_post(self):
"""Create a post and return its id"""
return self.fetch_rpc(
'metaWeblog.newPost',
(
1, # Blog id, always 1.
Expand All @@ -18,11 +23,14 @@ def test_new_post(self):
{
'mt_keywords': 'a tag,another tag',
'post_status': 'publish',
'mt_excerpt': 'the description',
'mt_excerpt': self.meta_description,
'title': 'the title',
'description': 'the body'},
True))

def test_new_post(self):
start = datetime.datetime.utcnow()
post_id = self.new_post()
end = datetime.datetime.utcnow()

post = self.fetch_rpc(
Expand All @@ -41,9 +49,19 @@ def test_new_post(self):
self.assertEqual('a tag,another tag', post['mt_keywords'])
self.assertEqual('publish', post['status'])
self.assertEqual('the title', post['title'])
self.assertEqual('the description', post['mt_excerpt'])
self.assertEqual(self.meta_description, post['mt_excerpt'])
self.assertEqual('the body', post['description']) # Confusing I know.
self.assertTrue(
start <= post['date_created_gmt'] <= end,
"Post's date_created_gmt %s isn't between %s and %s" % (
post['date_created_gmt'], start, end))

def test_post_page(self):
self.new_post()
title_slug = slugify.slugify('the title')
post_page = self.fetch(self.reverse_url('post', title_slug))
self.assertEqual(200, post_page.code)
soup = BeautifulSoup(post_page.body)
description_tag = soup.find('meta', attrs={'name': 'description'})
self.assertTrue(description_tag)
self.assertEqual(self.meta_description, description_tag['content'])

0 comments on commit a4ddb54

Please sign in to comment.