2015-07-25 09:19:46 +00:00
|
|
|
# coding=utf-8
|
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
import unittest
|
|
|
|
import test_lib as test
|
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
import sys
|
|
|
|
import os.path
|
2015-06-04 13:36:38 +00:00
|
|
|
sys.path.insert(1, os.path.abspath('..'))
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
from sickbeard import show_name_helpers, scene_exceptions, common, name_cache
|
|
|
|
|
|
|
|
import sickbeard
|
|
|
|
from sickbeard import db
|
|
|
|
from sickbeard.tv import TVShow as Show
|
|
|
|
|
|
|
|
|
|
|
|
class SceneTests(test.SickbeardTestDBCase):
|
|
|
|
|
2014-10-30 14:40:07 +00:00
|
|
|
def _test_allPossibleShowNames(self, name, indexerid=0, expected=[]):
|
|
|
|
s = Show(1, indexerid)
|
2014-03-10 05:18:05 +00:00
|
|
|
s.name = name
|
|
|
|
|
|
|
|
result = show_name_helpers.allPossibleShowNames(s)
|
|
|
|
self.assertTrue(len(set(expected).intersection(set(result))) == len(expected))
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def _test_pass_wordlist_checks(self, name, expected):
|
|
|
|
result = show_name_helpers.pass_wordlist_checks(name)
|
2014-03-10 05:18:05 +00:00
|
|
|
self.assertEqual(result, expected)
|
|
|
|
|
|
|
|
def test_allPossibleShowNames(self):
|
2015-07-25 09:19:46 +00:00
|
|
|
# common.sceneExceptions[-1] = ['Exception Test']
|
2016-09-04 20:00:44 +00:00
|
|
|
my_db = db.DBConnection()
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db.action('INSERT INTO scene_exceptions (indexer_id, show_name, season) VALUES (?,?,?)', [-1, 'Exception Test', -1])
|
2014-03-10 05:18:05 +00:00
|
|
|
common.countryList['Full Country Name'] = 'FCN'
|
|
|
|
|
|
|
|
self._test_allPossibleShowNames('Show Name', expected=['Show Name'])
|
|
|
|
self._test_allPossibleShowNames('Show Name', -1, expected=['Show Name', 'Exception Test'])
|
|
|
|
self._test_allPossibleShowNames('Show Name FCN', expected=['Show Name FCN', 'Show Name (Full Country Name)'])
|
|
|
|
self._test_allPossibleShowNames('Show Name (FCN)', expected=['Show Name (FCN)', 'Show Name (Full Country Name)'])
|
|
|
|
self._test_allPossibleShowNames('Show Name Full Country Name', expected=['Show Name Full Country Name', 'Show Name (FCN)'])
|
|
|
|
self._test_allPossibleShowNames('Show Name (Full Country Name)', expected=['Show Name (Full Country Name)', 'Show Name (FCN)'])
|
|
|
|
|
2015-09-18 00:06:34 +00:00
|
|
|
def test_pass_wordlist_checks(self):
|
|
|
|
self._test_pass_wordlist_checks('Show.S02.German.Stuff-Grp', False)
|
|
|
|
self._test_pass_wordlist_checks('Show.S02.Some.Stuff-Core2HD', False)
|
|
|
|
self._test_pass_wordlist_checks('Show.S02.Some.German.Stuff-Grp', False)
|
|
|
|
# self._test_pass_wordlist_checks('German.Show.S02.Some.Stuff-Grp', True)
|
|
|
|
self._test_pass_wordlist_checks('Show.S02.This.Is.German', False)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SceneExceptionTestCase(test.SickbeardTestDBCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(SceneExceptionTestCase, self).setUp()
|
2015-05-26 04:32:50 +00:00
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
sickbeard.showList = [Show(1, 79604), Show(1, 251085)]
|
2014-03-10 05:18:05 +00:00
|
|
|
scene_exceptions.retrieve_exceptions()
|
2015-05-26 04:32:50 +00:00
|
|
|
name_cache.buildNameCache()
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def test_sceneExceptionsEmpty(self):
|
|
|
|
self.assertEqual(scene_exceptions.get_scene_exceptions(0), [])
|
|
|
|
|
2015-07-25 09:19:46 +00:00
|
|
|
def test_sceneExceptionsBlack_Lagoon(self):
|
|
|
|
self.assertEqual(sorted(scene_exceptions.get_scene_exceptions(79604)), ['Black-Lagoon'])
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def test_sceneExceptionByName(self):
|
2015-07-25 09:19:46 +00:00
|
|
|
self.assertEqual(scene_exceptions.get_scene_exception_by_name('Black-Lagoon'), [79604, -1])
|
|
|
|
self.assertEqual(scene_exceptions.get_scene_exception_by_name('Black Lagoon: The Second Barrage'), [79604, 2])
|
|
|
|
self.assertEqual(scene_exceptions.get_scene_exception_by_name('Rokka no Yuusha'), [None, None])
|
|
|
|
|
|
|
|
def test_sceneExceptionByNameAnime(self):
|
|
|
|
sickbeard.showList = None
|
|
|
|
sickbeard.showList = [Show(1, 79604), Show(1, 295243)]
|
|
|
|
sickbeard.showList[0].anime = 1
|
|
|
|
sickbeard.showList[1].anime = 1
|
|
|
|
scene_exceptions.retrieve_exceptions()
|
|
|
|
name_cache.buildNameCache()
|
|
|
|
self.assertEqual(scene_exceptions.get_scene_exception_by_name(u'ブラック・ラグーン'), [79604, -1])
|
|
|
|
self.assertEqual(scene_exceptions.get_scene_exception_by_name(u'Burakku Ragūn'), [79604, -1])
|
|
|
|
self.assertEqual(scene_exceptions.get_scene_exception_by_name('Rokka no Yuusha'), [295243, -1])
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def test_sceneExceptionByNameEmpty(self):
|
2015-05-26 04:32:50 +00:00
|
|
|
self.assertEqual(scene_exceptions.get_scene_exception_by_name('nothing useful'), [None, None])
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
def test_sceneExceptionsResetNameCache(self):
|
|
|
|
# clear the exceptions
|
2016-09-04 20:00:44 +00:00
|
|
|
my_db = db.DBConnection()
|
2015-07-25 09:19:46 +00:00
|
|
|
my_db.action('DELETE FROM scene_exceptions')
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
# put something in the cache
|
|
|
|
name_cache.addNameToCache('Cached Name', 0)
|
|
|
|
|
|
|
|
# updating should not clear the cache this time since our exceptions didn't change
|
|
|
|
scene_exceptions.retrieve_exceptions()
|
|
|
|
self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), 0)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
suite = unittest.TestLoader().loadTestsFromName('scene_helpers_tests.SceneExceptionTestCase.test_' + sys.argv[1])
|
|
|
|
unittest.TextTestRunner(verbosity=2).run(suite)
|
|
|
|
else:
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(SceneTests)
|
|
|
|
unittest.TextTestRunner(verbosity=2).run(suite)
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(SceneExceptionTestCase)
|
|
|
|
unittest.TextTestRunner(verbosity=2).run(suite)
|