'Test that the LibraryContent block\'s \'refresh_children\' handler will correctly
handle permissions and allow/refuse when updating its content with the latest
version of a library. We try updating from a library with (write, read, or no)
access to a course with (write or no) access.'

@ddt.data((LibraryUserRole, CourseStaffRole, True), (CourseStaffRole, CourseStaffRole, True), (None, CourseStaffRole, False), (LibraryUserRole, None, False))
@ddt.unpack
def test_refresh_library_content_permissions(self, library_role, course_role, expected_result):

    self._add_simple_content_block()
    with modulestore().default_store(ModuleStoreEnum.Type.split):
        course = CourseFactory.create()
    self._login_as_non_staff_user()
    if library_role:
        library_role(self.lib_key).add_users(self.non_staff_user)
    if course_role:
        course_role(course.location.course_key).add_users(self.non_staff_user)
    lc_block = self._add_library_content_block(course, self.lib_key)
    self._bind_module(lc_block, user=self.non_staff_user)
    lc_block = self._refresh_children(lc_block, status_code_expected=(200 if expected_result else 403))
    self.assertEqual(len(lc_block.children), (1 if expected_result else 0))
