Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 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 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_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_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
def test_subscriptions_generate():
feed1 = mock.MagicMock()
feed2 = mock.MagicMock()
mysubscriptions = Subscriptions()
mysubscriptions.generate([feed1, feed2])
Feed.__init__ = mock.MagicMock(return_value=None)
mysubscriptions._parse_feeds()
assert len(mysubscriptions.feeds) == 2
def test_subscriptions_valid_base():
mysubscriptions = Subscriptions()
Feed.__init__ = mock.MagicMock(return_value=None)
mysubscriptions.load(my_dir + "/subscriptions/valid_base.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 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 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))