def test_givenRssFeedWhenVodcastFormatThenEntriesWithVideosContainedAreParsed(self):
        entries = self.rss_feed.entries
        vodcast = parse_video_item(entries[0])

        self.assertEqual(vodcast.title, 'Extra 3 one')
        self.assertEqual(vodcast.url, 'http://media.ndr.de/download/podcasts/extradrei196/TV-20101023-2220-5801.h264.mp4')
        self.assertEqual(vodcast.local_filename, 'TV-20101023-2220-5801.h264.mp4')
        self.assertEqual(vodcast.updated, datetime(2010, 10, 26, 9, 53, 49))
    def test_givenRssWithVodcastsWhenDownloadingThenOnlyNewFilesWillBeDownloaded(self):
        entries = self.rss_feed.entries
        vodcast = parse_video_item(entries[0])
        
        vodcast_downloader = VodcastDownloader()

        self.assertTrue(vodcast_downloader.should_be_downloaded(vodcast, as_local_datetime(datetime(2010, 10, 25, 11, 53, 49))), vodcast.updated)
        self.assertFalse(vodcast_downloader.should_be_downloaded(vodcast, as_local_datetime(datetime(2010, 10, 27, 11, 53, 49))), vodcast.updated)
    def test_reference_data_in_local_time(self):
        entries = self.rss_feed.entries
        vodcast = parse_video_item(entries[0])
        
        vodcast_downloader = VodcastDownloader()

        self.assertEqual(vodcast.updated, datetime(2010, 10, 26, 9, 53, 49))
        berlin = pytz.timezone("Europe/Berlin")
        self.assertTrue(vodcast_downloader.should_be_downloaded(vodcast, berlin.localize(datetime(2010, 10, 26, 10, 53, 49))), vodcast.updated)
    def test_givenVideoUrlWithParametersWhenGeneratingLocalFileThenParametersAreStriped(self):
        entry = type('Entry', (object,), {}) 
        entry.title = 'test_givenVideoUrlWithParametersWhenGeneratingLocalFileThenParametersAreStriped'
        entry.enclosures = (type('Enclosure', (object,), {})  , )
        entry.enclosures[0].type = 'video/mp4'
        entry.enclosures[0].href = 'TV-20101023-2220-5801.h264.mp4?should_be_removed'
        entry.updated_parsed = (2010, 10, 26, 10, 53, 49, 0, 0, 0)
        entry.description = 'for test only'
        vodcast = parse_video_item(entry)

        self.assertEqual(vodcast.local_filename, 'TV-20101023-2220-5801.h264.mp4')
    def test_givenUrlPointingToLocalResourceWhenDownloadedThenContentWillBeStored(self):
        entries = self.rss_feed.entries
        vodcast = parse_video_item(entries[0])
        
        tempdir = tempfile.mkdtemp()

        vodcast_downloader = VodcastDownloader(tempdir)
        
        testfile = self.__create_tempfile('vodcast content')
        
        vodcast.url = 'file://' + testfile.name

        vodcast_downloader.download(vodcast)
        
        self.assertFilePresent(tempdir, vodcast.local_filename, remove_after_check = True)
        
        os.remove(testfile.name)
        os.rmdir(tempdir)