diff --git a/tests/all_tests.py b/tests/all_tests.py new file mode 100644 index 0000000000000000000000000000000000000000..fc0eac66c0c82436e51d169074b74dc27593b509 --- /dev/null +++ b/tests/all_tests.py @@ -0,0 +1,38 @@ +# coding=UTF-8 +# Author: Dennis Lutter <lad1337@gmail.com> +# URL: http://code.google.com/p/sickbeard/ +# +# This file is part of Sick Beard. +# +# Sick Beard 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. +# +# Sick Beard 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 Sick Beard. If not, see <http://www.gnu.org/licenses/>. + +if __name__ == "__main__": + import glob + import unittest + + test_file_strings = [ x for x in glob.glob('*_tests.py') if not x in __file__] + module_strings = [file_string[0:len(file_string) - 3] for file_string in test_file_strings] + suites = [unittest.defaultTestLoader.loadTestsFromName(file_string) for file_string in module_strings] + testSuite = unittest.TestSuite(suites) + + + print "==================" + print "STARTING - ALL TESTS" + print "==================" + print "this will include" + for includedfiles in test_file_strings: + print "- " + includedfiles + + + text_runner = unittest.TextTestRunner().run(testSuite) diff --git a/tests/db_tests.py b/tests/db_tests.py new file mode 100644 index 0000000000000000000000000000000000000000..55055fd525fe73f895c43ef478c9f8fe691cfe24 --- /dev/null +++ b/tests/db_tests.py @@ -0,0 +1,40 @@ +# coding=UTF-8 +# Author: Dennis Lutter <lad1337@gmail.com> +# URL: http://code.google.com/p/sickbeard/ +# +# This file is part of Sick Beard. +# +# Sick Beard 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. +# +# Sick Beard 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 Sick Beard. If not, see <http://www.gnu.org/licenses/>. + +import unittest +import test_lib as test + + +class DBBasicTests(test.SickbeardTestDBCase): + + def setUp(self): + super(DBBasicTests, self).setUp() + self.db = test.db.DBConnection() + + def test_select(self): + self.db.select("SELECT * FROM tv_episodes WHERE showid = ? AND location != ''", [0000]) + + +if __name__ == '__main__': + print "==================" + print "STARTING - DB TESTS" + print "==================" + print "######################################################################" + suite = unittest.TestLoader().loadTestsFromTestCase(DBBasicTests) + unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/tests/name_parser_tests.py b/tests/name_parser_tests.py index e0fbef52b9a874fe38374c1eb8a8e2456ec8d576..81b6cc75572c1f354bc7f065265857fcf1193618 100644 --- a/tests/name_parser_tests.py +++ b/tests/name_parser_tests.py @@ -10,7 +10,7 @@ from sickbeard.name_parser import parser import sickbeard sickbeard.SYS_ENCODING = 'UTF-8' -DEBUG = VERBOSE = True +DEBUG = VERBOSE = False simple_test_cases = { 'standard': { diff --git a/tests/pp_tests.py b/tests/pp_tests.py new file mode 100644 index 0000000000000000000000000000000000000000..78df8e613472867d4bc4556b942cbe0e901344a0 --- /dev/null +++ b/tests/pp_tests.py @@ -0,0 +1,104 @@ +# coding=UTF-8 +# Author: Dennis Lutter <lad1337@gmail.com> +# URL: http://code.google.com/p/sickbeard/ +# +# This file is part of Sick Beard. +# +# Sick Beard 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. +# +# Sick Beard 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 Sick Beard. If not, see <http://www.gnu.org/licenses/>. + +import random +import unittest + +import test_lib as test + +import sys, os.path + +from sickbeard.postProcessor import PostProcessor +import sickbeard +from sickbeard.tv import TVEpisode, TVShow + + +class PPInitTests(unittest.TestCase): + + def setUp(self): + self.pp = PostProcessor(test.FILEPATH) + + def test_init_file_name(self): + self.assertEqual(self.pp.file_name, test.FILENAME) + + def test_init_folder_name(self): + self.assertEqual(self.pp.folder_name, test.SHOWNAME) + + +class PPPrivateTests(test.SickbeardTestDBCase): + + + def setUp(self): + super(PPPrivateTests, self).setUp() + + sickbeard.showList = [TVShow(0000), TVShow(0001)] + + self.pp = PostProcessor(test.FILEPATH) + self.show_obj = TVShow(0002) + + self.db = test.db.DBConnection() + newValueDict = {"tvdbid": 1002, + "name": test.SHOWNAME, + "description": "description", + "airdate": 1234, + "hasnfo": 1, + "hastbn": 1, + "status": 404, + "location": test.FILEPATH} + controlValueDict = {"showid": 0002, + "season": test.SEASON, + "episode": test.EPISODE} + + # use a custom update/insert method to get the data into the DB + self.db.upsert("tv_episodes", newValueDict, controlValueDict) + + self.ep_obj = TVEpisode(self.show_obj, test.SEASON, test.EPISODE, test.FILEPATH) + + def test__find_ep_destination_folder(self): + self.show_obj.location = test.FILEDIR + self.ep_obj.show.seasonfolders = 1 + sickbeard.SEASON_FOLDERS_FORMAT = 'Season %02d' + calculatedPath = self.pp._find_ep_destination_folder(self.ep_obj) + ecpectedPath = os.path.join(test.FILEDIR, "Season 0" + str(test.SEASON)) + self.assertEqual(calculatedPath, ecpectedPath) + + +class PPBasicTests(test.SickbeardTestDBCase): + def setUp(self): + super(PPBasicTests, self).setUp() + self.pp = PostProcessor(test.FILEPATH) + + @unittest.skip("this test is not fully configured / implmented") + def test_process(self): + self.assertTrue(self.pp.process()) + + +if __name__ == '__main__': + print "==================" + print "STARTING - PostProcessor TESTS" + print "==================" + print "######################################################################" + suite = unittest.TestLoader().loadTestsFromTestCase(PPInitTests) + unittest.TextTestRunner(verbosity=2).run(suite) + print "######################################################################" + suite = unittest.TestLoader().loadTestsFromTestCase(PPPrivateTests) + unittest.TextTestRunner(verbosity=2).run(suite) + print "######################################################################" + suite = unittest.TestLoader().loadTestsFromTestCase(PPBasicTests) + unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/tests/scene_helpers_tests.py b/tests/scene_helpers_tests.py index 36206d646bd68f05d52b9ab7c78216c3b0af2468..fb7e7d200af01f4b07dc524842ec69fd96b2d05e 100644 --- a/tests/scene_helpers_tests.py +++ b/tests/scene_helpers_tests.py @@ -1,4 +1,5 @@ import unittest +import test_lib as test import sys, os.path sys.path.append(os.path.abspath('..')) @@ -8,26 +9,25 @@ from sickbeard import show_name_helpers, scene_exceptions, common, name_cache import sickbeard from sickbeard import db from sickbeard.databases import cache_db +from sickbeard.tv import TVShow as Show -class Show: - def __init__(self, name, tvdbid, tvrname): - self.name = name - self.tvdbid = tvdbid - self.tvrname = tvrname -class SceneTests(unittest.TestCase): - +class SceneTests(test.SickbeardTestDBCase): + def _test_sceneToNormalShowNames(self, name, expected): result = show_name_helpers.sceneToNormalShowNames(name) self.assertTrue(len(set(expected).intersection(set(result))) == len(expected)) - dot_result = show_name_helpers.sceneToNormalShowNames(name.replace(' ','.')) - dot_expected = [x.replace(' ','.') for x in expected] + dot_result = show_name_helpers.sceneToNormalShowNames(name.replace(' ', '.')) + dot_expected = [x.replace(' ', '.') for x in expected] self.assertTrue(len(set(dot_expected).intersection(set(dot_result))) == len(dot_expected)) - + def _test_allPossibleShowNames(self, name, tvdbid=0, tvrname=None, expected=[]): - - result = show_name_helpers.allPossibleShowNames(Show(name, tvdbid, tvrname)) + s = Show(tvdbid) + s.name = name + s.tvrname = tvrname + + result = show_name_helpers.allPossibleShowNames(s) self.assertTrue(len(set(expected).intersection(set(result))) == len(expected)) def _test_filterBadReleases(self, name, expected): @@ -38,14 +38,20 @@ class SceneTests(unittest.TestCase): self.assertTrue(show_name_helpers.isGoodResult(name, show)) def test_isGoodName(self): - self._test_isGoodName('Show.Name.S01E02.Test-Test', Show('Show/Name', 0, '')) - self._test_isGoodName('Show.Name.S01E02.Test-Test', Show('Show. Name', 0, '')) - self._test_isGoodName('Show.Name.S01E02.Test-Test', Show('Show- Name', 0, '')) - self._test_isGoodName('Show.Name.Part.IV.Test-Test', Show('Show Name', 0, '')) - self._test_isGoodName('Show.Name.1x02.Test-Test', Show('Show Name', 0, '')) - self._test_isGoodName('Show.Name.S01.Test-Test', Show('Show Name', 0, '')) - self._test_isGoodName('Show.Name.E02.Test-Test', Show('Show: Name', 0, '')) - self._test_isGoodName('Show Name Season 2 Test', Show('Show: Name', 0, '')) + listOfcases = [('Show.Name.S01E02.Test-Test', 'Show/Name'), + ('Show.Name.S01E02.Test-Test', 'Show. Name'), + ('Show.Name.S01E02.Test-Test', 'Show- Name'), + ('Show.Name.Part.IV.Test-Test', 'Show Name'), + ('Show.Name.S01.Test-Test', 'Show Name'), + ('Show.Name.E02.Test-Test', 'Show: Name'), + ('Show Name Season 2 Test', 'Show: Name'), + ] + + for testCase in listOfcases: + scene_name, show_name = testCase + s = Show(0) + s.name = show_name + self._test_isGoodName(scene_name, s) def test_sceneToNormalShowNames(self): self._test_sceneToNormalShowNames('Show Name 2010', ['Show Name 2010', 'Show Name (2010)']) @@ -56,7 +62,7 @@ class SceneTests(unittest.TestCase): self._test_sceneToNormalShowNames('Show and Name 2010', ['Show and Name 2010', 'Show & Name 2010', 'Show and Name (2010)', 'Show & Name (2010)']) self._test_sceneToNormalShowNames('show name us', ['show name us', 'show name (us)']) self._test_sceneToNormalShowNames('Show And Name', ['Show And Name', 'Show & Name']) - + # failure cases self._test_sceneToNormalShowNames('Show Name 90210', ['Show Name 90210']) self._test_sceneToNormalShowNames('Show Name YA', ['Show Name YA']) @@ -66,7 +72,7 @@ class SceneTests(unittest.TestCase): myDB = db.DBConnection("cache.db") myDB.action("INSERT INTO scene_exceptions (tvdb_id, show_name) VALUES (?,?)", [-1, 'Exception Test']) 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', tvrname='TVRage Name', expected=['Show Name', 'TVRage Name']) @@ -77,7 +83,6 @@ class SceneTests(unittest.TestCase): self._test_allPossibleShowNames('Show Name (FCN)', -1, 'TVRage Name', expected=['Show Name (FCN)', 'Show Name (Full Country Name)', 'Exception Test', 'TVRage Name']) def test_filterBadReleases(self): - self._test_filterBadReleases('Show.S02.German.Stuff-Grp', False) self._test_filterBadReleases('Show.S02.Some.Stuff-Core2HD', False) self._test_filterBadReleases('Show.S02.Some.German.Stuff-Grp', False) @@ -85,14 +90,11 @@ class SceneTests(unittest.TestCase): self._test_filterBadReleases('Show.S02.This.Is.German', False) +class SceneExceptionTestCase(test.SickbeardTestDBCase): - -print 'Loading exceptions...', -db.upgradeDatabase(db.DBConnection("cache.db"), cache_db.InitialSchema) -scene_exceptions.retrieve_exceptions() -print 'done.' - -class SceneExceptionTestCase(unittest.TestCase): + def setUp(self): + super(SceneExceptionTestCase, self).setUp() + scene_exceptions.retrieve_exceptions() def test_sceneExceptionsEmpty(self): self.assertEqual(scene_exceptions.get_scene_exceptions(0), []) @@ -104,7 +106,7 @@ class SceneExceptionTestCase(unittest.TestCase): self.assertEqual(scene_exceptions.get_scene_exception_by_name('Babylon5'), 70726) self.assertEqual(scene_exceptions.get_scene_exception_by_name('babylon 5'), 70726) self.assertEqual(scene_exceptions.get_scene_exception_by_name('Carlos 2010'), 164451) - + def test_sceneExceptionByNameEmpty(self): self.assertEqual(scene_exceptions.get_scene_exception_by_name('nothing useful'), None) @@ -112,17 +114,17 @@ class SceneExceptionTestCase(unittest.TestCase): # clear the exceptions myDB = db.DBConnection("cache.db") myDB.action("DELETE FROM scene_exceptions") - + # put something in the cache name_cache.addNameToCache('Cached Name', 0) - + # updating should clear the cache so our previously "Cached Name" won't be in there scene_exceptions.retrieve_exceptions() self.assertEqual(name_cache.retrieveNameFromCache('Cached Name'), None) # 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) @@ -130,7 +132,7 @@ class SceneExceptionTestCase(unittest.TestCase): if __name__ == '__main__': if len(sys.argv) > 1: - suite = unittest.TestLoader().loadTestsFromName('scene_helpers_tests.SceneExceptionTestCase.test_'+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) diff --git a/tests/snatch_tests.py b/tests/snatch_tests.py new file mode 100644 index 0000000000000000000000000000000000000000..6ca7df9280728eccfb911c89c3fb06f0d373bc35 --- /dev/null +++ b/tests/snatch_tests.py @@ -0,0 +1,117 @@ +# coding=UTF-8 +# Author: Dennis Lutter <lad1337@gmail.com> +# URL: http://code.google.com/p/sickbeard/ +# +# This file is part of Sick Beard. +# +# Sick Beard 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. +# +# Sick Beard 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 Sick Beard. If not, see <http://www.gnu.org/licenses/>. + +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 + +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']} + } + + +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 + + +# the real one tries to contact tvdb just stop it from getting more info on the ep +def _fake_specifyEP(self, season, episode): + pass + +TVEpisode.specifyEpisode = _fake_specifyEP + +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(): + provider.getURL = self._fake_getURL + #provider.isActive = self._fake_isActive + + super(SearchTest, self).__init__(something) + + +def test_generator(tvdbdid, show_name, curData, forceSearch): + + def test(self): + global searchItems + searchItems = curData["i"] + show = TVShow(tvdbdid) + show.name = show_name + show.quality = curData["q"] + show.saveToDB() + sickbeard.showList.append(show) + + for epNumber in curData["e"]: + episode = TVEpisode(show, curData["s"], epNumber) + episode.status = c.WANTED + episode.saveToDB() + + bestResult = search.findEpisode(episode, forceSearch) + if not bestResult: + self.assertEqual(curData["b"], bestResult) + self.assertEqual(curData["b"], bestResult.name) #first is expected, second is choosen one + return test + +if __name__ == '__main__': + print "==================" + print "STARTING - Snatch TESTS" + print "==================" + print "######################################################################" + # create the test methods + tvdbdid = 1 + for forceSearch in (True, False): + for name, curData in tests.items(): + if not curData["a"]: + 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) diff --git a/tests/test_lib.py b/tests/test_lib.py new file mode 100644 index 0000000000000000000000000000000000000000..db399fa6c1969d10c705a2549878873ae6130ec3 --- /dev/null +++ b/tests/test_lib.py @@ -0,0 +1,194 @@ +# coding=UTF-8 +# Author: Dennis Lutter <lad1337@gmail.com> +# URL: http://code.google.com/p/sickbeard/ +# +# This file is part of Sick Beard. +# +# Sick Beard 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. +# +# Sick Beard 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 Sick Beard. If not, see <http://www.gnu.org/licenses/>. + +import unittest + +import sqlite3 + +import sys, os.path +sys.path.append(os.path.abspath('..')) +sys.path.append(os.path.abspath('../lib')) + +import sickbeard +import shutil, time +from sickbeard import encodingKludge as ek, providers, tvcache +from sickbeard import db +from sickbeard.databases import mainDB +from sickbeard.databases import cache_db + +#================= +# test globals +#================= +TESTDIR = os.path.abspath('.') +TESTDBNAME = "sickbeard.db" +TESTCACHEDBNAME = "cache.db" + + +SHOWNAME = u"show name" +SEASON = 4 +EPISODE = 2 +FILENAME = u"show name - s0" + str(SEASON) + "e0" + str(EPISODE) + ".mkv" +FILEDIR = os.path.join(TESTDIR, SHOWNAME) +FILEPATH = os.path.join(FILEDIR, FILENAME) + +#sickbeard.logger.sb_log_instance = sickbeard.logger.SBRotatingLogHandler(os.path.join(TESTDIR, 'sickbeard.log'), sickbeard.logger.NUM_LOGS, sickbeard.logger.LOG_SIZE) +sickbeard.logger.SBRotatingLogHandler.log_file = os.path.join(os.path.join(TESTDIR, 'Logs'), 'test_sickbeard.log') + + +#================= +# sickbeard globals +#================= +sickbeard.SYS_ENCODING = 'UTF-8' +sickbeard.showList = [] +sickbeard.QUALITY_DEFAULT = 4 +sickbeard.SEASON_FOLDERS_DEFAULT = 1 +sickbeard.SEASON_FOLDERS_FORMAT = 'Season %02d' + +sickbeard.NAMING_SHOW_NAME = 1 +sickbeard.NAMING_EP_NAME = 1 +sickbeard.NAMING_EP_TYPE = 0 +sickbeard.NAMING_MULTI_EP_TYPE = 1 +sickbeard.NAMING_SEP_TYPE = 0 +sickbeard.NAMING_USE_PERIODS = 0 +sickbeard.NAMING_QUALITY = 0 +sickbeard.NAMING_DATES = 1 + +sickbeard.PROVIDER_ORDER = ["sick_beard_index"] +sickbeard.newznabProviderList = providers.getNewznabProviderList("Sick Beard Index|http://momo.sickbeard.com/||1!!!NZBs.org|http://beta.nzbs.org/||0") +sickbeard.providerList = providers.makeProviderList() + +sickbeard.PROG_DIR = os.path.abspath('..') +sickbeard.DATA_DIR = sickbeard.PROG_DIR +sickbeard.LOG_DIR = os.path.join(TESTDIR, 'Logs') +sickbeard.logger.sb_log_instance.initLogging(False) + +#================= +# dummy functions +#================= +def _dummy_saveConfig(): + return True +# this overrides the sickbeard save_config which gets called during a db upgrade +# this might be considered a hack +mainDB.sickbeard.save_config = _dummy_saveConfig + + +#================= +# test classes +#================= +class SickbeardTestDBCase(unittest.TestCase): + def setUp(self): + sickbeard.showList = [] + setUp_test_db() + setUp_test_episode_file() + + def tearDown(self): + sickbeard.showList = [] + tearDown_test_db() + tearDown_test_episode_file() + + +class TestDBConnection(db.DBConnection, object): + + def __init__(self, dbFileName=TESTDBNAME): + dbFileName = os.path.join(TESTDIR, dbFileName) + super(TestDBConnection, self).__init__(dbFileName) + + +class TestCacheDBConnection(TestDBConnection, object): + + def __init__(self, providerName): + db.DBConnection.__init__(self, os.path.join(TESTDIR, TESTCACHEDBNAME)) + + # Create the table if it's not already there + try: + sql = "CREATE TABLE "+providerName+" (name TEXT, season NUMERIC, episodes TEXT, tvrid NUMERIC, tvdbid NUMERIC, url TEXT, time NUMERIC, quality TEXT);" + self.connection.execute(sql) + self.connection.commit() + except sqlite3.OperationalError, e: + if str(e) != "table "+providerName+" already exists": + raise + + # Create the table if it's not already there + try: + sql = "CREATE TABLE lastUpdate (provider TEXT, time NUMERIC);" + self.connection.execute(sql) + self.connection.commit() + except sqlite3.OperationalError, e: + if str(e) != "table lastUpdate already exists": + raise + +# this will override the normal db connection +sickbeard.db.DBConnection = TestDBConnection +sickbeard.tvcache.CacheDBConnection = TestCacheDBConnection + + +#================= +# test functions +#================= +def setUp_test_db(): + """upgrades the db to the latest version + """ + # upgrading the db + db.upgradeDatabase(db.DBConnection(), mainDB.InitialSchema) + # fix up any db problems + db.sanityCheckDatabase(db.DBConnection(), mainDB.MainSanityCheck) + + #and for cache.b too + db.upgradeDatabase(db.DBConnection("cache.db"), cache_db.InitialSchema) + + +def tearDown_test_db(): + """Deletes the test db + although this seams not to work on my system it leaves me with an zero kb file + """ + # uncomment next line so leave the db intact beween test and at the end + #return False + if os.path.exists(os.path.join(TESTDIR, TESTDBNAME)): + os.remove(os.path.join(TESTDIR, TESTDBNAME)) + if os.path.exists(os.path.join(TESTDIR, TESTCACHEDBNAME)): + os.remove(os.path.join(TESTDIR, TESTCACHEDBNAME)) + +def setUp_test_episode_file(): + if not os.path.exists(FILEDIR): + os.makedirs(FILEDIR) + + f = open(FILEPATH, "w") + f.write("foo bar") + f.close() + + +def tearDown_test_episode_file(): + shutil.rmtree(FILEDIR) + +tearDown_test_db() + +if __name__ == '__main__': + print "==================" + print "Dont call this directly" + print "==================" + print "you might want to call" + + dirList = os.listdir(TESTDIR) + for fname in dirList: + if (fname.find("_test") > 0) and (fname.find("pyc") < 0): + print "- " + fname + + print "==================" + print "or just call all_tests.py" + diff --git a/tests/tv_tests.py b/tests/tv_tests.py new file mode 100644 index 0000000000000000000000000000000000000000..40734dfc0c1e75e3817d3e309dbb85283fd9b278 --- /dev/null +++ b/tests/tv_tests.py @@ -0,0 +1,117 @@ +# coding=UTF-8 +# Author: Dennis Lutter <lad1337@gmail.com> +# URL: http://code.google.com/p/sickbeard/ +# +# This file is part of Sick Beard. +# +# Sick Beard 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. +# +# Sick Beard 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 Sick Beard. If not, see <http://www.gnu.org/licenses/>. + +import random +import unittest +import test_lib as test + +import sickbeard +from sickbeard.tv import TVEpisode, TVShow +from sickbeard import exceptions + + +class TVShowTests(test.SickbeardTestDBCase): + + def setUp(self): + super(TVShowTests, self).setUp() + sickbeard.showList = [] + + def test_init_tvdbid(self): + show = TVShow(0001, "en") + self.assertEqual(show.tvdbid, 0001) + + def test_change_tvdbid(self): + show = TVShow(0001, "en") + show.name = "show name" + show.tvrname = "show name" + show.network = "cbs" + show.genre = "crime" + show.runtime = 40 + show.status = "5" + show.airs = "monday" + show.startyear = 1987 + + show.saveToDB() + show.loadFromDB(skipNFO=True) + + show.tvdbid = 0002 + show.saveToDB() + show.loadFromDB(skipNFO=True) + + self.assertEqual(show.tvdbid, 0002) + + def test_set_name(self): + show = TVShow(0001, "en") + show.name = "newName" + show.saveToDB() + show.loadFromDB(skipNFO=True) + self.assertEqual(show.name, "newName") + + +class TVEpisodeTests(test.SickbeardTestDBCase): + + def setUp(self): + super(TVEpisodeTests, self).setUp() + sickbeard.showList = [] + + def test_init_empty_db(self): + show = TVShow(0001, "en") + ep = TVEpisode(show, 1, 1) + ep.name = "asdasdasdajkaj" + ep.saveToDB() + ep.loadFromDB(1, 1) + self.assertEqual(ep.name, "asdasdasdajkaj") + + +class TVTests(test.SickbeardTestDBCase): + + def setUp(self): + super(TVTests, self).setUp() + sickbeard.showList = [] + + def test_getEpisode(self): + show = TVShow(0001, "en") + show.name = "show name" + show.tvrname = "show name" + show.network = "cbs" + show.genre = "crime" + show.runtime = 40 + show.status = "5" + show.airs = "monday" + show.startyear = 1987 + show.saveToDB() + sickbeard.showList = [show] + #TODO: implement + + +if __name__ == '__main__': + print "==================" + print "STARTING - TV TESTS" + print "==================" + print "######################################################################" + suite = unittest.TestLoader().loadTestsFromTestCase(TVShowTests) + unittest.TextTestRunner(verbosity=2).run(suite) + print "######################################################################" + suite = unittest.TestLoader().loadTestsFromTestCase(TVEpisodeTests) + unittest.TextTestRunner(verbosity=2).run(suite) + print "######################################################################" + suite = unittest.TestLoader().loadTestsFromTestCase(TVTests) + unittest.TextTestRunner(verbosity=2).run(suite) + +