'Test that LibraryRoot.author_view can apply paging
We have to patch the runtime (module system) in order to be able to
render blocks in our test environment.'

def test_library_author_view_with_paging(self):

    library = LibraryFactory.create(modulestore=self.store)
    blocks = [ItemFactory.create(category='html', parent_location=library.location, user_id=self.user_id, publish_item=False, modulestore=self.store, data=('HtmlBlock' + str(i))) for i in range(5)]
    library = self.store.get_library(library.location.library_key)
    def render_and_check_contents(page, page_size):
        '    Renders    block    and    asserts    on    returned    content    '
        context = {'reorderable_items': set(), 'paging': {'page_number': page, 'page_size': page_size}}
        expected_blocks = blocks[(page_size * page):(page_size * (page + 1))]
        result = library.render(AUTHOR_VIEW, context)
        for expected_block in expected_blocks:
            self.assertIn(expected_block.data, result.content)
    render_and_check_contents(0, 3)
    render_and_check_contents(1, 3)
    render_and_check_contents(0, 2)
    render_and_check_contents(1, 2)
