test: add tests for Canvas Integration plugin#790
Conversation
5a52f91 to
d50315e
Compare
asadali145
left a comment
There was a problem hiding this comment.
LGTM! Just a couple of minor suggestions.
| class MockSubsection: | ||
| """Minimal subsection object used for assignment payload generation tests.""" | ||
|
|
||
| def __init__(self, location, display_name, due=None): | ||
| """Initialize subsection location, name, and optional due date.""" | ||
| self.location = location | ||
| self.display_name = display_name | ||
| self.fields = {"due": due} if due else {} | ||
|
|
There was a problem hiding this comment.
This is duplicate of subsection mock in test_api. Maybe create test utils for such stuff?
| return {"task_id": "test-task-id"} | ||
|
|
||
|
|
||
| class HashableUser: |
There was a problem hiding this comment.
This and I think the above stub is also repeated.
| _call_view(view_func, request, course_id="") | ||
|
|
||
|
|
||
| def test_list_canvas_enrollments_raises_when_no_canvas_course_id(monkeypatch): |
There was a problem hiding this comment.
I think this can be merged using parametrization with test_list_canvas_assignments_raises_when_no_canvas_course_id and test_list_canvas_grades_raises_when_no_canvas_course_id like above test.
| _call_view(views.list_canvas_enrollments, request, course_id=course_key) | ||
|
|
||
|
|
||
| def test_list_canvas_enrollments_success(monkeypatch): |
There was a problem hiding this comment.
Same, this can be merged with parametrizartion with other success tests below.
d50315e to
751d832
Compare
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
This PR expands the ol_openedx_canvas_integration plugin’s automated test coverage by adding new unit tests across core modules (API/client/tasks/views/context/signals/handlers) and by aligning existing CMS-task fixtures with the production Canvas assignment map structure.
Changes:
- Added new pytest-based unit test modules covering API, Canvas client, context API injection, handlers, receivers, and task helper logic.
- Expanded existing view/task test modules with additional unit-level tests (primarily via monkeypatch/stubs).
- Updated CMS task test fixtures to match production expectations for Canvas assignment maps (values as dicts containing an
id).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ol_openedx_canvas_integration/tests/test_views.py | Adds many new unit tests for view helpers and Canvas-related endpoints. |
| src/ol_openedx_canvas_integration/tests/test_utils.py | New tests for small utility helpers (canvas course id + task output formatter). |
| src/ol_openedx_canvas_integration/tests/test_tasks.py | Adds unit tests for task submission helpers and grade-sync task behavior. |
| src/ol_openedx_canvas_integration/tests/test_task_helpers.py | New tests for task helper functions (progress updates and task filtering). |
| src/ol_openedx_canvas_integration/tests/test_settings.py | Adjusts test settings root path resolution after test file organization changes. |
| src/ol_openedx_canvas_integration/tests/test_receivers.py | New tests ensuring grade-update receiver queues background sync. |
| src/ol_openedx_canvas_integration/tests/test_handlers.py | New tests for XBlock published/deleted event handlers and queueing behavior. |
| src/ol_openedx_canvas_integration/tests/test_context_api.py | New tests for plugin context injection and resource loading. |
| src/ol_openedx_canvas_integration/tests/test_cms_tasks.py | Fixes fixture structure to match production diff_assignments expectations. |
| src/ol_openedx_canvas_integration/tests/test_client.py | New tests for Canvas client pagination, caching, endpoints, and payload helpers. |
| src/ol_openedx_canvas_integration/tests/test_api.py | New tests for API helpers (enrollment filtering, grade pushing, and input errors). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def test_handle_xblock_publised_event_queues_sync(monkeypatch): | ||
| """Test that handle xblock publised event queues sync.""" |
| class StubResponse: | ||
| """Simple response object stub used by view tests.""" | ||
|
|
||
| def __init__(self, status_code=200, data=None): | ||
| """Initialize response fields used by assertions.""" | ||
| self.status_code = status_code | ||
| self.data = data or {} | ||
|
|
| def test_get_edx_enrollment_data(has_user, has_allowed, is_enrolled_val, expected): | ||
| """Test that _get_edx_enrollment_data returns correct flags for all combos.""" | ||
| email = "test@example.com" | ||
| course_key = "course-v1:MITx+Demo+2026" | ||
| user = SimpleNamespace(id=100, email=email) if has_user else None |
| def test_run_sync_canvas_enrollments_submits_task(monkeypatch): | ||
| """Test that run sync canvas enrollments submits task.""" | ||
| request = SimpleNamespace() | ||
| course_key = "course-v1:MITx+Demo+2026" | ||
| canvas_course_id = 9999 | ||
| unenroll_current = True | ||
|
|
What are the relevant tickets?
https://github.com/mitodl/hq/issues/8200
This pull request introduces a comprehensive suite of new and improved tests for the
ol_openedx_canvas_integrationpackage. The changes focus on adding robust unit tests for the API, client, context API, handlers, and receivers modules. There are also some minor corrections and refactoring in test data structures and file organization. The overall goal is to ensure better coverage, reliability, and maintainability of the integration's core features.New and Improved Test Coverage:
apimodule, covering grade mapping, Canvas assignment creation/updating, and error handling for missing inputs.clientmodule, including Canvas session handling, pagination, enrollment lookups, caching, assignment CRUD operations, and payload formatting.context_apimodule, verifying resource loading and context section injection for Canvas integration.Test Data Structure and File Organization Improvements:
test_cms_tasks.pyto use the correct assignment dictionary structure (mapping to dicts withidkeys instead of plain ints) for consistency with production code. [1] [2]test_cms_tasks.pyandtest_settings.pyto the maintestsdirectory and updating path logic accordingly. [1] [2]These changes significantly improve the reliability of the integration by ensuring that core logic is well-tested and that test data structures match the expectations of the production code.
Description (What does it do?)
Screenshots (if appropriate):
How can this be tested?
Additional Context