Skip to content

MPT-20438: Added endpoints and e2e tests for program enrollment attachments#320

Merged
robcsegal merged 1 commit intomainfrom
MPT-20438-add-endpoints-and-e-2-e-tests-for-program-enrollment-attachments
Apr 23, 2026
Merged

MPT-20438: Added endpoints and e2e tests for program enrollment attachments#320
robcsegal merged 1 commit intomainfrom
MPT-20438-add-endpoints-and-e-2-e-tests-for-program-enrollment-attachments

Conversation

@robcsegal
Copy link
Copy Markdown
Contributor

@robcsegal robcsegal commented Apr 22, 2026

This pull request adds support for program enrollment attachments in the API client, including synchronous and asynchronous service classes, a reusable attachment mixin, and comprehensive end-to-end and unit test coverage.

Enrollment Attachments Service Implementation:

  • Added EnrollmentAttachment model and EnrollmentAttachmentsService / AsyncEnrollmentAttachmentsService classes in mpt_api_client/resources/program/enrollments_attachments.py, supporting collection listing, get, create (file upload), update, delete, and download operations.
  • Introduced AttachmentMixin and AsyncAttachmentMixin in mpt_api_client/resources/program/mixins/attachment_mixin.py to compose file attachment operations for both sync and async services.

Integration with Enrollment Service:

  • Added .attachments(enrollment_id) method to EnrollmentService and AsyncEnrollmentService in mpt_api_client/resources/program/enrollments.py to expose the attachments sub-service.

Testing Enhancements:

  • Added end-to-end tests for both sync and async attachment flows in tests/e2e/program/enrollment/attachment/test_sync_attachment.py and test_async_attachment.py, covering upload, retrieval, listing, update, download, and deletion.
  • Created test fixtures for attachment data in tests/e2e/program/enrollment/attachment/conftest.py.
  • Added unit tests for EnrollmentAttachmentsService, AsyncEnrollmentAttachmentsService, and the attachment mixin in tests/unit/resources/program/test_enrollments_attachments.py and tests/unit/resources/program/mixin/test_attachment_mixin.py.

Configuration and Linting Updates:

  • Updated e2e_config.test.json with program.enrollment.attachment.id for E2E testing.
  • Extended flake8 linting configuration in pyproject.toml to ignore WPS235 for program resource files.

Closes MPT-20438

@robcsegal robcsegal requested a review from a team as a code owner April 22, 2026 21:11
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

📝 Walkthrough

Walkthrough

Introduces enrollment attachments functionality to the MPT API client, including a new EnrollmentAttachmentsService with sync/async variants, attachment mixins for CRUD and file operations, helper methods on EnrollmentService, comprehensive test coverage, and configuration updates.

Changes

Cohort / File(s) Summary
Core Resource Implementation
mpt_api_client/resources/program/enrollments_attachments.py, mpt_api_client/resources/program/mixins/attachment_mixin.py, mpt_api_client/resources/program/enrollments.py
Adds new EnrollmentAttachment model and EnrollmentAttachmentsService/AsyncEnrollmentAttachmentsService classes with CRUD and file transfer capabilities. Introduces generic AttachmentMixin and AsyncAttachmentMixin composing file and resource operations. Extends EnrollmentService/AsyncEnrollmentService with new attachments(enrollment_id) helper methods.
Configuration
e2e_config.test.json, pyproject.toml
Adds test configuration entry for enrollment attachment identifier; updates Flake8 per-file ignore rules to include WPS235 warning code for program resources.
E2E Tests
tests/e2e/program/enrollment/attachment/conftest.py, tests/e2e/program/enrollment/attachment/test_sync_attachment.py, tests/e2e/program/enrollment/attachment/test_async_attachment.py
Introduces pytest fixtures supplying attachment IDs and request payload factory. Adds comprehensive async and sync test suites validating attachment CRUD operations, retrieval by ID, pagination, filtering with RQLQuery, downloads, and error handling with graceful cleanup.
Unit Tests
tests/unit/resources/program/test_enrollments.py, tests/unit/resources/program/test_enrollments_attachments.py, tests/unit/resources/program/mixin/test_attachment_mixin.py
Extends enrollment tests to validate attachments() service property. Adds new module testing EnrollmentAttachmentsService path computation and method availability. Adds mixin tests verifying CRUD and file operation methods exist on attachment service instances.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Jira Issue Key In Title ✅ Passed PR title contains Jira issue key MPT-20438 in correct MPT-XXXX format.
Test Coverage Required ✅ Passed The PR modifies 3 code files and includes 6 test files covering the new functionality.
Single Commit Required ✅ Passed The PR contains exactly one commit (ef7e6db) encompassing all changes including enrollment attachments resources, mixins, tests, and configuration updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/e2e/program/enrollment/attachment/test_async_attachment.py (1)

