Skip to content

Commit e0585a4

Browse files
committed
Improved testing!
1 parent 9e464d2 commit e0585a4

4 files changed

Lines changed: 73 additions & 53 deletions

File tree

frameioclient/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,7 @@ def copy_asset(self, destination_folder_id, **kwargs):
351351
return self._api_call('post', endpoint, kwargs)
352352

353353
def bulk_copy_assets(self, destination_folder_id, asset_list=[], copy_comments=False):
354-
"""
355-
Bulk copy assets
354+
"""Bulk copy assets
356355
357356
:Args:
358357
destination_folder_id (string): The id of the folder you want to copy into.

frameioclient/download.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,24 @@ def __init__(self, asset, download_folder):
1212
def get_download_key(self):
1313
try:
1414
url = self.asset['original']
15-
except KeyError:
15+
except KeyError as e:
1616
if self.asset['is_session_watermarked'] == True:
1717
resolution_list = list()
18-
for resolution_key, download_url in sorted(self.asset['downloads'].items()):
19-
resolution = resolution_key.split("_")[1] # Grab the item at index 1 (resolution)
20-
try:
21-
resolution = int(resolution)
22-
except ValueError:
23-
continue
24-
25-
if download_url is not None:
26-
resolution_list.append(download_url)
27-
28-
# Grab the highest resolution (first item) now
29-
url = resolution_list[0]
18+
try:
19+
for resolution_key, download_url in sorted(self.asset['downloads'].items()):
20+
resolution = resolution_key.split("_")[1] # Grab the item at index 1 (resolution)
21+
try:
22+
resolution = int(resolution)
23+
except ValueError:
24+
continue
25+
26+
if download_url is not None:
27+
resolution_list.append(download_url)
28+
29+
# Grab the highest resolution (first item) now
30+
url = resolution_list[0]
31+
except KeyError:
32+
raise DownloadException
3033
else:
3134
raise DownloadException
3235

tests/test_frameiodownloader.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+

tests/test_wmid.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)