def test_subscriptions_broken_no_body(): mysubscriptions = Subscriptions() Feed.__init__ = mock.MagicMock(return_value=None) with pytest.raises(SubscriptionsStructureError): mysubscriptions.load(my_dir + "/subscriptions/broken_no_body.xml") for generated in mysubscriptions.parse(): pass
def test_subscriptions_parse_feedparseerror(): Feed.__init__ = mock.MagicMock(return_value=None) Feed.__init__.side_effect = FeedParseError() mysubscriptions = Subscriptions() mysubscriptions.load(my_dir + "/subscriptions/valid_complete.xml") for generated in mysubscriptions.parse(): assert isinstance(generated[1], FeedParseError)
def test_subscriptions_broken_no_outline(): mysubscriptions = Subscriptions() Feed.__init__ = mock.MagicMock(return_value=None) mysubscriptions.load(my_dir + "/subscriptions/broken_no_outline.xml") count = 0 for generated in mysubscriptions.parse(): count += 1 assert count == 0
def test_subscriptions_valid_no_head(): mysubscriptions = Subscriptions() Feed.__init__ = mock.MagicMock(return_value=None) mysubscriptions.load(my_dir + "/subscriptions/valid_no_head.xml") assert isinstance(mysubscriptions, Subscriptions) Feed.__init__.assert_any_call(url="http://feed1") Feed.__init__.assert_any_call(url="http://feed2") assert Feed.__init__.call_count == 2 assert len(mysubscriptions.feeds) == 2
def test_subscriptions_valid_complete(): mysubscriptions = Subscriptions() Feed.__init__ = mock.MagicMock(return_value=None) mysubscriptions.load(my_dir + "/subscriptions/valid_complete.xml") for generated in mysubscriptions.parse(): pass assert isinstance(mysubscriptions, Subscriptions) Feed.__init__.assert_any_call(url="http://feed1") Feed.__init__.assert_any_call(url="http://feed2") assert Feed.__init__.call_count == 2 assert len(mysubscriptions.feeds) == 2
def import_subscriptions(path: str, database: Database) -> None: subscriptions = Subscriptions() # Load 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.load(path) print("Importing %d feeds..." % len(subscriptions.feeds)) for feed in subscriptions.feeds: database.replace_feed(feed) episodes = feed.parse_episodes() database.replace_episodes(feed, episodes) print("Imported '%s' with %d episodes" % (str(feed), len(episodes)))
def test_subscriptions_save(): temp_fname = my_dir + "/subscriptions/saved_temp.xml" Feed.__init__ = mock.MagicMock(return_value=None) mysubscriptions1 = Subscriptions() mysubscriptions1.load(my_dir + "/subscriptions/valid_complete.xml") mysubscriptions1.save(temp_fname) mysubscriptions2 = Subscriptions() mysubscriptions2.load(my_dir + "/subscriptions/saved_temp.xml") os.remove(temp_fname) tree1 = ElementTree.tostring(mysubscriptions1._tree.getroot()) tree2 = ElementTree.tostring(mysubscriptions2._tree.getroot()) assert tree1 == tree2
def import_subscriptions(path: str, database: Database) -> None: subscriptions = Subscriptions() # Load 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.load(path) for generated in subscriptions.parse(): if isinstance(generated, Feed): feed = generated database.replace_feed(feed) episodes = feed.parse_episodes() database.replace_episodes(feed, episodes) print("Added \"%s\" with %d episodes" % (str(feed), len(episodes))) else: print("ERROR: Failed to load %s -- %s" % (str(generated[0]), str(generated[1]))) print("Imported %d feeds" % len(subscriptions.feeds))
def test_subscriptions_broken_parse(): mysubscriptions = Subscriptions() Feed.__init__ = mock.MagicMock(return_value=None) with pytest.raises(SubscriptionsParseError): mysubscriptions.load(my_dir + "/subscriptions/broken_parse.xml")
def test_subscriptions_broken_nonexistant(): mysubscriptions = Subscriptions() Feed.__init__ = mock.MagicMock(return_value=None) with pytest.raises(SubscriptionsLoadError): mysubscriptions.load(my_dir + "/subscriptions/doesnt_exist")
def test_subscriptions_valid_minimal(): mysubscriptions = Subscriptions() Feed.__init__ = mock.MagicMock(return_value=None) mysubscriptions.load(my_dir + "/subscriptions/valid_minimal.xml") assert isinstance(mysubscriptions, Subscriptions) assert len(mysubscriptions.feeds) == 0