|
| 1 | +""" |
| 2 | +Test cases for the customized VideoBlock _poster method for Educast videos. |
| 3 | +""" |
| 4 | +from django.test import TestCase |
| 5 | + |
| 6 | +from nau_openedx_extensions.xblocks.video_block import get_educast_poster_factory |
| 7 | + |
| 8 | + |
| 9 | +class FakeVideoBlock(): |
| 10 | + """ |
| 11 | + A fake VideoBlock XBlock class for testing |
| 12 | + """ |
| 13 | + def __init__(self): |
| 14 | + self.html5_sources = {} |
| 15 | + |
| 16 | + |
| 17 | +class TestVideoBlock(TestCase): |
| 18 | + """ |
| 19 | + Test cases for the customized VideoBlock _poster method for Educast videos. |
| 20 | + """ |
| 21 | + def test_get_educast_poster_https(self): |
| 22 | + """ |
| 23 | + Test the customized _poster method for VideoBlock. |
| 24 | + """ |
| 25 | + # Create a mock previous _poster method |
| 26 | + def mock_prev_poster(self): # pylint: disable=unused-argument |
| 27 | + return None |
| 28 | + |
| 29 | + # Create the customized _poster method |
| 30 | + customized_poster_method = get_educast_poster_factory(mock_prev_poster) |
| 31 | + |
| 32 | + # Create an instance of VideoBlock and set html5_sources |
| 33 | + video_block = FakeVideoBlock() |
| 34 | + video_block.html5_sources = ['https://dev.educast.fccn.pt/vod/clips/bum66sthd/streaming.m3u8'] |
| 35 | + |
| 36 | + # Call the customized _poster method |
| 37 | + poster_url = customized_poster_method(video_block) |
| 38 | + |
| 39 | + # Verify the poster URL is as expected |
| 40 | + expected_url = 'https://dev.educast.fccn.pt/img/clips/bum66sthd/delivery/cover' |
| 41 | + self.assertEqual(poster_url, expected_url) |
| 42 | + |
| 43 | + def test_get_educast_poster_http(self): |
| 44 | + """ |
| 45 | + Test the customized _poster method for VideoBlock. |
| 46 | + """ |
| 47 | + # Create a mock previous _poster method |
| 48 | + def mock_prev_poster(self): # pylint: disable=unused-argument |
| 49 | + return None |
| 50 | + |
| 51 | + # Create the customized _poster method |
| 52 | + customized_poster_method = get_educast_poster_factory(mock_prev_poster) |
| 53 | + |
| 54 | + # Create an instance of VideoBlock and set html5_sources |
| 55 | + video_block = FakeVideoBlock() |
| 56 | + video_block.html5_sources = ['http://educast.fccn.pt/vod/clips/fdgfdgfdgfdg/streaming.m3u8'] |
| 57 | + |
| 58 | + # Call the customized _poster method |
| 59 | + poster_url = customized_poster_method(video_block) |
| 60 | + |
| 61 | + # Verify the poster URL is as expected |
| 62 | + expected_url = 'http://educast.fccn.pt/img/clips/fdgfdgfdgfdg/delivery/cover' |
| 63 | + self.assertEqual(poster_url, expected_url) |
| 64 | + |
| 65 | + def test_get_educast_poster_no_protocol(self): |
| 66 | + """ |
| 67 | + Test the customized _poster method for VideoBlock. |
| 68 | + """ |
| 69 | + # Create a mock previous _poster method |
| 70 | + def mock_prev_poster(self): # pylint: disable=unused-argument |
| 71 | + return None |
| 72 | + |
| 73 | + # Create the customized _poster method |
| 74 | + customized_poster_method = get_educast_poster_factory(mock_prev_poster) |
| 75 | + |
| 76 | + # Create an instance of VideoBlock and set html5_sources |
| 77 | + video_block = FakeVideoBlock() |
| 78 | + video_block.html5_sources = ['//educast.fccn.pt/vod/clips/aaaaaa/streaming.m3u8'] |
| 79 | + |
| 80 | + # Call the customized _poster method |
| 81 | + poster_url = customized_poster_method(video_block) |
| 82 | + |
| 83 | + # Verify the poster URL is as expected |
| 84 | + expected_url = '//educast.fccn.pt/img/clips/aaaaaa/delivery/cover' |
| 85 | + self.assertEqual(poster_url, expected_url) |
0 commit comments