85-90: Verify delete effect, not only request success.

The test currently calls delete but does not validate that the attachment is actually gone.

Suggested follow-up check
 async def test_delete_enrollment_attachment(enrollment_attachments, created_enrollment_attachment):
     result = created_enrollment_attachment

     await enrollment_attachments.delete(result.id)
+    with pytest.raises(MPTAPIError, match=r"404 Not Found"):
+        await enrollment_attachments.get(result.id)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/program/enrollment/attachment/test_async_attachment.py` around
lines 85 - 90, The test_delete_enrollment_attachment currently calls
enrollment_attachments.delete(result.id) but does not assert the deletion;
update the test to verify the effect by attempting to retrieve the deleted
attachment (e.g., call enrollment_attachments.get(result.id) or list
attachments) and assert the expected failure/absence (raise NotFound/404 or
returns None/does not appear in list). Ensure you reference the same result.id
from created_enrollment_attachment and handle the client’s specific
error/response semantics when asserting deletion.
tests/e2e/program/enrollment/attachment/test_sync_attachment.py (1)

33-37: Strengthen assertions to validate behavior, not just existence.

For core E2E paths, asserting specific fields (e.g., returned id, updated name/description) would catch more regressions than is not None checks alone.

Also applies to: 66-80

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/program/enrollment/attachment/test_sync_attachment.py` around lines
33 - 37, The current test only checks non-null result; strengthen assertions in
test_get_enrollment_attachment_by_id by validating that result.id ==
attachment_id and that key fields (e.g., result.name, result.description,
result.created_at or other expected attributes) match the expected values
returned by enrollment_attachments.get(attachment_id); also apply the same
pattern to the related update/return tests in this file (the tests covering
update/attachment sync) to assert specific changed fields and IDs rather than
only checking for non-None results.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/e2e/program/enrollment/attachment/test_async_attachment.py`:
- Around line 91-94: In test_download_enrollment_attachment, strengthen the
assertion on result.file_contents returned by
enrollment_attachments.download(attachment_id) so empty byte payloads don't
pass: replace the current "is not None" check with a truthy/length-based
assertion (e.g., assert result.file_contents and len(result.file_contents) > 0)
and optionally verify the type (e.g., bytes) to ensure a non-empty binary
payload is returned by download.

---

Nitpick comments:
In `@tests/e2e/program/enrollment/attachment/test_async_attachment.py`:
- Around line 85-90: The test_delete_enrollment_attachment currently calls
enrollment_attachments.delete(result.id) but does not assert the deletion;
update the test to verify the effect by attempting to retrieve the deleted
attachment (e.g., call enrollment_attachments.get(result.id) or list
attachments) and assert the expected failure/absence (raise NotFound/404 or
returns None/does not appear in list). Ensure you reference the same result.id
from created_enrollment_attachment and handle the client’s specific
error/response semantics when asserting deletion.

In `@tests/e2e/program/enrollment/attachment/test_sync_attachment.py`:
- Around line 33-37: The current test only checks non-null result; strengthen
assertions in test_get_enrollment_attachment_by_id by validating that result.id
== attachment_id and that key fields (e.g., result.name, result.description,
result.created_at or other expected attributes) match the expected values
returned by enrollment_attachments.get(attachment_id); also apply the same
pattern to the related update/return tests in this file (the tests covering
update/attachment sync) to assert specific changed fields and IDs rather than
only checking for non-None results.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 82f83797-2777-4fe4-94d0-fb41e1fdd0a8

📥 Commits

Reviewing files that changed from the base of the PR and between 28ccd6f and ef7e6db.

📒 Files selected for processing (11)
  • e2e_config.test.json
  • mpt_api_client/resources/program/enrollments.py
  • mpt_api_client/resources/program/enrollments_attachments.py
  • mpt_api_client/resources/program/mixins/attachment_mixin.py
  • pyproject.toml
  • tests/e2e/program/enrollment/attachment/conftest.py
  • tests/e2e/program/enrollment/attachment/test_async_attachment.py
  • tests/e2e/program/enrollment/attachment/test_sync_attachment.py
  • tests/unit/resources/program/mixin/test_attachment_mixin.py
  • tests/unit/resources/program/test_enrollments.py
  • tests/unit/resources/program/test_enrollments_attachments.py

Comment thread tests/e2e/program/enrollment/attachment/test_async_attachment.py
@robcsegal robcsegal changed the title MPT-20438: Added enpoints and e2e tests for program enrollment attachments MPT-20438: Added endpoints and e2e tests for program enrollment attachments Apr 23, 2026
@robcsegal robcsegal merged commit 5c70074 into main Apr 23, 2026
4 checks passed
@robcsegal robcsegal deleted the MPT-20438-add-endpoints-and-e-2-e-tests-for-program-enrollment-attachments branch April 23, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants