|
33 | 33 | LearningResourcePriceFactory, |
34 | 34 | LearningResourceRunFactory, |
35 | 35 | ) |
36 | | -from learning_resources.models import ContentFile, LearningResource |
| 36 | +from learning_resources.models import ( |
| 37 | + ContentFile, |
| 38 | + LearningResource, |
| 39 | + LearningResourceRelationship, |
| 40 | +) |
37 | 41 | from main.test_utils import assert_json_equal, drf_datetime |
38 | 42 | from main.utils import frontend_absolute_url |
39 | 43 |
|
@@ -141,6 +145,36 @@ def test_serialize_podcast_episode_to_json(): |
141 | 145 | ) |
142 | 146 |
|
143 | 147 |
|
| 148 | +def test_serialize_video_resource_playlists_to_json(): |
| 149 | + """ |
| 150 | + Verify that a serialized video resource has the correct playlist data |
| 151 | + """ |
| 152 | + playlist = factories.VideoPlaylistFactory.create() |
| 153 | + video = factories.VideoFactory.create() |
| 154 | + LearningResourceRelationship.objects.get_or_create( |
| 155 | + parent=playlist.learning_resource, |
| 156 | + child=video.learning_resource, |
| 157 | + relation_type=LearningResourceRelationTypes.PLAYLIST_VIDEOS.value, |
| 158 | + ) |
| 159 | + serializer = serializers.VideoResourceSerializer(instance=video.learning_resource) |
| 160 | + assert serializer.data["playlists"] == [playlist.learning_resource.id] |
| 161 | + |
| 162 | + |
| 163 | +def test_serialize_podcast_episode_playlists_to_json(): |
| 164 | + """ |
| 165 | + Verify that a serialized podcast episode resource has the correct podcast data |
| 166 | + """ |
| 167 | + podcast = factories.PodcastFactory.create() |
| 168 | + podcast_episode = factories.PodcastEpisodeFactory.create() |
| 169 | + LearningResourceRelationship.objects.get_or_create( |
| 170 | + parent=podcast.learning_resource, |
| 171 | + child=podcast_episode.learning_resource, |
| 172 | + relation_type=LearningResourceRelationTypes.PODCAST_EPISODES.value, |
| 173 | + ) |
| 174 | + serializer = serializers.PodcastEpisodeSerializer(instance=podcast_episode) |
| 175 | + assert serializer.data["podcasts"] == [podcast.learning_resource.id] |
| 176 | + |
| 177 | + |
144 | 178 | @pytest.mark.parametrize("has_context", [True, False]) |
145 | 179 | @pytest.mark.parametrize( |
146 | 180 | ("params", "detail_key", "specific_serializer_cls", "detail_serializer_cls"), |
|
0 commit comments