|
| 1 | +import pytest |
| 2 | +from frameioclient.download import FrameioDownloader |
| 3 | +from frameioclient.exceptions import DownloadException |
| 4 | + |
| 5 | + |
| 6 | +regular_asset = { |
| 7 | + "is_hls_required": False, |
| 8 | + "is_session_watermarked": False, |
| 9 | + "downloads": { |
| 10 | + "h264_720": "some-720-url", |
| 11 | + "h264_1080_best": "some-1080-url" |
| 12 | + }, |
| 13 | + "h264_720": "some-720-url", |
| 14 | + "h264_1080_best": "some-1080-url", |
| 15 | + "original": "some-original-url", |
| 16 | + "hls_manifest": "some-hls-url" |
| 17 | +} |
| 18 | + |
| 19 | +watermarked_asset_download_allowed = { |
| 20 | + "is_hls_required": True, |
| 21 | + "is_session_watermarked": True, |
| 22 | + "downloads": { |
| 23 | + "h264_720": "download-stream-service-url", |
| 24 | + "h264_1080_best": "download-stream-service-url" |
| 25 | + }, |
| 26 | + "hls_manifest": "hls-url" |
| 27 | +} |
| 28 | + |
| 29 | +watermarked_asset_no_download = { |
| 30 | + "is_hls_required": True, |
| 31 | + "is_session_watermarked": True, |
| 32 | + "hls_manifest": "hls-url" |
| 33 | +} |
| 34 | + |
| 35 | +no_download_allowed = { |
| 36 | + "is_hls_required": True, |
| 37 | + "is_session_watermarked": False, |
| 38 | + "hls_manifest": "hls-url" |
| 39 | +} |
| 40 | + |
| 41 | +def test_get_download_key_returns_original(): |
| 42 | + url = FrameioDownloader(regular_asset, './').get_download_key() |
| 43 | + assert url == regular_asset['original'] |
| 44 | + |
| 45 | +def test_get_download_key_returns_watermarked_download(): |
| 46 | + url = FrameioDownloader(watermarked_asset_download_allowed, './').get_download_key() |
| 47 | + assert url == watermarked_asset_download_allowed['downloads']['h264_1080_best'] |
| 48 | + |
| 49 | +def test_get_download_key_fails_gracefully_on_watermarked_asset(): |
| 50 | + with pytest.raises(DownloadException): |
| 51 | + FrameioDownloader(watermarked_asset_no_download, './').get_download_key() |
| 52 | + |
| 53 | +def test_get_download_key_fails_gracefully_when_downloads_disallowed(): |
| 54 | + with pytest.raises(DownloadException): |
| 55 | + FrameioDownloader(no_download_allowed, './').get_download_key() |
| 56 | + |
0 commit comments