-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-20438: Added endpoints and e2e tests for program enrollment attachments #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
robcsegal
merged 1 commit into
main
from
MPT-20438-add-endpoints-and-e-2-e-tests-for-program-enrollment-attachments
Apr 23, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
mpt_api_client/resources/program/enrollments_attachments.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| from mpt_api_client.http import AsyncService, Service | ||
| from mpt_api_client.http.mixins import ( | ||
| AsyncCollectionMixin, | ||
| CollectionMixin, | ||
| ) | ||
| from mpt_api_client.models import Model | ||
| from mpt_api_client.models.model import BaseModel | ||
| from mpt_api_client.resources.program.mixins.attachment_mixin import ( | ||
| AsyncAttachmentMixin, | ||
| AttachmentMixin, | ||
| ) | ||
|
|
||
|
|
||
| class EnrollmentAttachment(Model): | ||
| """Enrollment Attachment resource. | ||
|
|
||
| Attributes: | ||
| name: The name of the attachment. | ||
| description: The description of the attachment. | ||
| type: The type of the attachment. | ||
| filename: The filename of the attachment. | ||
| size: The size of the attachment in bytes. | ||
| content_type: The content type of the attachment. | ||
| enrollment: The enrollment associated with the attachment. | ||
| audit: The audit information for the attachment. | ||
| """ | ||
|
|
||
| name: str | None = None | ||
| description: str | None = None | ||
| type: str | None = None | ||
| filename: str | None = None | ||
| size: int | None = None | ||
| content_type: str | None = None | ||
| enrollment: BaseModel | None = None | ||
| audit: BaseModel | None = None | ||
|
|
||
|
|
||
| class EnrollmentAttachmentsServiceConfig: | ||
| """Enrollment Attachments service configuration.""" | ||
|
|
||
| _endpoint = "/public/v1/program/enrollments/{enrollment_id}/attachments" | ||
| _model_class = EnrollmentAttachment | ||
| _collection_key = "data" | ||
| _upload_file_key = "file" | ||
| _upload_data_key = "attachment" | ||
|
|
||
|
|
||
| class EnrollmentAttachmentsService( | ||
| AttachmentMixin[EnrollmentAttachment], | ||
| CollectionMixin[EnrollmentAttachment], | ||
| Service[EnrollmentAttachment], | ||
| EnrollmentAttachmentsServiceConfig, | ||
| ): | ||
| """Enrollment Attachments service.""" | ||
|
|
||
|
|
||
| class AsyncEnrollmentAttachmentsService( | ||
| AsyncAttachmentMixin[EnrollmentAttachment], | ||
| AsyncCollectionMixin[EnrollmentAttachment], | ||
| AsyncService[EnrollmentAttachment], | ||
| EnrollmentAttachmentsServiceConfig, | ||
| ): | ||
| """Enrollment Attachments service.""" |
32 changes: 32 additions & 0 deletions
32
mpt_api_client/resources/program/mixins/attachment_mixin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| from mpt_api_client.http.mixins import ( | ||
| AsyncCreateFileMixin, | ||
| AsyncDeleteMixin, | ||
| AsyncDownloadFileMixin, | ||
| AsyncGetMixin, | ||
| AsyncUpdateMixin, | ||
| CreateFileMixin, | ||
| DeleteMixin, | ||
| DownloadFileMixin, | ||
| GetMixin, | ||
| UpdateMixin, | ||
| ) | ||
|
|
||
|
|
||
| class AttachmentMixin[Model]( | ||
| CreateFileMixin[Model], | ||
| UpdateMixin[Model], | ||
| DeleteMixin, | ||
| DownloadFileMixin[Model], | ||
| GetMixin[Model], | ||
| ): | ||
| """Attachment mixin.""" | ||
|
|
||
|
|
||
| class AsyncAttachmentMixin[Model]( | ||
| AsyncCreateFileMixin[Model], | ||
| AsyncUpdateMixin[Model], | ||
| AsyncDeleteMixin, | ||
| AsyncDownloadFileMixin[Model], | ||
| AsyncGetMixin[Model], | ||
| ): | ||
| """Async Attachment mixin.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def attachment_id(e2e_config): | ||
| return e2e_config["program.enrollment.attachment.id"] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def invalid_attachment_id(): | ||
| return "ENA-0000-0000-0000-0000" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def enrollment_attachment_factory(): | ||
| def factory(name: str = "E2E Created Program Enrollment Attachment"): | ||
| return { | ||
| "name": name, | ||
| "description": name, | ||
| } | ||
|
|
||
| return factory |
94 changes: 94 additions & 0 deletions
94
tests/e2e/program/enrollment/attachment/test_async_attachment.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
| from mpt_api_client.rql.query_builder import RQLQuery | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def created_enrollment_attachment( | ||
| async_mpt_vendor, enrollment_attachment_factory, enrollment_id, pdf_fd | ||
| ): | ||
| new_enrollment_attachment_request_data = enrollment_attachment_factory( | ||
| name="E2E Created Program Enrollment Attachment", | ||
| ) | ||
| enrollment_attachments = async_mpt_vendor.program.enrollments.attachments(enrollment_id) | ||
|
|
||
| created_enrollment_attachment = await enrollment_attachments.create( | ||
| new_enrollment_attachment_request_data, file=pdf_fd | ||
| ) | ||
|
|
||
| yield created_enrollment_attachment | ||
|
|
||
| try: | ||
| await enrollment_attachments.delete(created_enrollment_attachment.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete enrollment attachment: {error.title}") # noqa: WPS421 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def enrollment_attachments(async_mpt_vendor, enrollment_id): | ||
| return async_mpt_vendor.program.enrollments.attachments(enrollment_id) | ||
|
|
||
|
|
||
| async def test_get_enrollment_attachment_by_id(enrollment_attachments, attachment_id): | ||
| result = await enrollment_attachments.get(attachment_id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_get_enrollment_attachment_not_found(enrollment_attachments, invalid_attachment_id): | ||
| with pytest.raises(MPTAPIError, match=r"404 Not Found"): | ||
| await enrollment_attachments.get(invalid_attachment_id) | ||
|
|
||
|
|
||
| async def test_list_enrollment_attachments(enrollment_attachments): | ||
| limit = 10 | ||
|
|
||
| result = await enrollment_attachments.fetch_page(limit=limit) | ||
|
|
||
| assert len(result) > 0 | ||
|
|
||
|
|
||
| async def test_filter_enrollment_attachments(enrollment_attachments, attachment_id): | ||
| select_fields = ["-description"] | ||
| filtered_attachments = ( | ||
| enrollment_attachments | ||
| .filter(RQLQuery(id=attachment_id)) | ||
| .filter(RQLQuery(name="E2E Seeded Program Enrollment Attachment")) | ||
| .select(*select_fields) | ||
| ) | ||
|
|
||
| result = [attachment async for attachment in filtered_attachments.iterate()] | ||
|
|
||
| assert len(result) == 1 | ||
|
|
||
|
|
||
| def test_create_enrollment_attachment(created_enrollment_attachment): | ||
| result = created_enrollment_attachment | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_update_enrollment_attachment(enrollment_attachments, created_enrollment_attachment): | ||
| updated_data = { | ||
| "name": "E2E Updated Program Enrollment Attachment", | ||
| "description": "E2E Updated Program Enrollment Attachment", | ||
| } | ||
|
|
||
| result = await enrollment_attachments.update(created_enrollment_attachment.id, updated_data) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_delete_enrollment_attachment(enrollment_attachments, created_enrollment_attachment): | ||
| result = created_enrollment_attachment | ||
|
|
||
| await enrollment_attachments.delete(result.id) | ||
|
|
||
|
|
||
| async def test_download_enrollment_attachment(enrollment_attachments, attachment_id): | ||
| result = await enrollment_attachments.download(attachment_id) | ||
|
|
||
| assert result.file_contents is not None | ||
92 changes: 92 additions & 0 deletions
92
tests/e2e/program/enrollment/attachment/test_sync_attachment.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import pytest | ||
|
|
||
| from mpt_api_client.exceptions import MPTAPIError | ||
| from mpt_api_client.rql.query_builder import RQLQuery | ||
|
|
||
| pytestmark = [pytest.mark.flaky] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def created_enrollment_attachment(mpt_vendor, enrollment_attachment_factory, enrollment_id, pdf_fd): | ||
| new_enrollment_attachment_request_data = enrollment_attachment_factory( | ||
| name="E2E Created Program Enrollment Attachment", | ||
| ) | ||
| enrollment_attachments = mpt_vendor.program.enrollments.attachments(enrollment_id) | ||
|
|
||
| created_enrollment_attachment = enrollment_attachments.create( | ||
| new_enrollment_attachment_request_data, file=pdf_fd | ||
| ) | ||
|
|
||
| yield created_enrollment_attachment | ||
|
|
||
| try: | ||
| enrollment_attachments.delete(created_enrollment_attachment.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete enrollment attachment: {error.title}") # noqa: WPS421 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def enrollment_attachments(mpt_vendor, enrollment_id): | ||
| return mpt_vendor.program.enrollments.attachments(enrollment_id) | ||
|
|
||
|
|
||
| def test_get_enrollment_attachment_by_id(enrollment_attachments, attachment_id): | ||
| result = enrollment_attachments.get(attachment_id) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| def test_get_enrollment_attachment_not_found(enrollment_attachments, invalid_attachment_id): | ||
| with pytest.raises(MPTAPIError, match=r"404 Not Found"): | ||
| enrollment_attachments.get(invalid_attachment_id) | ||
|
|
||
|
|
||
| def test_list_enrollment_attachments(enrollment_attachments): | ||
| limit = 10 | ||
|
|
||
| result = enrollment_attachments.fetch_page(limit=limit) | ||
|
|
||
| assert len(result) > 0 | ||
|
|
||
|
|
||
| def test_filter_enrollment_attachments(enrollment_attachments, attachment_id): | ||
| select_fields = ["-description"] | ||
| filtered_attachments = ( | ||
| enrollment_attachments | ||
| .filter(RQLQuery(id=attachment_id)) | ||
| .filter(RQLQuery(name="E2E Seeded Program Enrollment Attachment")) | ||
| .select(*select_fields) | ||
| ) | ||
|
|
||
| result = list(filtered_attachments.iterate()) | ||
|
|
||
| assert len(result) == 1 | ||
|
|
||
|
|
||
| def test_create_enrollment_attachment(created_enrollment_attachment): | ||
| result = created_enrollment_attachment | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| def test_update_enrollment_attachment(enrollment_attachments, created_enrollment_attachment): | ||
| updated_data = { | ||
| "name": "E2E Updated Program Enrollment Attachment", | ||
| "description": "E2E Updated Program Enrollment Attachment", | ||
| } | ||
|
|
||
| result = enrollment_attachments.update(created_enrollment_attachment.id, updated_data) | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| def test_delete_enrollment_attachment(enrollment_attachments, created_enrollment_attachment): | ||
| result = created_enrollment_attachment | ||
|
|
||
| enrollment_attachments.delete(result.id) | ||
|
|
||
|
|
||
| def test_download_enrollment_attachment(enrollment_attachments, attachment_id): | ||
| result = enrollment_attachments.download(attachment_id) | ||
|
|
||
| assert result.file_contents is not None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.