Fixed platform filter. Fixes #18

This commit is contained in:
Eddy Hintze 2020-02-22 13:54:57 -05:00
parent c1e1df35fe
commit ccff521927
5 changed files with 48 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*egg-info
__pycache__
hbd-cookies.txt

View File

@ -1,5 +1,9 @@
# Change log
### 0.2.2
- Confirm the download is complete by checking the expected size to what downloaded
- Fixed the platform filter
### 0.2.1
- Fixed include & exclude logic being switched in v0.2.0

View File

@ -1 +1 @@
__version__ = '0.2.1'
__version__ = '0.2.2'

View File

@ -306,6 +306,9 @@ class DownloadLibrary:
space=' ' * (pb_width - done),
), end='\r')
if dl != total_length:
raise ValueError("Download did not complete")
def _load_cache_data(self, cache_file):
try:
with open(cache_file, 'r') as f:
@ -326,7 +329,9 @@ class DownloadLibrary:
def _should_download_platform(self, platform):
platform = platform.lower()
return self.platform_include and platform not in self.platform_include
if self.platform_include and platform not in self.platform_include:
return False
return True
def _should_download_file_type(self, ext):
ext = ext.lower()

View File

@ -1,6 +1,9 @@
from humblebundle_downloader.download_library import DownloadLibrary
###
# _should_download_file_type
###
def test_include_logic_has_values():
dl = DownloadLibrary(
'fake_cookie_path',
@ -47,3 +50,36 @@ def test_exclude_logic_empty():
assert dl._should_download_file_type('df') is True
assert dl._should_download_file_type('EPub') is True
assert dl._should_download_file_type('mobi') is True
###
# _should_download_platform
###
def test_download_platform_filter_none():
dl = DownloadLibrary(
'fake_cookie_path',
'fake_library_path',
platform_include=None,
)
assert dl._should_download_platform('ebook') is True
assert dl._should_download_platform('audio') is True
def test_download_platform_filter_blank():
dl = DownloadLibrary(
'fake_cookie_path',
'fake_library_path',
platform_include=[],
)
assert dl._should_download_platform('ebook') is True
assert dl._should_download_platform('audio') is True
def test_download_platform_filter_audio():
dl = DownloadLibrary(
'fake_cookie_path',
'fake_library_path',
platform_include=['audio'],
)
assert dl._should_download_platform('ebook') is False
assert dl._should_download_platform('audio') is True