Exemple #1
0
 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)
Exemple #2
0
def _categories(user, app, context):
    btn = context.get_argument('btn', '')
    if btn=='add':
        # add category:
        if context.method=='get':
            return {
                    '__view__' : 'manage_category_editor',
                    'add' : True,
                    'category' : model.BlogCategory(name='Unamed', description=''),
            }
        name = context.get_argument('name')
        description = context.get_argument('description', '')
        model.create_category(name, description)
        return __get_category_list('Category "%s" created.' % name)

    if btn=='delete':
        if len(model.get_categories())==1:
            return __get_category_list(error='You cannot delete the only 1 category.')
        try:
            model.delete_category(context.get_argument('id'))
        except ApplicationError, e:
            return __get_category_list(error=e.message)
Exemple #3
0
 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])
Exemple #4
0
 def test_get_published_posts(self):
     # prepare 20 posts:
     category = model.create_category('get_pub')
     def _get_state(n):
         if n % 2==0:
             return model.POST_PUBLISHED
         return model.POST_DRAFT
     _create_post(20, _create_user(), 'test', 'abc', category, _get_state)
     # get first 5: test-0, test-2, test-4, test-6, test-8
     posts, cursor = model.get_published_posts(5)
     self.assertEquals(['test-%d' % d for d in range(0, 9, 2)], [str(p.title) for p in posts])
     # get next 5: test-10, test-12, test-14, test-16, test-18:
     posts, cursor = model.get_published_posts(10, cursor)
     self.assertEquals(['test-%d' % d for d in range(10, 19, 2)], [str(p.title) for p in posts])
Exemple #5
0
def _categories(user, app, context):
    btn = context.get_argument('btn', '')
    if btn == 'add':
        # add category:
        if context.method == 'get':
            return {
                '__view__': 'manage_category_editor',
                'add': True,
                'category': model.BlogCategory(name='Unamed', description=''),
            }
        name = context.get_argument('name')
        description = context.get_argument('description', '')
        model.create_category(name, description)
        return __get_category_list('Category "%s" created.' % name)

    if btn == 'delete':
        if len(model.get_categories()) == 1:
            return __get_category_list(
                error='You cannot delete the only 1 category.')
        try:
            model.delete_category(context.get_argument('id'))
        except ApplicationError, e:
            return __get_category_list(error=e.message)