def test_find_episode_file_error( self, files, which_are_videos, file_sizes, expected_exception, stub_listdir, stub_getsize, stub_is_video_file): stub_listdir.return_value = files # files to look for stub_is_video_file.side_effect = which_are_videos stub_getsize.side_effect = file_sizes with pytest.raises(expected_exception): find_episode_file('any dir')
def store(self, episode: Episode): """ Stores the given episode in its respective store directory and renames it to its store filename according to the configurator assigned with the organizer. :param episode: episode to be store. """ downloaded_dir = self.config.episode_downloaded_dir(episode) video_file = videofiles.find_episode_file(downloaded_dir) # create the store directory store_dir = self.config.episode_store_dir(episode) os.makedirs(store_dir, exist_ok=True) # build episode path from its store directory, filename and the video # file extension filename = self.config.episode_filename(episode) extension = os.path.splitext(video_file)[1] complete_filename = filename + extension store_path = os.path.join(store_dir, complete_filename) video_path = os.path.join(downloaded_dir, video_file) # TODO: implement the moving in a separate thread # the move should be done in a separate thread because it will work # as a copy (very slow) if the destination folder is not in the same # filesystem self._move_episode_file(video_path, store_path) # episode must be only marked as STORED after finishing moving the # episode file database = Database(self.database_file) database.set_state(episode, EpisodeState.STORED)
def test_find_episode_file( self, files, which_are_videos, file_sizes, expected, stub_listdir, stub_getsize, stub_is_video_file): stub_listdir.return_value = files # files to look for stub_is_video_file.side_effect = which_are_videos stub_getsize.side_effect = file_sizes assert find_episode_file('any dir') == expected