-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-20325: Added endpoints and e2e tests for program media #305
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-20325-add-endpoints-and-e-2-e-tests-for-program-media
Apr 17, 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
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,26 @@ | ||
| from mpt_api_client.http.mixins import ( | ||
| AsyncCreateFileMixin, | ||
| AsyncDownloadFileMixin, | ||
| CreateFileMixin, | ||
| DownloadFileMixin, | ||
| ) | ||
| from mpt_api_client.resources.program.mixins.publishable_mixin import ( | ||
| AsyncPublishableMixin, | ||
| PublishableMixin, | ||
| ) | ||
|
|
||
|
|
||
| class MediaMixin[Model]( | ||
| CreateFileMixin[Model], | ||
| DownloadFileMixin[Model], | ||
| PublishableMixin[Model], | ||
| ): | ||
| """Media mixin.""" | ||
|
|
||
|
|
||
| class AsyncMediaMixin[Model]( | ||
| AsyncCreateFileMixin[Model], | ||
| AsyncDownloadFileMixin[Model], | ||
| AsyncPublishableMixin[Model], | ||
| ): | ||
| """Media 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,73 @@ | ||
| from mpt_api_client.http import AsyncService, Service | ||
| from mpt_api_client.http.mixins import ( | ||
| AsyncCollectionMixin, | ||
| AsyncModifiableResourceMixin, | ||
| CollectionMixin, | ||
| ModifiableResourceMixin, | ||
| ) | ||
| from mpt_api_client.models import Model | ||
| from mpt_api_client.models.model import BaseModel | ||
| from mpt_api_client.resources.program.mixins import ( | ||
| AsyncMediaMixin, | ||
| MediaMixin, | ||
| ) | ||
|
|
||
|
|
||
| class Media(Model): | ||
| """Media resource. | ||
|
|
||
| Attributes: | ||
| name: Media name. | ||
| type: Media type. | ||
| description: Media description. | ||
| status: Media status. | ||
| filename: Original file name. | ||
| size: File size in bytes. | ||
| content_type: MIME content type of the media file. | ||
| display_order: Display order of the media item. | ||
| url: URL to access the media file. | ||
| program: Reference to the program. | ||
| audit: Audit information (created, updated events). | ||
| """ | ||
|
|
||
| name: str | None | ||
| type: str | None | ||
| description: str | None | ||
| status: str | None | ||
| filename: str | None | ||
| size: int | None | ||
| content_type: str | None | ||
| display_order: int | None | ||
| url: str | None | ||
| program: BaseModel | None | ||
| audit: BaseModel | None | ||
|
|
||
|
|
||
| class MediaServiceConfig: | ||
| """Media service configuration.""" | ||
|
|
||
| _endpoint = "/public/v1/program/programs/{program_id}/media" | ||
| _model_class = Media | ||
| _collection_key = "data" | ||
| _upload_file_key = "file" | ||
| _upload_data_key = "media" | ||
|
|
||
|
|
||
| class MediaService( | ||
| MediaMixin[Media], | ||
| ModifiableResourceMixin[Media], | ||
| CollectionMixin[Media], | ||
| Service[Media], | ||
| MediaServiceConfig, | ||
| ): | ||
| """Media service.""" | ||
|
|
||
|
|
||
| class AsyncMediaService( | ||
| AsyncMediaMixin[Media], | ||
| AsyncModifiableResourceMixin[Media], | ||
| AsyncCollectionMixin[Media], | ||
| AsyncService[Media], | ||
| MediaServiceConfig, | ||
| ): | ||
| """Async media service.""" |
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,27 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def invalid_media_id(): | ||
| return "PMD-0000-0000-0000" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def media_id(e2e_config): | ||
| return e2e_config["program.media.id"] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def media_data_factory(): | ||
| def factory(media_type: str = "Image"): | ||
| return { | ||
| "name": "E2E Created Program Media", | ||
| "description": "E2E Created Program Media", | ||
| "displayOrder": 1, | ||
| "type": media_type, | ||
| "mediatype": media_type, | ||
| "url": "", | ||
| "language": "en-us", | ||
| } | ||
|
|
||
| return factory |
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,105 @@ | ||
| 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 async_vendor_media_service(async_mpt_vendor, program_id): | ||
| return async_mpt_vendor.program.programs.media(program_id) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def created_media_from_file(async_vendor_media_service, media_data_factory, logo_fd): | ||
| media_data = media_data_factory() | ||
| media = await async_vendor_media_service.create(media_data, file=logo_fd) | ||
| yield media, media_data | ||
| try: | ||
| await async_vendor_media_service.delete(media.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete media {media.id}: {error.title}") # noqa: WPS421 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def created_media_from_url( | ||
| async_vendor_media_service, media_data_factory, video_url, logo_fd | ||
| ): | ||
| media_data = media_data_factory(media_type="Video") | ||
|
|
||
| media_data["url"] = video_url | ||
| media = await async_vendor_media_service.create(media_data, file=logo_fd) | ||
| yield media, media_data | ||
| try: | ||
| await async_vendor_media_service.delete(media.id) | ||
| except MPTAPIError as error: | ||
| print(f"TEARDOWN - Unable to delete media {media.id}: {error.title}") # noqa: WPS421 | ||
|
|
||
|
|
||
| def test_create_media(created_media_from_file): # noqa: AAA01 | ||
| result, media_data = created_media_from_file | ||
|
|
||
| assert result.name == media_data["name"] | ||
| assert result.description == media_data["description"] | ||
|
|
||
|
|
||
| def test_create_media_from_url(created_media_from_url): # noqa: AAA01 | ||
| result, media_data = created_media_from_url | ||
|
|
||
| assert result.name == media_data["name"] | ||
| assert result.description == media_data["description"] | ||
|
|
||
|
|
||
| async def test_update_media(async_vendor_media_service, created_media_from_file): | ||
| media, _ = created_media_from_file | ||
| update_data = {"name": "E2E Updated Program Media"} | ||
|
|
||
| result = await async_vendor_media_service.update(media.id, update_data) | ||
|
|
||
| assert result.name == update_data["name"] | ||
|
|
||
|
|
||
| async def test_delete_media(async_vendor_media_service, created_media_from_file): | ||
| media, _ = created_media_from_file | ||
|
|
||
| result = await async_vendor_media_service.delete(media.id) | ||
|
|
||
| assert result is None | ||
|
|
||
|
|
||
| async def test_get_media(async_vendor_media_service, media_id): | ||
| result = await async_vendor_media_service.get(media_id) | ||
|
|
||
| assert result.id == media_id | ||
|
|
||
|
|
||
| async def test_get_media_invalid_id(async_vendor_media_service, invalid_media_id): | ||
| with pytest.raises(MPTAPIError): | ||
| await async_vendor_media_service.get(invalid_media_id) | ||
|
|
||
|
|
||
| async def test_filter_and_select_media(async_vendor_media_service, media_id): | ||
| select_fields = ["-revision", "-audit"] | ||
| filtered_media = async_vendor_media_service.filter(RQLQuery(id=media_id)).select(*select_fields) | ||
|
|
||
| result = [media async for media in filtered_media.iterate()] | ||
|
|
||
| assert len(result) == 1 | ||
|
|
||
|
|
||
| async def test_media_publish(async_vendor_media_service, created_media_from_file): | ||
| media, _ = created_media_from_file | ||
|
|
||
| result = await async_vendor_media_service.publish(media.id) | ||
|
|
||
| assert result.status == "Published" | ||
|
|
||
|
|
||
| async def test_media_unpublish(async_vendor_media_service, created_media_from_file): | ||
| media, _ = created_media_from_file | ||
| await async_vendor_media_service.publish(media.id) | ||
|
|
||
| result = await async_vendor_media_service.unpublish(media.id) | ||
|
|
||
| assert result.status == "Unpublished" | ||
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.