def test_get_posts(self): # prepare 20 posts: category = model.create_category('get_all') _create_post(20, _create_user(), 'test', 'abc', category) # get first 5: test-0, ..., test-4 posts, cursor = model.get_posts(5) self.assertEquals(['test-%d' % d for d in range(5)], [str(p.title) for p in posts]) # get next 10: test-5, ..., test-14: posts, cursor = model.get_posts(10, cursor) self.assertEquals(['test-%d' % d for d in range(5, 15)], [str(p.title) for p in posts]) # get next 5: test-15, ..., test-19: posts, cursor = model.get_posts(10, cursor) self.assertEquals(['test-%d' % d for d in range(15, 20)], [str(p.title) for p in posts])
def __get_post_list(user, context): category = None cat = context.get_argument('category', '') if cat: category = model.get_category(cat) offset = context.get_argument('offset', '') if not offset: offset = None index = 1 if offset: index = int(context.get_argument('index')) categories = model.get_categories() ref = None if user.role >= store.ROLE_AUTHOR: ref = user.id ps, next_cursor = model.get_posts(5, offset, ref, category, published_only=False) return { '__view__' : 'manage_post_list', 'static' : False, 'ps' : ps, 'category' : cat, 'categories' : categories, 'offset' : offset, 'next' : next_cursor, 'index' : index, }
def __get_post_list(user, context): category = None cat = context.get_argument('category', '') if cat: category = model.get_category(cat) offset = context.get_argument('offset', '') if not offset: offset = None index = 1 if offset: index = int(context.get_argument('index')) categories = model.get_categories() ref = None if user.role >= store.ROLE_AUTHOR: ref = user.id ps, next_cursor = model.get_posts(5, offset, ref, category, published_only=False) return { '__view__': 'manage_post_list', 'static': False, 'ps': ps, 'category': cat, 'categories': categories, 'offset': offset, 'next': next_cursor, 'index': index, }
def get_all_public_posts(**kw): ''' show all public posts of blog ''' ctx = kw['context'] number = 20 index = ctx.get_argument('index', '') if index: index = int(index) else: index = 1 offset = ctx.get_argument('offset', '') if not offset: offset = None posts, next = model.get_posts(number, offset) return { '__theme__': True, '__view__': 'posts', '__title__': 'All posts', '__header__': blog.get_feed_html(), 'posts': posts, 'index': index, 'next': next, 'offset': offset, }
def get_all_public_posts(**kw): ''' show all public posts of blog ''' ctx = kw['context'] number = 20 index = ctx.get_argument('index', '') if index: index = int(index) else: index = 1 offset = ctx.get_argument('offset', '') if not offset: offset = None posts, next = model.get_posts(number, offset) return { '__theme__' : True, '__view__' : 'posts', '__title__' : 'All posts', '__header__' : blog.get_feed_html(), 'posts' : posts, 'index' : index, 'next' : next, 'offset' : offset, }
def test_get_posts_by_category(self): # prepare 20 posts: python = model.create_category('python') java = model.create_category('java') user = _create_user() _create_post(10, user, 'python test', 'this is a python test', python) _create_post(10, user, 'java test', 'this is a java test', java) ps, cursor = model.get_posts(category=python) self.assertEquals(10, len(ps)) self.assertEquals(None, cursor)
def index(**kw): ''' show recent posts of blog ''' ctx = kw['context'] number = 20 posts, next = blog_model.get_posts(number, None) return { '__theme__' : True, '__view__' : 'index', '__title__' : 'Home', '__header__' : blog.get_feed_html(), 'posts' : posts, }
def feed(**kw): ''' Generate rss feed. ''' host = kw['request'].host_url options = store.get_settings(blog.GROUP_OPTIONS) blog.update_default_settings(options) title = options[blog.FEED_TITLE] description = 'Subscribe RSS feed' hub = 'http://pubsubhubbub.appspot.com' link = options[blog.FEED_PROXY] or ('%s/blog/feed' % host) max = int(options[blog.FEED_ITEMS]) posts, cursor = model.get_posts(limit=max) response = kw['response'] response.content_type = 'application/rss+xml' response.charset = 'utf8' out = response.out out.write(r'''<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"> <channel> <atom:link rel="hub" href="%s"/> <title>%s</title> <link>%s</link> <description>%s</description> <generator>expressme.org</generator> <language>en</language>''' % (hub, title, link, description)) for post in posts: out.write(r''' <item> <title>%s</title> <link>%s/blog/post/%s</link> <dc:creator>%s</dc:creator> <pubDate>%s</pubDate> <description><![CDATA[%s]]></description> </item>''' % ( post.title, host, post.id, post.author, post.creation_date.strftime('%a, %d %b %Y %H:%M:%S'), post.content )) out.write(r''' </channel> </rss> ''')
def feed(**kw): ''' Generate rss feed. ''' host = kw['request'].host_url options = store.get_settings(blog.GROUP_OPTIONS) blog.update_default_settings(options) title = options[blog.FEED_TITLE] description = 'Subscribe RSS feed' hub = 'http://pubsubhubbub.appspot.com' link = options[blog.FEED_PROXY] or ('%s/blog/feed' % host) max = int(options[blog.FEED_ITEMS]) posts, cursor = model.get_posts(limit=max) response = kw['response'] response.content_type = 'application/rss+xml' response.charset = 'utf8' out = response.out out.write(r'''<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"> <channel> <atom:link rel="hub" href="%s"/> <title>%s</title> <link>%s</link> <description>%s</description> <generator>expressme.org</generator> <language>en</language>''' % (hub, title, link, description)) for post in posts: out.write(r''' <item> <title>%s</title> <link>%s/blog/post/%s</link> <dc:creator>%s</dc:creator> <pubDate>%s</pubDate> <description><![CDATA[%s]]></description> </item>''' % (post.title, host, post.id, post.author, post.creation_date.strftime('%a, %d %b %Y %H:%M:%S'), post.content)) out.write(r''' </channel> </rss> ''')
def get_posts_by_category(cat_key, **kw): ctx = kw['context'] category = model.get_category(cat_key) number = 20 offset = ctx.get_argument('offset', '') if not offset: offset = None index = ctx.get_argument('index', '') if index: index = int(index) else: index = 1 posts, next = model.get_posts(number, offset, category=category) return { '__theme__': True, '__view__': 'posts', '__title__': 'Posts of %s' % category.name, '__header__': blog.get_feed_html(), 'category': category, 'posts': posts, 'index': index, 'next': next, 'offset': offset, }
def get_posts_by_category(cat_key, **kw): ctx = kw['context'] category = model.get_category(cat_key) number = 20 offset = ctx.get_argument('offset', '') if not offset: offset = None index = ctx.get_argument('index', '') if index: index = int(index) else: index = 1 posts, next = model.get_posts(number, offset, category=category) return { '__theme__' : True, '__view__' : 'posts', '__title__' : 'Posts of %s' % category.name, '__header__' : blog.get_feed_html(), 'category' : category, 'posts' : posts, 'index' : index, 'next' : next, 'offset' : offset, }
def test_get_posts(self, get_db_mock): mock_db = get_db_mock() result = model.get_posts() self.assertTrue(mock_db.select.called)