Private GIT

Skip to content
Snippets Groups Projects
Commit e6f4fb1e authored by Gaëtan Muller's avatar Gaëtan Muller
Browse files

Add tests

parent 5fbd1399
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
import re
import sickbeard
from base64 import b16encode, b32decode
from datetime import datetime
......@@ -30,6 +31,7 @@ from sickbeard.common import MULTI_EP_RESULT, Quality, SEASON_RESULT, user_agent
from sickbeard.db import DBConnection
from sickbeard.helpers import download_file, getURL, remove_file_failed
from sickbeard.name_parser.parser import InvalidNameException, InvalidShowException, NameParser
from sickbeard.show_name_helpers import allPossibleShowNames
from sickbeard.tvcache import TVCache
from sickrage.helper.common import replace_extension, sanitize_filename
from sickrage.helper.encoding import ek
......@@ -360,11 +362,14 @@ class GenericProvider:
return False
def is_enabled(self):
return self.enabled
return bool(self.enabled)
@staticmethod
def make_id(name):
return re.sub(r'[^\w\d_]', '_', name.strip().lower())
if not name:
return ''
return re.sub(r'[^\w\d_]', '_', str(name).strip().lower())
def search_rss(self, episodes):
return self.cache.findNeededEpisodes(episodes)
......@@ -385,10 +390,55 @@ class GenericProvider:
return SearchResult(episodes)
def _get_episode_search_strings(self, episode, add_string=''):
if not episode:
return []
search_string = {
'Episode': []
}
for show_name in set(allPossibleShowNames(episode.show)):
episode_string = show_name + ' '
if episode.show.air_by_date:
episode_string += str(episode.airdate).replace('-', ' ')
elif episode.show.sports:
episode_string += str(episode.airdate).replace('-', ' ')
episode_string += ('|', ' ')[len(self.proper_strings) > 1]
episode_string += episode.airdate.strftime('%b')
elif episode.show.anime:
episode_string += '%02d' % int(episode.scene_absolute_number)
else:
episode_string += sickbeard.config.naming_ep_type[2] % {
'seasonnumber': episode.scene_season,
'episodenumber': episode.scene_episode,
}
if add_string:
episode_string += ' ' + add_string
search_string['Episode'].append(episode_string.encode('utf-8').strip())
return [search_string]
def _get_season_search_strings(self, episode):
return []
search_string = {
'Season': []
}
for show_name in set(allPossibleShowNames(self.show)):
episode_string = show_name + ' '
if episode.show.air_by_date or episode.show.sports:
episode_string += str(episode.airdate).split('-')[0]
elif episode.show.anime:
episode_string += '%d' % int(episode.scene_absolute_number)
else:
episode_string += 'S%02d' % int(episode.scene_season)
search_string['Season'].append(episode_string.encode('utf-8').strip())
return [search_string]
def _get_size(self, item):
return -1
......@@ -397,18 +447,28 @@ class GenericProvider:
return ''
def _get_title_and_url(self, item):
if not item:
return '', ''
title = item.get('title', '')
url = item.get('link', '')
if title:
title = u'' + title.replace(' ', '.')
else:
title = ''
if url:
url = url.replace('&amp;', '&').replace('%26tr%3D', '&tr=')
else:
url = ''
return title, url
def _make_url(self, result):
if not result:
return '', ''
urls = []
filename = u''
......
......@@ -32,7 +32,7 @@ class NZBProvider(GenericProvider):
self.provider_type = GenericProvider.NZB
def is_active(self):
return sickbeard.USE_NZBS and self.is_enabled()
return bool(sickbeard.USE_NZBS) and self.is_enabled()
def _get_result(self, episodes):
return NZBSearchResult(episodes)
......@@ -40,7 +40,7 @@ class NZBProvider(GenericProvider):
def _get_size(self, item):
try:
size = item.get('links')[1].get('length', -1)
except IndexError:
except (AttributeError, IndexError, TypeError):
size = -1
if not size:
......
......@@ -25,7 +25,6 @@ from sickbeard import logger
from sickbeard.classes import Proper, TorrentSearchResult
from sickbeard.common import Quality
from sickbeard.db import DBConnection
from sickbeard.show_name_helpers import allPossibleShowNames
from sickrage.helper.common import try_int
from sickrage.helper.exceptions import ex
from sickrage.providers.GenericProvider import GenericProvider
......@@ -67,14 +66,7 @@ class TorrentProvider(GenericProvider):
return results
def is_active(self):
return sickbeard.USE_TORRENTS and self.is_enabled()
@staticmethod
def _clean_title(title):
if not title:
return ''
return title.replace(' ', '.')
return bool(sickbeard.USE_TORRENTS) and self.is_enabled()
@property
def _custom_trackers(self):
......@@ -86,60 +78,9 @@ class TorrentProvider(GenericProvider):
return ''
def _get_episode_search_strings(self, episode, add_string=''):
if not episode:
return []
search_string = {
'Episode': []
}
for show_name in set(allPossibleShowNames(episode.show)):
episode_string = show_name + ' '
if episode.show.air_by_date:
episode_string += str(episode.airdate).replace('-', ' ')
elif episode.show.sports:
episode_string += str(episode.airdate).replace('-', ' ')
episode_string += ('|', ' ')[len(self.proper_strings) > 1]
episode_string += episode.airdate.strftime('%b')
elif episode.show.anime:
episode_string += '%02d' % int(episode.scene_absolute_number)
else:
episode_string += sickbeard.config.naming_ep_type[2] % {
'seasonnumber': episode.scene_season,
'episodenumber': episode.scene_episode,
}
if add_string:
episode_string += ' ' + add_string
search_string['Episode'].append(episode_string.encode('utf-8').strip())
return [search_string]
def _get_result(self, episodes):
return TorrentSearchResult(episodes)
def _get_season_search_strings(self, episode):
search_string = {
'Season': []
}
for show_name in set(allPossibleShowNames(self.show)):
episode_string = show_name + ' '
if episode.show.air_by_date or episode.show.sports:
episode_string += str(episode.airdate).split('-')[0]
elif episode.show.anime:
episode_string += '%d' % int(episode.scene_absolute_number)
else:
episode_string += 'S%02d' % int(episode.scene_season)
search_string['Season'].append(episode_string.encode('utf-8').strip())
return [search_string]
def _get_size(self, item):
if isinstance(item, dict):
size = item.get('size', -1)
......@@ -179,7 +120,7 @@ class TorrentProvider(GenericProvider):
download_url = download_url.replace('&amp;', '&')
if title:
title = self._clean_title(title)
title = title.replace(' ', '.')
return title, download_url
......
......@@ -25,6 +25,7 @@ from __future__ import print_function
import helper
import media
import providers
import show
import system
import unittest
......@@ -35,6 +36,7 @@ if __name__ == '__main__':
TEST_MODULES = [
helper,
media,
providers,
show,
system,
]
......
# coding=utf-8
"""
Tests for SickRage providers
"""
import unittest
from generic_provider_tests import GenericProviderTests
from nzb_provider_tests import NZBProviderTests
from torrent_provider_tests import TorrentProviderTests
if __name__ == '__main__':
print('=====> Running all test in "sickrage_tests.providers" <=====')
TEST_CLASSES = [
GenericProviderTests,
NZBProviderTests,
TorrentProviderTests,
]
for test_class in TEST_CLASSES:
SUITE = unittest.TestLoader().loadTestsFromTestCase(test_class)
unittest.TextTestRunner(verbosity=2).run(SUITE)
# coding=utf-8
# This file is part of SickRage.
#
# URL: https://SickRage.GitHub.io
# Git: https://github.com/SickRage/SickRage.git
#
# SickRage is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SickRage is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
"""
Test GenericProvider
"""
from __future__ import print_function
import os
import sys
import unittest
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../lib')))
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..')))
from sickrage.providers.GenericProvider import GenericProvider
class GenericProviderTests(unittest.TestCase):
"""
Test GenericProvider
"""
def test_get_id(self):
"""
Test get_id
"""
test_cases = {
None: '',
123: '123',
12.3: '12_3',
0: '',
-123: '_123',
-12.3: '_12_3',
'': '',
' ': '',
'123': '123',
' 123 ': '123',
'12.3': '12_3',
' 12.3 ': '12_3',
'0': '0',
' 0 ': '0',
'-123': '_123',
' -123 ': '_123',
'-12.3': '_12_3',
' -12.3 ': '_12_3',
'abc': 'abc',
' abc ': 'abc',
'ABC': 'abc',
' ABC ': 'abc',
'.def': '_def',
'g,hi': 'g_hi',
'jk!l': 'jk_l',
'mno?': 'mno_',
'_pqr$': '_pqr_',
}
unicode_test_cases = {
u'': '',
u' ': '',
u'123': '123',
u' 123 ': '123',
u'12.3': '12_3',
u' 12.3 ': '12_3',
u'0': '0',
u' 0 ': '0',
u'-123': '_123',
u' -123 ': '_123',
u'-12.3': '_12_3',
u' -12.3 ': '_12_3',
u'abc': 'abc',
u' abc ': 'abc',
u'ABC': 'abc',
u' ABC ': 'abc',
u'.def': '_def',
u'g,hi': 'g_hi',
u'jk!l': 'jk_l',
u'mno?': 'mno_',
u'_pqr$': '_pqr_',
}
for test in test_cases, unicode_test_cases:
for (name, result) in test.iteritems():
self.assertEqual(GenericProvider(name).get_id(), result)
def test_image_name(self):
"""
Test image_name
"""
test_cases = {
None: '.png',
123: '123.png',
12.3: '12_3.png',
0: '.png',
-123: '_123.png',
-12.3: '_12_3.png',
'': '.png',
' ': '.png',
'123': '123.png',
' 123 ': '123.png',
'12.3': '12_3.png',
' 12.3 ': '12_3.png',
'0': '0.png',
' 0 ': '0.png',
'-123': '_123.png',
' -123 ': '_123.png',
'-12.3': '_12_3.png',
' -12.3 ': '_12_3.png',
'abc': 'abc.png',
' abc ': 'abc.png',
'ABC': 'abc.png',
' ABC ': 'abc.png',
'.def': '_def.png',
'g,hi': 'g_hi.png',
'jk!l': 'jk_l.png',
'mno?': 'mno_.png',
'_pqr$': '_pqr_.png',
}
unicode_test_cases = {
u'': '.png',
u' ': '.png',
u'123': '123.png',
u' 123 ': '123.png',
u'12.3': '12_3.png',
u' 12.3 ': '12_3.png',
u'0': '0.png',
u' 0 ': '0.png',
u'-123': '_123.png',
u' -123 ': '_123.png',
u'-12.3': '_12_3.png',
u' -12.3 ': '_12_3.png',
u'abc': 'abc.png',
u' abc ': 'abc.png',
u'ABC': 'abc.png',
u' ABC ': 'abc.png',
u'.def': '_def.png',
u'g,hi': 'g_hi.png',
u'jk!l': 'jk_l.png',
u'mno?': 'mno_.png',
u'_pqr$': '_pqr_.png',
}
for test in test_cases, unicode_test_cases:
for (name, result) in test.iteritems():
self.assertEqual(GenericProvider(name).image_name(), result)
def test_is_active(self):
"""
Test is_active
"""
self.assertFalse(GenericProvider('Test Provider').is_active())
def test_is_enabled(self):
"""
Test is_enabled
"""
self.assertFalse(GenericProvider('Test Provider').is_enabled())
def test_make_id(self):
"""
Test make_id
"""
test_cases = {
None: '',
123: '123',
12.3: '12_3',
0: '',
-123: '_123',
-12.3: '_12_3',
'': '',
' ': '',
'123': '123',
' 123 ': '123',
'12.3': '12_3',
' 12.3 ': '12_3',
'0': '0',
' 0 ': '0',
'-123': '_123',
' -123 ': '_123',
'-12.3': '_12_3',
' -12.3 ': '_12_3',
'abc': 'abc',
' abc ': 'abc',
'ABC': 'abc',
' ABC ': 'abc',
'.def': '_def',
'g,hi': 'g_hi',
'jk!l': 'jk_l',
'mno?': 'mno_',
'_pqr$': '_pqr_',
}
unicode_test_cases = {
u'': '',
u' ': '',
u'123': '123',
u' 123 ': '123',
u'12.3': '12_3',
u' 12.3 ': '12_3',
u'0': '0',
u' 0 ': '0',
u'-123': '_123',
u' -123 ': '_123',
u'-12.3': '_12_3',
u' -12.3 ': '_12_3',
u'abc': 'abc',
u' abc ': 'abc',
u'ABC': 'abc',
u' ABC ': 'abc',
u'.def': '_def',
u'g,hi': 'g_hi',
u'jk!l': 'jk_l',
u'mno?': 'mno_',
u'_pqr$': '_pqr_',
}
for test in test_cases, unicode_test_cases:
for (name, result) in test.iteritems():
self.assertEqual(GenericProvider.make_id(name), result)
def test_seed_ratio(self):
"""
Test seed_ratio
"""
self.assertEqual(GenericProvider('Test Provider').seed_ratio(), '')
def test__check_auth(self):
"""
Test _check_auth
"""
self.assertTrue(GenericProvider('Test Provider')._check_auth())
def test__do_login(self):
"""
Test _do_login
"""
self.assertTrue(GenericProvider('Test Provider')._do_login())
def test__do_search(self):
"""
Test _do_search
"""
test_cases = {
None: [],
123: [],
12.3: [],
-123: [],
-12.3: [],
'': [],
'123': [],
'12.3': [],
'-123': [],
'-12.3': [],
}
unicode_test_cases = {
u'': [],
u'123': [],
u'12.3': [],
u'-123': [],
u'-12.3': [],
}
for test in test_cases, unicode_test_cases:
for (search_params, result) in test.iteritems():
self.assertEqual(GenericProvider('Test Provider')._do_search(search_params), result)
def test__get_size(self):
"""
Test _get_size
"""
self.assertEqual(GenericProvider('Test Provider')._get_size(None), -1)
def test__get_storage_dir(self):
"""
Test _get_storage_dir
"""
self.assertEqual(GenericProvider('Test Provider')._get_storage_dir(), '')
def test__get_title_and_url(self):
"""
Test _get_title_and_url
"""
items_list = [
None, {}, {'link': None, 'title': None}, {'link': '', 'title': ''},
{'link': 'http://www.google.com/&amp;foo=bar%26tr%3Dtest', 'title': 'Some Title'}
]
results_list = [
('', ''), ('', ''), ('', ''), ('', ''), ('Some.Title', 'http://www.google.com/&foo=bar&tr=test')
]
unicode_items_list = [
{'link': u'', 'title': u''},
{'link': u'http://www.google.com/&amp;foo=bar%26tr%3Dtest', 'title': u'Some Title'}
]
unicode_results_list = [
('', ''), ('Some.Title', 'http://www.google.com/&foo=bar&tr=test')
]
self.assertEqual(
len(items_list), len(results_list),
'Number of parameters (%d) and results (%d) does not match' % (len(items_list), len(results_list))
)
self.assertEqual(
len(unicode_items_list), len(unicode_results_list),
'Number of parameters (%d) and results (%d) does not match' % (
len(unicode_items_list), len(unicode_results_list))
)
for (index, item) in enumerate(items_list):
self.assertEqual(GenericProvider('Test Provider')._get_title_and_url(item), results_list[index])
for (index, item) in enumerate(unicode_items_list):
self.assertEqual(GenericProvider('Test Provider')._get_title_and_url(item), unicode_results_list[index])
def test__verify_download(self):
"""
Test _verify_download
"""
self.assertTrue(GenericProvider('Test Provider')._verify_download())
if __name__ == '__main__':
print('=====> Testing %s' % __file__)
SUITE = unittest.TestLoader().loadTestsFromTestCase(GenericProviderTests)
unittest.TextTestRunner(verbosity=2).run(SUITE)
# coding=utf-8
# This file is part of SickRage.
#
# URL: https://SickRage.GitHub.io
# Git: https://github.com/SickRage/SickRage.git
#
# SickRage is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SickRage is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
"""
Test NZBProvider
"""
from __future__ import print_function
import os
import sys
import unittest
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../lib')))
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..')))
import sickbeard
from generic_provider_tests import GenericProviderTests
from sickrage.providers.GenericProvider import GenericProvider
from sickrage.providers.NZBProvider import NZBProvider
class NZBProviderTests(GenericProviderTests):
"""
Test NZBProvider
"""
def test___init__(self):
"""
Test __init__
"""
self.assertEqual(NZBProvider('Test Provider').provider_type, GenericProvider.NZB)
def test_is_active(self):
"""
Test is_active
"""
test_cases = {
(False, False): False,
(False, None): False,
(False, True): False,
(None, False): False,
(None, None): False,
(None, True): False,
(True, False): False,
(True, None): False,
(True, True): True,
}
for ((use_nzb, enabled), result) in test_cases.iteritems():
sickbeard.USE_NZBS = use_nzb
provider = NZBProvider('Test Provider')
provider.enabled = enabled
self.assertEqual(provider.is_active(), result)
def test__get_size(self):
"""
Test _get_size
"""
items_list = [
None, {}, {'links': None}, {'links': []}, {'links': [{}]},
{'links': [{'length': 1}, {'length': None}, {'length': 3}]},
{'links': [{'length': 1}, {'length': ''}, {'length': 3}]},
{'links': [{'length': 1}, {'length': '0'}, {'length': 3}]},
{'links': [{'length': 1}, {'length': '123'}, {'length': 3}]},
{'links': [{'length': 1}, {'length': '12.3'}, {'length': 3}]},
{'links': [{'length': 1}, {'length': '-123'}, {'length': 3}]},
{'links': [{'length': 1}, {'length': '-12.3'}, {'length': 3}]},
{'links': [{'length': 1}, {'length': 0}, {'length': 3}]},
{'links': [{'length': 1}, {'length': 123}, {'length': 3}]},
{'links': [{'length': 1}, {'length': 12.3}, {'length': 3}]},
{'links': [{'length': 1}, {'length': -123}, {'length': 3}]},
{'links': [{'length': 1}, {'length': -12.3}, {'length': 3}]},
]
results_list = [
-1, -1, -1, -1, -1, -1, -1, 0, 123, -1, -123, -1, 0, 123, 12, -123, -12
]
unicode_items_list = [
{u'links': None}, {u'links': []}, {u'links': [{}]},
{u'links': [{u'length': 1}, {u'length': None}, {u'length': 3}]},
{u'links': [{u'length': 1}, {u'length': u''}, {u'length': 3}]},
{u'links': [{u'length': 1}, {u'length': u'0'}, {u'length': 3}]},
{u'links': [{u'length': 1}, {u'length': u'123'}, {u'length': 3}]},
{u'links': [{u'length': 1}, {u'length': u'12.3'}, {u'length': 3}]},
{u'links': [{u'length': 1}, {u'length': u'-123'}, {u'length': 3}]},
{u'links': [{u'length': 1}, {u'length': u'-12.3'}, {u'length': 3}]},
{u'links': [{u'length': 1}, {u'length': 0}, {u'length': 3}]},
{u'links': [{u'length': 1}, {u'length': 123}, {u'length': 3}]},
{u'links': [{u'length': 1}, {u'length': 12.3}, {u'length': 3}]},
{u'links': [{u'length': 1}, {u'length': -123}, {u'length': 3}]},
{u'links': [{u'length': 1}, {u'length': -12.3}, {u'length': 3}]},
]
unicode_results_list = [
-1, -1, -1, -1, -1, 0, 123, -1, -123, -1, 0, 123, 12, -123, -12
]
self.assertEqual(
len(items_list), len(results_list),
'Number of parameters (%d) and results (%d) does not match' % (len(items_list), len(results_list))
)
self.assertEqual(
len(unicode_items_list), len(unicode_results_list),
'Number of parameters (%d) and results (%d) does not match' % (
len(unicode_items_list), len(unicode_results_list))
)
for (index, item) in enumerate(items_list):
self.assertEqual(NZBProvider('Test Provider')._get_size(item), results_list[index])
for (index, item) in enumerate(unicode_items_list):
self.assertEqual(NZBProvider('Test Provider')._get_size(item), unicode_results_list[index])
def test__get_storage_dir(self):
"""
Test _get_storage_dir
"""
test_cases = [
None, 123, 12.3, '', os.path.join('some', 'path', 'to', 'folder')
]
for nzb_dir in test_cases:
sickbeard.NZB_DIR = nzb_dir
self.assertEqual(NZBProvider('Test Provider')._get_storage_dir(), nzb_dir)
if __name__ == '__main__':
print('=====> Testing %s' % __file__)
SUITE = unittest.TestLoader().loadTestsFromTestCase(NZBProviderTests)
unittest.TextTestRunner(verbosity=2).run(SUITE)
# coding=utf-8
# This file is part of SickRage.
#
# URL: https://SickRage.GitHub.io
# Git: https://github.com/SickRage/SickRage.git
#
# SickRage is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SickRage is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
"""
Test TorrentProvider
"""
from __future__ import print_function
import os
import sys
import unittest
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../lib')))
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../..')))
import sickbeard
from generic_provider_tests import GenericProviderTests
from sickrage.providers.GenericProvider import GenericProvider
from sickrage.providers.TorrentProvider import TorrentProvider
class TorrentProviderTests(GenericProviderTests):
"""
Test TorrentProvider
"""
def test___init__(self):
"""
Test __init__
"""
self.assertEqual(TorrentProvider('Test Provider').provider_type, GenericProvider.TORRENT)
def test_is_active(self):
"""
Test is_active
"""
test_cases = {
(False, False): False,
(False, None): False,
(False, True): False,
(None, False): False,
(None, None): False,
(None, True): False,
(True, False): False,
(True, None): False,
(True, True): True,
}
for ((use_torrents, enabled), result) in test_cases.iteritems():
sickbeard.USE_TORRENTS = use_torrents
provider = TorrentProvider('Test Provider')
provider.enabled = enabled
self.assertEqual(provider.is_active(), result)
def test__get_size(self):
"""
Test _get_size
"""
items_list = [
None, {}, {'size': None}, {'size': ''}, {'size': '0'}, {'size': '123'}, {'size': '12.3'}, {'size': '-123'},
{'size': '-12.3'}, {'size': '1100000'}, {'size': 0}, {'size': 123}, {'size': 12.3}, {'size': -123},
{'size': -12.3}, {'size': 1100000}, [], [None], [1100000], [None, None, None], [None, None, ''],
[None, None, '0'], [None, None, '123'], [None, None, '12.3'], [None, None, '-123'], [None, None, '-12.3'],
[None, None, '1100000'], [None, None, 0], [None, None, 123], [None, None, 12.3], [None, None, -123],
[None, None, -12.3], [None, None, 1100000], (), (None, None, None), (None, None, ''), (None, None, '0'),
(None, None, '123'), (None, None, '12.3'), (None, None, '-123'), (None, None, '-12.3'),
(None, None, '1100000'), '', '0', '123', '12.3', '-123', '-12.3', '1100000', 0, 123, 12.3, -123, -12.3,
1100000
]
results_list = [
-1, -1, -1, -1, 0, 123, -1, -123, -1, 1100000, -1, -1, -1, -1, -1, 1100000, -1, -1, -1, -1, -1, 0, 123, -1,
-123, -1, 1100000, -1, -1, -1, -1, -1, 1100000, -1, -1, -1, 0, 123, -1, -123, -1, 1100000, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1
]
unicode_items_list = [
{u'size': None}, {u'size': u''}, {u'size': u'0'}, {u'size': u'123'}, {u'size': u'12.3'}, {u'size': u'-123'},
{u'size': u'-12.3'}, {u'size': u'1100000'}, {u'size': 0}, {u'size': 123}, {u'size': 12.3}, {u'size': -123},
{u'size': -12.3}, {u'size': 1100000}, [None, None, u''], [None, None, u'0'], [None, None, u'123'],
[None, None, u'12.3'], [None, None, u'-123'], [None, None, u'-12.3'], [None, None, u'1100000'],
(None, None, u''), (None, None, u'0'), (None, None, u'123'), (None, None, u'12.3'), (None, None, u'-123'),
(None, None, u'-12.3'), (None, None, u'1100000'), u'', u'0', u'123', u'12.3', u'-123', u'-12.3', u'1100000'
]
unicode_results_list = [
-1, -1, 0, 123, -1, -123, -1, 1100000, -1, -1, -1, -1, -1, 1100000, -1, 0, 123, -1, -123, -1, 1100000, -1,
0, 123, -1, -123, -1, 1100000, -1, -1, -1, -1, -1, -1, -1
]
self.assertEqual(
len(items_list), len(results_list),
'Number of parameters (%d) and results (%d) does not match' % (len(items_list), len(results_list))
)
self.assertEqual(
len(unicode_items_list), len(unicode_results_list),
'Number of parameters (%d) and results (%d) does not match' % (
len(unicode_items_list), len(unicode_results_list))
)
for (index, item) in enumerate(items_list):
self.assertEqual(TorrentProvider('Test Provider')._get_size(item), results_list[index])
for (index, item) in enumerate(unicode_items_list):
self.assertEqual(TorrentProvider('Test Provider')._get_size(item), unicode_results_list[index])
def test__get_storage_dir(self):
"""
Test _get_storage_dir
"""
test_cases = [
None, 123, 12.3, '', os.path.join('some', 'path', 'to', 'folder')
]
for torrent_dir in test_cases:
sickbeard.TORRENT_DIR = torrent_dir
self.assertEqual(TorrentProvider('Test Provider')._get_storage_dir(), torrent_dir)
if __name__ == '__main__':
print('=====> Testing %s' % __file__)
SUITE = unittest.TestLoader().loadTestsFromTestCase(TorrentProviderTests)
unittest.TextTestRunner(verbosity=2).run(SUITE)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment