Skip to content

Commit d5e92db

Browse files
committed
fixup! feat: add support for optional Canvas due date syncing
1 parent 049c698 commit d5e92db

2 files changed

Lines changed: 37 additions & 10 deletions

File tree

src/ol_openedx_canvas_integration/ol_openedx_canvas_integration/cms_tasks.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,33 @@ def sync_course_assignments_with_canvas(course_id):
187187

188188
@shared_task
189189
def sync_canvas_due_dates(course_id: str):
190+
"""
191+
Synchronizes due dates for a specified course with the Canvas platform.
192+
193+
This task is a wrapper around the `_sync_canvas_due_dates` function, which performs the actual
194+
synchronization of assignment due dates from Canvas to the platform.
195+
196+
Parameters:
197+
course_id (str): The unique identifier of the course whose due
198+
dates need to be synchronized.
199+
"""
190200
_sync_canvas_due_dates(course_id)
191201

192202

193203
def _sync_canvas_due_dates(course_id: str):
204+
"""
205+
Synchronize assignment due dates from Canvas to a specific course in the platform.
206+
207+
This function retrieves assignment due dates from Canvas associated with a given course
208+
and updates the platform's course content accordingly. The function skips synchronization
209+
if the course has no Canvas ID or if using Canvas due dates is disabled for the course.
210+
211+
Arguments:
212+
course_id (str): The unique identifier of the course whose due dates are to be synchronized.
213+
214+
Raises:
215+
Various exceptions during retrieval or update operations are logged but not raised.
216+
"""
194217
course_key = CourseKey.from_string(course_id)
195218
course = get_course_by_id(course_key)
196219
canvas_course_id = get_canvas_course_id(course)

src/ol_openedx_canvas_integration/tests/test_cms_tasks.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,17 @@ def create_course(self, other_course_settings:dict|None=None):
154154
)
155155
def test_sync_canvas_due_dates_no_canvas_id(self, other_course_settings):
156156
course, _ = self.create_course(other_course_settings)
157+
canvas_client_mock = MagicMock()
158+
157159
with (
158-
patch("ol_openedx_canvas_integration.cms_tasks.TASK_LOG") as mocked_log,
160+
patch(
161+
"ol_openedx_canvas_integration.cms_tasks.CanvasClient",
162+
return_value=canvas_client_mock,
163+
),
159164
):
160165
_sync_canvas_due_dates(str(course.id))
161166

162-
mocked_log.info.assert_called_with(
163-
"Due Date Sync: No canvas ID. Skipped for course %s",
164-
str(course.id),
165-
)
167+
canvas_client_mock.get_canvas_assignments.assert_not_called()
166168

167169
@ddt.data(
168170
{},
@@ -173,15 +175,17 @@ def test_sync_canvas_due_dates_due_dates_disabled(self, other_course_settings):
173175
"canvas_id": 11,
174176
**other_course_settings,
175177
})
178+
canvas_client_mock = MagicMock()
179+
176180
with (
177-
patch("ol_openedx_canvas_integration.cms_tasks.TASK_LOG") as mocked_log,
181+
patch(
182+
"ol_openedx_canvas_integration.cms_tasks.CanvasClient",
183+
return_value=canvas_client_mock,
184+
),
178185
):
179186
_sync_canvas_due_dates(str(course.id))
180187

181-
mocked_log.info.assert_called_with(
182-
"Due Date Sync: Disabled. Skipped for course %s",
183-
str(course.id),
184-
)
188+
canvas_client_mock.get_canvas_assignments.assert_not_called()
185189

186190

187191
def test_sync_canvas_due_dates_updates_due_dates(self):

0 commit comments

Comments
 (0)