mirror of
https://github.com/xtream1101/humblebundle-downloader.git
synced 2025-02-08 14:43:37 +01:00
Added tests. Fixed include & exclude being switched
This commit is contained in:
parent
3a06f09f09
commit
2ca4ad1e77
@ -1,4 +1,4 @@
|
|||||||
image: python:3
|
image: python:3.7-alpine
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
@ -13,6 +13,12 @@ flake8:
|
|||||||
- pip install tox
|
- pip install tox
|
||||||
- tox -e flake8
|
- tox -e flake8
|
||||||
|
|
||||||
|
pytest:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- pip install tox
|
||||||
|
- tox -e py37
|
||||||
|
|
||||||
pypi-package:
|
pypi-package:
|
||||||
stage: package
|
stage: package
|
||||||
only:
|
only:
|
||||||
|
@ -25,10 +25,7 @@ class DownloadLibrary:
|
|||||||
def __init__(self, cookie_path, library_path, progress_bar=False,
|
def __init__(self, cookie_path, library_path, progress_bar=False,
|
||||||
ext_include=None, ext_exclude=None, platform_include=None,
|
ext_include=None, ext_exclude=None, platform_include=None,
|
||||||
purchase_keys=None, trove=False, update=False):
|
purchase_keys=None, trove=False, update=False):
|
||||||
|
self.cookie_path = cookie_path
|
||||||
with open(cookie_path, 'r') as f:
|
|
||||||
self.account_cookies = f.read().strip()
|
|
||||||
|
|
||||||
self.library_path = library_path
|
self.library_path = library_path
|
||||||
self.progress_bar = progress_bar
|
self.progress_bar = progress_bar
|
||||||
self.ext_include = [] if ext_include is None else list(map(str.lower, ext_include)) # noqa: E501
|
self.ext_include = [] if ext_include is None else list(map(str.lower, ext_include)) # noqa: E501
|
||||||
@ -40,19 +37,23 @@ class DownloadLibrary:
|
|||||||
self.platform_include = list(map(str.lower, platform_include))
|
self.platform_include = list(map(str.lower, platform_include))
|
||||||
|
|
||||||
self.cache_file = os.path.join(library_path, '.cache.json')
|
self.cache_file = os.path.join(library_path, '.cache.json')
|
||||||
|
self.purchase_keys = purchase_keys
|
||||||
|
self.trove = trove
|
||||||
|
self.update = update
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
with open(self.cookie_path, 'r') as f:
|
||||||
|
self.account_cookies = f.read().strip()
|
||||||
|
|
||||||
self.cache_data = self._load_cache_data(self.cache_file)
|
self.cache_data = self._load_cache_data(self.cache_file)
|
||||||
|
self.purchase_keys = self.purchase_keys if self.purchase_keys else self._get_purchase_keys() # noqa: E501
|
||||||
|
|
||||||
self.purchase_keys = purchase_keys if purchase_keys else self._get_purchase_keys() # noqa: E501
|
if self.trove is True:
|
||||||
|
|
||||||
if trove is True:
|
|
||||||
logger.info("Checking Humble Trove...")
|
logger.info("Checking Humble Trove...")
|
||||||
self.trove_products = self._get_trove_products()
|
self.trove_products = self._get_trove_products()
|
||||||
else:
|
else:
|
||||||
self.trove_products = []
|
self.trove_products = []
|
||||||
|
|
||||||
self.update = update
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
for product in self.trove_products:
|
for product in self.trove_products:
|
||||||
title = _clean_name(product['human-name'])
|
title = _clean_name(product['human-name'])
|
||||||
self._process_trove_product(title, product)
|
self._process_trove_product(title, product)
|
||||||
@ -329,5 +330,8 @@ class DownloadLibrary:
|
|||||||
|
|
||||||
def _should_download_file_type(self, ext):
|
def _should_download_file_type(self, ext):
|
||||||
ext = ext.lower()
|
ext = ext.lower()
|
||||||
return ((self.ext_include and ext.lower() not in self.ext_include)
|
if self.ext_include != []:
|
||||||
or (self.ext_exclude and ext.lower() in self.ext_exclude))
|
return ext in self.ext_include
|
||||||
|
elif self.ext_exclude != []:
|
||||||
|
return ext not in self.ext_exclude
|
||||||
|
return True
|
||||||
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
49
tests/test_download_library.py
Normal file
49
tests/test_download_library.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
from humblebundle_downloader.download_library import DownloadLibrary
|
||||||
|
|
||||||
|
|
||||||
|
def test_include_logic_has_values():
|
||||||
|
dl = DownloadLibrary(
|
||||||
|
'fake_cookie_path',
|
||||||
|
'fake_library_path',
|
||||||
|
ext_include=['pdf', 'EPub'],
|
||||||
|
)
|
||||||
|
assert dl._should_download_file_type('pdf') is True
|
||||||
|
assert dl._should_download_file_type('df') is False
|
||||||
|
assert dl._should_download_file_type('ePub') is True
|
||||||
|
assert dl._should_download_file_type('mobi') is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_include_logic_empty():
|
||||||
|
dl = DownloadLibrary(
|
||||||
|
'fake_cookie_path',
|
||||||
|
'fake_library_path',
|
||||||
|
ext_include=[],
|
||||||
|
)
|
||||||
|
assert dl._should_download_file_type('pdf') is True
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
def test_exclude_logic_has_values():
|
||||||
|
dl = DownloadLibrary(
|
||||||
|
'fake_cookie_path',
|
||||||
|
'fake_library_path',
|
||||||
|
ext_exclude=['pdf', 'EPub'],
|
||||||
|
)
|
||||||
|
assert dl._should_download_file_type('pdf') is False
|
||||||
|
assert dl._should_download_file_type('df') is True
|
||||||
|
assert dl._should_download_file_type('ePub') is False
|
||||||
|
assert dl._should_download_file_type('mobi') is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_exclude_logic_empty():
|
||||||
|
dl = DownloadLibrary(
|
||||||
|
'fake_cookie_path',
|
||||||
|
'fake_library_path',
|
||||||
|
ext_exclude=[],
|
||||||
|
)
|
||||||
|
assert dl._should_download_file_type('pdf') is True
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user