Пример #1
0
def jsonify_blog_post(year, month, day):
    '''
    accept a blog post and retun a json object representing that blog post
    '''
    blog_post = fetch_blog_post(year, month, day)

    if not blog_post:
        data = {'error' : 'blog post does not exist'}
    else:
        title = re.search('[#].*\n', blog_post).group()
        author = re.search('author:.*\n', blog_post)
        if author:
            author = author.group()
            blog_post = re.sub(author, '', blog_post)
            author = re.sub('author:', '', author).strip('\n')
        else:
            author = 'Quentin Donnellan'

        blog_post = re.sub(title, '', blog_post).strip('\n')
        
        title = re.sub('[#]', '', title).strip('\n')
        data = {
            'year' : year,
            'day' : day, 
            'month' : month,
            'author' : author.strip(' '),
            'markdown' : blog_post,
            'html' : markdown(blog_post),
            'title' : title.strip(' '),
            'permalink' : 'http://qdonnellan.com/blog/%s/%s/%s' % (year, month, day),
            'api_reference' : '/api/blog/%s/%s/%s' % (year, month, day),
        }
    return json.dumps(data)
 def test_fetch_for_non_existing_blog_post(self):
     """
     test that a bad blog post id returns None
     """
     data = fetch_blog_post(2077, 12, 4)
     self.assertIsNone(data)
 def test_fetcH_for_existing_blog_post(self):
     """
     test that a request for an existing blog post returns that post
     """
     data = fetch_blog_post(2013, 3, 27)
     self.assertIsNotNone(data)
 def test_fetch_for_non_existing_blog_post(self):
     '''
     test that a bad blog post id returns None
     '''
     data = fetch_blog_post('2077', '12', '04')
     self.assertIsNone(data)
 def test_fetch_for_existing_blog_post(self):
     '''
     test that a request for an existing blog post returns that post
     '''
     data = fetch_blog_post('2013', '03', '27')
     self.assertIsNotNone(data)