def test03_illformed_feeds(self): """ Try to add all illformed feeds. """ m = Manager() for url in illformed: self.assertEqual(m.add_site(url, True), None)
def test02_invalid_sites(self): """ Try to add all invalid sites. """ m = Manager() for invalid in invalid_urls: name = m.add_site(invalid[0]) self.assertEqual(name, invalid[1])
def test01_add_sites(self): """ Add all valid sites. """ m = Manager() for valid in valid_urls: m.del_site(valid[0]) name = m.add_site(valid[0]) self.assertEqual(name, valid[1])
def test06_update(self): """ Doesn't update because Last-Modified header is the same than last time. """ m = Manager() m.update_sites(0) sites = m.get_sites() for site in sites: for valid in valid_urls: if site.feed.url == valid[0]: self.assertEqual(site.feed.updated, False)
def test07_update(self): """ Doesn't update or download headers because last time was less than 1 minute ago. """ m = Manager() m.update_sites(1) sites = m.get_sites() for site in sites: for valid in valid_urls: if site.feed.url == valid[0]: self.assertEqual(site.feed.updated, False)
def test00_add_site_as_read(self): """ Add a valid site and mark the last link as read. """ m = Manager() valid = valid_urls[0] m.del_site(valid[0]) name = m.add_site(valid[0], True) self.assertEqual(name, valid[1]) m.update_sites() sites = m.get_sites() for site in sites: if site.feed.url == valid[0]: self.assertEqual(site.feed.last_entrylink, valid[3]) self.assertEqual(site.feed.updated, False) break m.del_site(valid[0])
def test08_mp3blogs(self): """ Getting links from mp3 blogs. """ m = Manager() q = "enclosure_ends=mp3 or embed_ends=mp3 or link_ends=mp3" for blog in mp3blogs: m.del_site(blog[0]) name = m.add_site(blog[0]) if not name: raise AssertionError("Couldn't add feed '%s'." % blog[0]) m.update_sites().filter(q) sites = m.get_sites() for site in sites: if site.feed.url == blog[0]: if len(blog) > 1: self.assertEqual(site.feed.updated, True) entries = site.feed.entries urls = [] for entry in entries: for l in entry.links: urls.append(l) for l in entry.enclosures: urls.append(l) urls = Set(urls) for i in range(1, len(blog)): if not blog[i] in urls: raise AssertionError("1Couldn't find link '%s' in" \ " feed '%s'." % (blog[i], site.feed.url)) for url in urls: print url if not url in blog: raise AssertionError("2Couldn't find link " \ "'%s' in feed '%s'." % (url, blog[0])) m.del_site(blog[0])
def test04_update(self): """ Updates all feeds. """ m = Manager() m.update_sites() sites = m.get_sites() for site in sites: for valid in valid_urls: if site.feed.url == valid[0]: self.assertEqual(site.title, valid[1]) self.assertEqual(site.feed.last_modified, valid[2]) self.assertEqual(site.feed.last_entrylink, valid[3]) self.assertEqual(site.feed.updated, True) for valid in valid_urls: m.del_site(valid[0])
def test05_update(self): """ Updates first 2 feeds. """ m = Manager() m.update_sites(0, 2) sites = m.get_sites() count = 0 for site in sites: for valid in valid_urls: if site.feed.url == valid[0]: print count if count < 2: self.assertEqual(site.feed.updated, True) else: self.assertEqual(site.feed.updated, False) count += 1 for valid in valid_urls: m.del_site(valid[0])
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. See the License for the specific language governing # permissions and limitations under the License. """ Easy examples for using Leolo. """ from leolo.manager import Manager m = Manager() # Add a new subscription name = m.add_site("http://leolo.s3.amazonaws.com/rss_fsf.xml") if not name: m.del_site("http://leolo.s3.amazonaws.com/rss_fsf.xml") exit() print "New site added: " + name print m.display_sites() # print all subscriptions m.update_sites() # search new entries sites = m.get_sites() # get a list of sites for site in sites: print " ================" print " Name: " + site.title
def test11_del_sites(self): m = Manager() self.assertRaises(TypeError, m.del_site, []) self.assertRaises(TypeError, m.del_site, ()) for valid in valid_urls: m.del_site(valid[0])
# coding=utf-8 # Copyright 2010 Rafa Muñoz Cárdenas # # Licensed under the Apache License, Version 2.0 (the "License"); you # may not use this file except in compliance with the License. You # may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. See the License for the specific language governing # permissions and limitations under the License. """ Advanced examples for using Leolo. """ from leolo.manager import Manager m = Manager() # Add a new subscription name = m.add_site("http://leolo.s3.amazonaws.com/rss_django.xml") m.update_sites() # search new entries m.del_site("http://leolo.s3.amazonaws.com/rss_django.xml")