def add_feed(category_id): cursor = Cursor(category_id) url = request.form['url'] try: rq = urllib.request.Request(url) rq.add_header('User-Agent', '{0}/{1}'.format(version.__package__, version.VERSION)) f = urllib.request.urlopen(rq): document = f.read() f.close() except Exception: r = jsonify( error='unreachable-url', message='Cannot connect to given url' ) r.status_code = 400 return r try: feed_links = autodiscovery(document, url) except FeedUrlNotFoundError: r = jsonify( error='unreachable-feed-url', message='Cannot find feed url' ) r.status_code = 400 return r feed_url = feed_links[0].url feed_url, feed, hints = next(iter(crawl([feed_url], 1))) with stage: sub = cursor.subscribe(feed) stage.subscriptions = cursor.subscriptionlist stage.feeds[sub.feed_id] = feed return feeds(category_id)
def test_autodiscovery_atom(): expected = [FeedLink(type="application/atom+xml", url="http://vio.atomtest.com/feed/atom/")] feedlinks = autodiscovery(atom_blog, None) assert feedlinks == expected feed_links, icon_links = AutoDiscovery().find(atom_blog) assert feed_links == expected assert icon_links == []
def add_feed(category_id): stage = get_stage() cursor = Cursor(category_id) url = request.form['url'] try: f = urllib2.urlopen(url) document = f.read() f.close() except Exception: r = jsonify(error='unreachable-url', message='Cannot connect to given url') r.status_code = 400 return r try: feed_links = autodiscovery(document, url) except FeedUrlNotFoundError: r = jsonify(error='unreachable-feed-url', message='Cannot find feed url') r.status_code = 400 return r feed_url = feed_links[0].url feed_url, feed, hints = next(iter(crawl([feed_url], 1))) with stage: sub = cursor.subscribe(feed) stage.subscriptions = cursor.subscriptionlist stage.feeds[sub.feed_id] = feed return feeds(category_id)
def test_autodiscovery_rss2(): expected = [FeedLink(type="application/rss+xml", url="http://vio.rsstest.com/feed/rss/")] feedlinks = autodiscovery(rss_blog, None) assert feedlinks == expected feed_links, icon_links = AutoDiscovery().find(rss_blog) assert feed_links == expected assert icon_links == []
def add_feed(category_id): cursor = Cursor(category_id) url = request.form['url'] try: f = urllib.request.urlopen(url) document = f.read() f.close() except Exception: r = jsonify( error='unreachable-url', message='Cannot connect to given url' ) r.status_code = 400 return r try: feed_links = autodiscovery(document, url) except FeedUrlNotFoundError: r = jsonify( error='unreachable-feed-url', message='Cannot find feed url' ) r.status_code = 400 return r feed_url = feed_links[0].url feed_url, feed, hints = next(iter(crawl([feed_url], 1))) with stage: sub = cursor.subscribe(feed) stage.subscriptions = cursor.subscriptionlist stage.feeds[sub.feed_id] = feed return feeds(category_id)
def test_autodiscovery_with_binary(): expected = [ FeedLink(type='application/rss+xml', url='http://vio.rsstest.com/feed/rss/') ] feedlinks = autodiscovery(binary_rss_blog, None) assert feedlinks == expected feed_links, icon_links = AutoDiscovery().find(binary_rss_blog) assert feed_links == expected assert icon_links == []
def test_autodiscovery_atom(): expected = [ FeedLink(type='application/atom+xml', url='http://vio.atomtest.com/feed/atom/') ] feedlinks = autodiscovery(atom_blog, None) assert feedlinks == expected feed_links, icon_links = AutoDiscovery().find(atom_blog) assert feed_links == expected assert icon_links == []
def test_autodiscovery_rss2(): expected = [ FeedLink(type='application/rss+xml', url='http://vio.rsstest.com/feed/rss/') ] feedlinks = autodiscovery(rss_blog, None) assert feedlinks == expected feed_links, icon_links = AutoDiscovery().find(rss_blog) assert feed_links == expected assert icon_links == []
def test_autodiscovery_with_two_feeds(): expected = [ FeedLink(type="application/atom+xml", url="http://vio.atomtest.com/feed/atom/"), FeedLink(type="application/rss+xml", url="http://vio.rsstest.com/feed/rss/"), ] feed_links = autodiscovery(blog_with_two_feeds, None) assert feed_links == expected feed_links, icon_links = AutoDiscovery().find(blog_with_two_feeds) assert feed_links == expected assert icon_links == ["http://vio.atomtest.com/favicon.ico", "http://vio.atomtest.com/icon.png"]
def test_autodiscovery_with_two_feeds(): expected = [ FeedLink(type='application/atom+xml', url='http://vio.atomtest.com/feed/atom/'), FeedLink(type='application/rss+xml', url='http://vio.rsstest.com/feed/rss/') ] feed_links = autodiscovery(blog_with_two_feeds, None) assert feed_links == expected feed_links, icon_links = AutoDiscovery().find(blog_with_two_feeds) assert feed_links == expected assert icon_links == [ 'http://vio.atomtest.com/favicon.ico', 'http://vio.atomtest.com/icon.png' ]
def test_autodiscovery_with_regex(): class TestHTMLParser(HTMLParser.HTMLParser): def handle_starttag(self, tag, attrs): pass def handle_endtag(self, tag): pass def handle_data(self, data): pass parser = TestHTMLParser() with raises(UnicodeDecodeError): parser.feed(autodiscovery_with_regex) feed_link = autodiscovery(autodiscovery_with_regex, None)[0] feed_link.type == 'application/atom+xml' feed_link.url == 'http://vio.atomtest.com/feed/atom/'
def test_autodiscovery_with_regex(): class TestHTMLParser(HTMLParser.HTMLParser): def handle_starttag(self, tag, attrs): pass def handle_endtag(self, tag): pass def handle_data(self, data): pass parser = TestHTMLParser() with raises(UnicodeDecodeError): parser.feed(autodiscovery_with_regex) feed_link = autodiscovery(autodiscovery_with_regex, None)[0] feed_link.type == "application/atom+xml" feed_link.url == "http://vio.atomtest.com/feed/atom/"
def test_autodiscovery_of_relative_url(): feed_link = autodiscovery(relative_feed_url, 'http://vio.atomtest.com/')[0] assert feed_link.type == 'application/atom+xml' assert feed_link.url == 'http://vio.atomtest.com/feed/atom/'
def test_autodiscovery_when_atom(): feed_link = autodiscovery(atom_xml, 'http://vio.atomtest.com/feed/atom')[0] assert feed_link.type == 'application/atom+xml' assert feed_link.url == 'http://vio.atomtest.com/feed/atom'
def test_autodiscovery_with_no_feed_url(): with raises(FeedUrlNotFoundError): autodiscovery(html_with_no_feed_url, None) feed_links, icon_links = AutoDiscovery().find(html_with_no_feed_url) assert feed_links == icon_links == []
def test_autodiscovery_with_no_feed_url(): with raises(FeedUrlNotFoundError): autodiscovery(html_with_no_feed_url, None)
def test_autodiscovery_when_rss2(): feed_link = autodiscovery(rss_xml, 'http://vio.rsstest.com/feed')[0] assert feed_link.type == 'application/rss+xml' assert feed_link.url == 'http://vio.rsstest.com/feed'
def test_autodiscovery_atom(): feedlink = autodiscovery(atom_blog, None)[0] assert feedlink.type == 'application/atom+xml' assert feedlink.url == 'http://vio.atomtest.com/feed/atom/'
def test_autodiscovery_with_binary(): feedlink = autodiscovery(binary_rss_blog, None)[0] assert feedlink.type == 'application/rss+xml' assert feedlink.url == 'http://vio.rsstest.com/feed/rss/'
def test_autodiscovery_with_two_feeds(): feedlinks = autodiscovery(blog_with_two_feeds, None) assert feedlinks[0].type == 'application/atom+xml' assert feedlinks[0].url == 'http://vio.atomtest.com/feed/atom/' assert feedlinks[1].type == 'application/rss+xml' assert feedlinks[1].url == 'http://vio.rsstest.com/feed/rss/'