Skip to content

test: add tests for Canvas Integration plugin#790

Open
arslanashraf7 wants to merge 2 commits into
mainfrom
arslan/8200-add-canvas-integration-tests
Open

test: add tests for Canvas Integration plugin#790
arslanashraf7 wants to merge 2 commits into
mainfrom
arslan/8200-add-canvas-integration-tests

Conversation

@arslanashraf7

@arslanashraf7 arslanashraf7 commented May 8, 2026

Copy link
Copy Markdown
Contributor

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_integration package. 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:

  • Added extensive unit tests for the api module, covering grade mapping, Canvas assignment creation/updating, and error handling for missing inputs.
  • Added comprehensive tests for the client module, including Canvas session handling, pagination, enrollment lookups, caching, assignment CRUD operations, and payload formatting.
  • Added tests for the context_api module, verifying resource loading and context section injection for Canvas integration.
  • Added tests for event handler functions to ensure proper task queuing logic for published and deleted XBlock events.
  • Added tests for signal receivers to confirm background grade sync tasks are triggered as expected.

Test Data Structure and File Organization Improvements:

  • Updated test fixtures in test_cms_tasks.py to use the correct assignment dictionary structure (mapping to dicts with id keys instead of plain ints) for consistency with production code. [1] [2]
  • Renamed and relocated test files for better organization and clarity, e.g., moving test_cms_tasks.py and test_settings.py to the main tests directory 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):

  • Desktop screenshots
  • Mobile width screenshots

How can this be tested?

  • Take a look at the plugin and make sure the new tests cover everything
  • Take a look at the tests/code
  • Make sure the ol-openedx-canvas-integration tests run run and CI is green

Additional Context

@arslanashraf7
arslanashraf7 force-pushed the arslan/8200-add-canvas-integration-tests branch from 5a52f91 to d50315e Compare May 14, 2026 10:52
@arslanashraf7 arslanashraf7 changed the title feat: add tests for Canvas Integration plugin test: add tests for Canvas Integration plugin May 14, 2026

@asadali145 asadali145 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just a couple of minor suggestions.

Comment on lines +73 to +81
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 {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicate of subsection mock in test_api. Maybe create test utils for such stuff?

return {"task_id": "test-task-id"}


class HashableUser:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, this can be merged with parametrizartion with other success tests below.

Copilot AI review requested due to automatic review settings July 22, 2026 15:42
@arslanashraf7
arslanashraf7 force-pushed the arslan/8200-add-canvas-integration-tests branch from d50315e to 751d832 Compare July 22, 2026 15:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +27 to +28
def test_handle_xblock_publised_event_queues_sync(monkeypatch):
"""Test that handle xblock publised event queues sync."""
Comment on lines +153 to +160
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 {}

Comment on lines +195 to +199
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
Comment on lines +300 to +306
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants