예제 #1
0
class TestPinto(unittest.TestCase):
    @classmethod
    def setupClass(self):
        #save original podcasts in memory
        self.orig_podcasts = ConfigParser.ConfigParser()
        self.orig_podcasts.read(config.podcasts_file)
        print(self.orig_podcasts.sections())

    @classmethod
    def tearDownClass(self):
        #restore podcasts file
        os.remove(config.podcasts_file)
        with open(config.podcasts_file, 'wb') as new_file:
            self.orig_podcasts.write(new_file)

    def setUp(self):
        self.pinto = Pinto(config.config_file, config.data_dir,
                           config.download_dir)

    def test_data_dir_created(self):
        assert(os.path.isdir(config.data_dir))

    def test_config_file_created(self):
        assert(os.path.exists(config.config_file))

    def test_list_num_results(self):
        length = len(self.pinto.podcasts_config.sections())
        assert(len(self.pinto.podcasts()) == length)

    def test_add_duplicate_podcast(self):
        assert(not self.pinto.add("TED",
               "http://feeds.feedburner.com/tedtalks_video"))

    def test_add_increments_num_podcasts(self):
        orig_length = len(self.pinto.podcasts_config.sections())
        self.pinto.add("NYTimes Video",
                       "https://www.nytsyn.com/rss/custom_itunes/4")
        assert(len(self.pinto.podcasts()) == orig_length + 1)

    def test_remove_decrements_num_podcasts(self):
        orig_length = len(self.pinto.podcasts_config.sections())
        self.pinto.remove("TheRealNews")
        updated_length = len(self.pinto.podcasts_config.sections())
        assert(updated_length == orig_length-1)

    def test_remove_nonexistent_podcast(self):
        assert(not self.pinto.remove("Imaginary Podcast"))

    def test_download_nonexistent_podcast(self):
        assert(not self.pinto.download("Imaginary Podcast"))
예제 #2
0
 def setUp(self):
     self.pinto = Pinto(config.config_file, config.data_dir,
                        config.download_dir)