def test_database_delete_feed(prevent_modification): copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH) mydatabase = Database() assert len(mydatabase.feeds()) == 2 feed = mydatabase.feeds()[0] mydatabase.delete_feed(feed) assert len(mydatabase.feeds()) == 1
def test_database_add_feed(prevent_modification): copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH) mydatabase = Database() myfeed_path = my_dir + "/feeds/valid_basic.xml" myfeed = Feed(file=myfeed_path) assert len(mydatabase.feeds()) == 2 mydatabase.replace_feed(myfeed) assert len(mydatabase.feeds()) == 3
def test_database_from_json(prevent_modification): copyfile(my_dir + "/datafiles/feeds_working", Database.OLD_PATH) mydatabase = Database() feeds = mydatabase.feeds() assert len(feeds) == 2 assert feeds[0].key == "feed key" assert feeds[0].title == "feed title" assert feeds[0].description == "feed description" assert feeds[0].link == "feed link" assert feeds[0].last_build_date == "feed last_build_date" assert feeds[0].copyright == "feed copyright" episodes0 = mydatabase.episodes(feeds[0]) assert episodes0[0].title == "episode title" assert episodes0[0].description == "episode description" assert episodes0[0].link == "episode link" assert episodes0[0].pubdate == "episode pubdate" assert episodes0[0].copyright == "episode copyright" assert episodes0[0].enclosure == "episode enclosure" assert feeds[1].key == "http://feed2_url" assert feeds[1].title == "feed2 title" assert feeds[1].description == "feed2 description" assert feeds[1].link == "feed2 link" assert feeds[1].last_build_date == "feed2 last_build_date" assert feeds[1].copyright == "feed2 copyright" episodes1 = mydatabase.episodes(feeds[1]) assert episodes1[0].title == "episode title" assert episodes1[0].description == "episode description" assert episodes1[0].link == "episode link" assert episodes1[0].pubdate == "episode pubdate" assert episodes1[0].copyright == "episode copyright" assert episodes1[0].enclosure == "episode enclosure"
def test_database_episodes_length(prevent_modification): copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH) mydatabase = Database() feed1 = mydatabase.feeds()[0] feed2 = mydatabase.feeds()[1] assert len(mydatabase.episodes(feed1)) == 1 assert len(mydatabase.episodes(feed2)) == 1
def test_database_feed_episodes(prevent_modification): copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH) mydatabase = Database() feed = mydatabase.feeds()[0] episodes = mydatabase.episodes(feed) for episode in episodes: assert isinstance(episode, Episode)
def test_database_feed(prevent_modification): copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH) mydatabase = Database() feed = mydatabase.feeds()[0] assert isinstance(feed, Feed) assert feed.key == "feed key" assert feed.title == "feed title"
def test_database_delete_feed_and_episode(prevent_modification): copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH) mydatabase = Database() feed = mydatabase.feeds()[0] feed_episode = mydatabase.episodes(feed)[0] mydatabase.delete_feed(feed) feed_episode = mydatabase.episodes(feed) assert len(feed_episode) == 0
def export_subscriptions(path: str, database: Database) -> None: subscriptions = Subscriptions() feeds = database.feeds() subscriptions.generate(feeds) # Save may raise an error, but they are user-friendly enough that we don't # need to catch them here. It's also okay to crash at this point. subscriptions.save(path) print("Exported %d feeds" % len(feeds))
def test_database_replace_queue_with_deleted_episode(display): copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH) mydatabase = Database() myqueue = Queue(display) player1 = mock.MagicMock(spec=Player) feed = mydatabase.feeds()[0] episode = mydatabase.episodes(feed)[0] player1.episode = episode myqueue.add(player1) mydatabase.delete_feed(feed) mydatabase.replace_queue(myqueue) assert len(mydatabase.queue()) == 0
def test_database_reload(prevent_modification, display): mydatabase = Database() myfeed_path = my_dir + "/feeds/valid_basic.xml" myfeed = Feed(file=myfeed_path) real_title = myfeed.title myfeed._title = "fake title" mydatabase.replace_feed(myfeed) display.change_status = mock.MagicMock(name="change_status") mydatabase.reload(display) assert display.change_status.call_count == 2 assert mydatabase.feeds()[0].title == real_title
def test_database_delete_feed_episode_and_progress(prevent_modification): copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH) mydatabase = Database() feed = mydatabase.feeds()[0] feed_episode = mydatabase.episodes(feed)[0] mydatabase.replace_progress(feed_episode, 1000) feed_episode = mydatabase.episodes(feed)[0] assert feed_episode.progress == 1000 mydatabase.replace_progress(feed_episode, 1000) mydatabase.delete_feed(feed) # returns None since nothing was deleted assert mydatabase.delete_progress(feed_episode) is None
def test_database_from_json(prevent_modification): copyfile(my_dir + "/datafiles/feeds_working", Database.OLD_PATH) mydatabase = Database() feeds = mydatabase.feeds() assert len(feeds) == 2 # we don't technically make any assumptions about the order of the feeds if feeds[0].key != "feed key": feeds.reverse() assert feeds[0].key == "feed key" assert feeds[0].title == "feed title" assert feeds[0].description == "feed description" assert feeds[0].link == "feed link" assert feeds[0].last_build_date == "feed last_build_date" assert feeds[0].copyright == "feed copyright" episodes0 = mydatabase.episodes(feeds[0]) assert episodes0[0].title == "episode title" assert episodes0[0].description == "episode description" assert episodes0[0].link == "episode link" assert episodes0[0].pubdate == "episode pubdate" assert episodes0[0].copyright == "episode copyright" assert episodes0[0].enclosure == "episode enclosure" assert not episodes0[0].played assert feeds[1].key == "http://feed2_url" assert feeds[1].title == "feed2 title" assert feeds[1].description == "feed2 description" assert feeds[1].link == "feed2 link" assert feeds[1].last_build_date == "feed2 last_build_date" assert feeds[1].copyright == "feed2 copyright" episodes1 = mydatabase.episodes(feeds[1]) assert episodes1[0].title == "episode title" assert episodes1[0].description == "episode description" assert episodes1[0].link == "episode link" assert episodes1[0].pubdate == "episode pubdate" assert episodes1[0].copyright == "episode copyright" assert episodes1[0].enclosure == "episode enclosure" assert not episodes1[0].played
def test_database_feeds_length(prevent_modification): copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH) mydatabase = Database() assert len(mydatabase.feeds()) == 2