Skip to content

test: add tests for Canvas Integration plugin#790

Open
arslanashraf7 wants to merge 1 commit into
mainfrom
arslan/8200-add-canvas-integration-tests
Open

test: add tests for Canvas Integration plugin#790
arslanashraf7 wants to merge 1 commit 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.

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.

2 participants