'Test that the REST API will correctly allow/refuse when copying
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_duplicate_across_courses(self, library_role, course_role, expected_result):

    block = 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)
    response = self.client.ajax_post(reverse_url('xblock_handler'), {'parent_locator': unicode(course.location), 'duplicate_source_locator': unicode(block.location)})
    self.assertIn(response.status_code, (200, 403))
    duplicate_action_allowed = (response.status_code == 200)
    self.assertEqual(duplicate_action_allowed, expected_result)
