diff --git a/lms/product/canvas/_plugin/course_copy.py b/lms/product/canvas/_plugin/course_copy.py index 1eeb517075..a36aedf253 100644 --- a/lms/product/canvas/_plugin/course_copy.py +++ b/lms/product/canvas/_plugin/course_copy.py @@ -5,6 +5,7 @@ class CanvasCourseCopyPlugin: """Handle course copy in Canvas.""" file_type = "canvas_file" + page_type = "canvas_page" def __init__(self, api, file_service, files_helper: CourseCopyFilesHelper): self._api = api @@ -28,7 +29,7 @@ def find_matching_file_in_course(self, course_id, file_ids): _ = self._api.list_files(course_id) for file_id in file_ids: - file = self._file_service.get(file_id, type_="canvas_file") + file = self._file_service.get(file_id, type_=self.file_type) if not file: continue @@ -38,6 +39,11 @@ def find_matching_file_in_course(self, course_id, file_ids): return None + def find_matching_page_in_course(self, original_page_id, new_course_id): + return self._files_helper.find_matching_file_in_course( + self._api.pages.list, self.page_type, original_page_id, new_course_id + ) + def find_matching_group_set_in_course(self, _course, _group_set_id): # We are not yet handling course copy for groups in Canvas. # Canvas doesn't copy group sets during course copy so the approach taken diff --git a/lms/product/plugin/course_copy.py b/lms/product/plugin/course_copy.py index 1807664ca6..834af140e8 100644 --- a/lms/product/plugin/course_copy.py +++ b/lms/product/plugin/course_copy.py @@ -131,3 +131,6 @@ def find_matching_file_in_course(self, original_file_id, new_course_id): def find_matching_group_set_in_course(self, _course, group_set_id): raise NotImplementedError() + + def find_matching_page_in_course(self, original_file_id, new_course_id): + raise NotImplementedError() diff --git a/tests/unit/lms/product/canvas/_plugin/course_copy_test.py b/tests/unit/lms/product/canvas/_plugin/course_copy_test.py index 4390b974ce..aa8e8eb983 100644 --- a/tests/unit/lms/product/canvas/_plugin/course_copy_test.py +++ b/tests/unit/lms/product/canvas/_plugin/course_copy_test.py @@ -94,6 +94,24 @@ def test_find_matching_file_in_course_returns_None_if_theres_no_match( sentinel.course_id, [sentinel.file_id] ) + def test_find_matching_page_in_course( + self, plugin, course_copy_files_helper, canvas_api_client + ): + result = plugin.find_matching_page_in_course( + sentinel.page_id, sentinel.course_id + ) + + course_copy_files_helper.find_matching_file_in_course.assert_called_once_with( + canvas_api_client.pages.list, + "canvas_page", + sentinel.page_id, + sentinel.course_id, + ) + + assert ( + result == course_copy_files_helper.find_matching_file_in_course.return_value + ) + @pytest.mark.usefixtures( "canvas_api_client", "file_service", "course_copy_files_helper" )