Skip to content

Commit

Permalink
Add new method for finding copied pages
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Oct 20, 2023
1 parent 1a26d56 commit cc7a4c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lms/product/canvas/_plugin/course_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lms/product/plugin/course_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
18 changes: 18 additions & 0 deletions tests/unit/lms/product/canvas/_plugin/course_copy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit cc7a4c8

Please sign in to comment.