示例#1
0
    def test_get_posts_pagination_sizes(self):
        """Ensure get_posts works with various pagination sizes"""
        user1 = create_account('user1', '*****@*****.**', 'Password')

        # Create loads of posts
        for i in xrange(100):
            create_post(user1, 'user1', 'Test post {}'.format(i))

        FEED_ITEMS_PER_PAGE = app.config.get('FEED_ITEMS_PER_PAGE')

        self.assertEqual(len(get_posts(user1).items), FEED_ITEMS_PER_PAGE)
        self.assertEqual(len(get_posts(user1, per_page=25).items), 25)
        self.assertEqual(len(get_posts(user1, per_page=50).items), 50)
        self.assertEqual(len(get_posts(user1, per_page=100).items), 100)
示例#2
0
    def test_get_posts_pagination_sizes(self):
        """Ensure get_posts works with various pagination sizes"""
        user1 = create_account('user1', '*****@*****.**', 'Password')

        # Create loads of posts
        for i in xrange(100):
            create_post(user1, 'user1', 'Test post {}'.format(i))

        FEED_ITEMS_PER_PAGE = app.config.get('FEED_ITEMS_PER_PAGE')

        self.assertEqual(len(get_posts(user1).items), FEED_ITEMS_PER_PAGE)
        self.assertEqual(len(get_posts(user1, per_page=25).items), 25)
        self.assertEqual(len(get_posts(user1, per_page=50).items), 50)
        self.assertEqual(len(get_posts(user1, per_page=100).items), 100)
示例#3
0
    def test_get_posts(self):
        """
        Test users post list works correctly
        """
        # Create test user
        user1 = create_account('user1', '*****@*****.**', 'Password')
        # Ensure the users post list is empty
        self.assertEqual(len(get_posts(user1).items), 0)

        # Create a few test posts, ensure they appears in the users list
        post1 = create_post(user1, 'user1', 'Test post 1')
        post2 = create_post(user1, 'user1', 'Test post 2')
        create_post(user1, 'user1', 'Test post 3')
        self.assertEqual(len(get_posts(user1).items), 3)
        self.assertEqual(get_posts(user1).total, 3)

        # Delete one of the posts and ensure that it does not appear in the
        # list.
        delete_post(post1)

        # Ensure the above is now correct with post1 missing
        self.assertEqual(len(get_posts(user1).items), 2)
        self.assertEqual(get_posts(user1).total, 2)

        # Delete a post from MongoDB with the driver
        m.db.posts.remove({'_id': post2})
        # Ensure the above is now correct with post2 missing
        self.assertEqual(len(get_posts(user1).items), 1)
        self.assertEqual(get_posts(user1).total, 1)
示例#4
0
    def test_get_posts(self):
        """
        Test users post list works correctly
        """
        # Create test user
        user1 = create_account('user1', '*****@*****.**', 'Password')
        # Ensure the users post list is empty
        self.assertEqual(len(get_posts(user1).items), 0)

        # Create a few test posts, ensure they appears in the users list
        post1 = create_post(user1, 'user1', 'Test post 1')
        post2 = create_post(user1, 'user1', 'Test post 2')
        create_post(user1, 'user1', 'Test post 3')
        self.assertEqual(len(get_posts(user1).items), 3)
        self.assertEqual(get_posts(user1).total, 3)

        # Delete one of the posts and ensure that it does not appear in the
        # list.
        delete_post(post1)

        # Ensure the above is now correct with post1 missing
        self.assertEqual(len(get_posts(user1).items), 2)
        self.assertEqual(get_posts(user1).total, 2)

        # Delete a post from MongoDB with the driver
        m.db.posts.remove({'_id': post2})
        # Ensure the above is now correct with post2 missing
        self.assertEqual(len(get_posts(user1).items), 1)
        self.assertEqual(get_posts(user1).total, 1)
示例#5
0
文件: views.py 项目: hnk/pjuu
def profile(username):
    """It will show the users posts. Referred to as "posts" on the site."""
    uid = get_uid_username(username)

    if uid is None:
        abort(404)

    # Data
    _profile = get_profile(uid)

    # Pagination
    page = handle_page(request)
    # Get the posts pagination
    pagination = get_posts(uid, page)

    # Post form
    post_form = PostForm()
    return render_template('posts.html', profile=_profile,
                           pagination=pagination, post_form=post_form)
示例#6
0
def profile(username):
    """It will show the users posts. Referred to as "posts" on the site.

    .. note: Viewable to public! (Only public posts)
    """
    uid = get_uid_username(username)

    if uid is None:
        abort(404)

    # Data
    _profile = get_profile(uid)

    # Pagination
    page = handle_page(request)

    # Get the page sizes taking in to account non-logged in users
    if current_user:
        page_size = current_user.get('feed_pagination_size',
                                     app.config.get('FEED_ITEMS_PER_PAGE', 25))
    else:
        page_size = app.config.get('FEED_ITEMS_PER_PAGE', 25)

    # Get the posts pagination
    if current_user:
        current_user_id = current_user.get('_id')
    else:
        current_user_id = None
    permission = get_user_permission(_profile.get('_id'), current_user_id)

    _posts = get_posts(uid, page, page_size, perm=permission)

    # Post form
    post_form = PostForm()
    return render_template('posts.html',
                           profile=_profile,
                           pagination=_posts,
                           post_form=post_form)
示例#7
0
文件: views.py 项目: pjuu/pjuu
def profile(username):
    """It will show the users posts. Referred to as "posts" on the site.

    .. note: Viewable to public! (Only public posts)
    """
    uid = get_uid_username(username)

    if uid is None:
        abort(404)

    # Data
    _profile = get_profile(uid)

    # Pagination
    page = handle_page(request)

    # Get the page sizes taking in to account non-logged in users
    if current_user:
        page_size = current_user.get('feed_pagination_size',
                                     app.config.get('FEED_ITEMS_PER_PAGE', 25))
    else:
        page_size = app.config.get('FEED_ITEMS_PER_PAGE', 25)

    # Get the posts pagination
    if current_user:
        current_user_id = current_user.get('_id')
    else:
        current_user_id = None
    permission = get_user_permission(_profile.get('_id'), current_user_id)

    _posts = get_posts(uid, page, page_size, perm=permission)

    # Post form
    post_form = PostForm()
    return render_template('posts.html', profile=_profile,
                           pagination=_posts, post_form=post_form)