'Tests that the permissions queries are cached when rendering numerous discussion XBlocks.'

def test_permissions_query_load(self):

    user = UserFactory.create()
    course = ToyCourseFactory.create()
    course_key = course.id
    course_usage_key = self.store.make_course_usage_key(course_key)
    discussions = []
    for counter in range(5):
        discussion_id = 'test_discussion_{}'.format(counter)
        discussions.append(ItemFactory.create(parent_location=course_usage_key, category='discussion', discussion_id=discussion_id, discussion_category='Category    discussion', discussion_target='Target    Discussion'))
    num_queries = 3
    for discussion in discussions:
        discussion_xblock = get_module_for_descriptor_internal(user=user, descriptor=discussion, student_data=mock.Mock(name='student_data'), course_id=course.id, track_function=mock.Mock(name='track_function'), xqueue_callback_url_prefix=mock.Mock(name='xqueue_callback_url_prefix'), request_token='request_token')
        with self.assertNumQueries(num_queries):
            fragment = discussion_xblock.render('student_view')
        num_queries = 0
        html = fragment.content
        self.assertIn('data-user-create-comment="false"', html)
        self.assertIn('data-user-create-subcomment="false"', html)
