2014-03-10 05:18:05 +00:00
|
|
|
# coding=UTF-8
|
|
|
|
# Author: Dennis Lutter <lad1337@gmail.com>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# This file is part of SickGear.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is free software: you can redistribute it and/or modify
|
2014-03-10 05:18:05 +00:00
|
|
|
# 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.
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is distributed in the hope that it will be useful,
|
2014-03-10 05:18:05 +00:00
|
|
|
# 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
|
2014-11-12 16:43:14 +00:00
|
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-06-09 11:13:00 +00:00
|
|
|
from __future__ import print_function
|
2014-03-10 05:18:05 +00:00
|
|
|
import random
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import test_lib as test
|
|
|
|
|
|
|
|
import sys, os.path
|
|
|
|
|
|
|
|
import sickbeard.search as search
|
|
|
|
import sickbeard
|
|
|
|
from sickbeard.tv import TVEpisode, TVShow
|
|
|
|
import sickbeard.common as c
|
|
|
|
|
2015-08-11 11:51:26 +00:00
|
|
|
tests = {'Dexter': {'a': 1, 'q': c.HD, 's': 5, 'e': [7], 'b': 'Dexter.S05E07.720p.BluRay.X264-REWARD', 'i': ['Dexter.S05E07.720p.BluRay.X264-REWARD', 'Dexter.S05E07.720p.X264-REWARD']},
|
|
|
|
'House': {'a': 1, 'q': c.HD, 's': 4, 'e': [5], 'b': 'House.4x5.720p.BluRay.X264-REWARD', 'i': ['Dexter.S05E04.720p.X264-REWARD', 'House.4x5.720p.BluRay.X264-REWARD']},
|
|
|
|
'Hells Kitchen': {'a': 1, 'q': c.SD, 's': 6, 'e': [14, 15], 'b': 'Hells.Kitchen.s6e14e15.HDTV.XviD-ASAP', 'i': ['Hells.Kitchen.S06E14.HDTV.XviD-ASAP', 'Hells.Kitchen.6x14.HDTV.XviD-ASAP', 'Hells.Kitchen.s6e14e15.HDTV.XviD-ASAP']}
|
2014-03-10 05:18:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def _create_fake_xml(items):
|
|
|
|
xml = '<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:newznab="http://www.newznab.com/DTD/2010/feeds/attributes/" encoding="utf-8"><channel>'
|
|
|
|
for item in items:
|
|
|
|
xml += '<item><title>' + item + '</title>\n'
|
|
|
|
xml += '<link>http://fantasy.com/' + item + '</link></item>'
|
|
|
|
xml += '</channel></rss>'
|
|
|
|
return xml
|
|
|
|
|
|
|
|
|
|
|
|
searchItems = []
|
|
|
|
|
|
|
|
|
|
|
|
class SearchTest(test.SickbeardTestDBCase):
|
|
|
|
|
|
|
|
def _fake_getURL(self, url, headers=None):
|
|
|
|
global searchItems
|
|
|
|
return _create_fake_xml(searchItems)
|
|
|
|
|
|
|
|
def _fake_isActive(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def __init__(self, something):
|
|
|
|
for provider in sickbeard.providers.sortedProviderList():
|
2015-07-13 09:39:20 +00:00
|
|
|
provider.get_url = self._fake_getURL
|
2014-03-10 05:18:05 +00:00
|
|
|
#provider.isActive = self._fake_isActive
|
|
|
|
|
|
|
|
super(SearchTest, self).__init__(something)
|
|
|
|
|
|
|
|
|
|
|
|
def test_generator(tvdbdid, show_name, curData, forceSearch):
|
|
|
|
|
|
|
|
def test(self):
|
|
|
|
global searchItems
|
2015-08-11 11:51:26 +00:00
|
|
|
searchItems = curData['i']
|
2014-04-26 20:12:58 +00:00
|
|
|
show = TVShow(1, tvdbdid)
|
2014-03-10 05:18:05 +00:00
|
|
|
show.name = show_name
|
2015-08-11 11:51:26 +00:00
|
|
|
show.quality = curData['q']
|
2014-03-10 05:18:05 +00:00
|
|
|
show.saveToDB()
|
|
|
|
sickbeard.showList.append(show)
|
2014-04-27 10:31:54 +00:00
|
|
|
episode = None
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2015-08-11 11:51:26 +00:00
|
|
|
for epNumber in curData['e']:
|
|
|
|
episode = TVEpisode(show, curData['s'], epNumber)
|
2014-03-10 05:18:05 +00:00
|
|
|
episode.status = c.WANTED
|
|
|
|
episode.saveToDB()
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
bestResult = search.search_providers(show, episode.season, episode.episode, forceSearch)
|
2014-03-10 05:18:05 +00:00
|
|
|
if not bestResult:
|
2015-08-11 11:51:26 +00:00
|
|
|
self.assertEqual(curData['b'], bestResult)
|
|
|
|
self.assertEqual(curData['b'], bestResult.name) #first is expected, second is choosen one
|
2014-03-10 05:18:05 +00:00
|
|
|
return test
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-06-09 11:13:00 +00:00
|
|
|
print('==================')
|
|
|
|
print('STARTING - Snatch TESTS')
|
|
|
|
print('==================')
|
|
|
|
print('######################################################################')
|
2014-03-10 05:18:05 +00:00
|
|
|
# create the test methods
|
|
|
|
tvdbdid = 1
|
|
|
|
for forceSearch in (True, False):
|
|
|
|
for name, curData in tests.items():
|
2015-08-11 11:51:26 +00:00
|
|
|
if not curData['a']:
|
2014-03-10 05:18:05 +00:00
|
|
|
continue
|
|
|
|
fname = name.replace(' ', '_')
|
|
|
|
if forceSearch:
|
|
|
|
test_name = 'test_manual_%s_%s' % (fname, tvdbdid)
|
|
|
|
else:
|
|
|
|
test_name = 'test_%s_%s' % (fname, tvdbdid)
|
|
|
|
|
|
|
|
test = test_generator(tvdbdid, name, curData, forceSearch)
|
|
|
|
setattr(SearchTest, test_name, test)
|
|
|
|
tvdbdid += 1
|
|
|
|
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(SearchTest)
|
|
|
|
unittest.TextTestRunner(verbosity=2).run(suite)
|