def test_link_html_property(): link = Link(uri='http://dahlia.kr/', mimetype='text/html') assert link.html link = Link(uri='http://dahlia.kr/', mimetype='application/xhtml+xml') assert link.html link = Link(uri='http://dahlia.kr/', mimetype='application/xml') assert not link.html
def test_subscription_set_subscribe(subs): feed = Feed(id='urn:earthreader:test:test_subscription_set_subscribe', title=Text(value='Feed title')) feed.links.extend([ Link(uri='http://example.com/index.xml', relation='self', mimetype='application/atom+xml'), Link(uri='http://example.com/', relation='alternate', mimetype='text/html') ]) rv = subs.subscribe(feed, icon_uri='http://example.com/favicon.ico') sub = next(iter(subs)) assert rv is sub assert sub.feed_id == '0691e2f0c3ea1d7fa9da48e14a46ac8077815ad3' assert sub.icon_uri == 'http://example.com/favicon.ico' assert sub.label == 'Feed title' assert sub.feed_uri == 'http://example.com/index.xml' assert sub.alternate_uri == 'http://example.com/' subs.remove(sub) assert not subs feed.links.append( Link(uri='http://example.com/favicon.ico', relation='shortcut icon')) rv = subs.subscribe(feed) assert rv is next(iter(subs)) assert rv == sub
def test_feed_read(fx_feed): feed = fx_feed assert feed.title == Text(value='Example Feed') link = feed.links[0] assert isinstance(link, Link) assert link.relation == 'alternate' assert link.uri == 'http://example.org/' assert len(feed.links) == 1 assert feed.updated_at == datetime.datetime(2003, 12, 13, 18, 30, 2, tzinfo=utc) authors = feed.authors assert isinstance(authors[0], Person) assert authors[0].name == 'John Doe' assert isinstance(authors[1], Person) assert authors[1].name == 'Jane Doe' assert len(feed.authors) == 2 assert feed.id == 'urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6' categories = feed.categories assert isinstance(categories[0], Category) assert categories[0].term == 'technology' assert isinstance(categories[1], Category) assert categories[1].term == 'business' assert len(categories) == 2 assert feed.rights == Text(value='Public Domain') entries = feed.entries assert isinstance(entries[0], Entry) assert entries[0].title == Text(value='Atom-Powered Robots Run Amok') assert (list(entries[0].links) == [ Link(uri='http://example.org/2003/12/13/atom03') ]) assert entries[0].id == 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a' assert entries[0].updated_at == datetime.datetime(2003, 12, 13, 18, 30, 2, tzinfo=utc) assert entries[0].summary == Text(value='Some text.') assert list(entries[0].authors) == [Person(name='Jane Doe')] assert isinstance(entries[1], Entry) assert entries[1].title == Text(value='Danger, Will Robinson!') assert (list( entries[1].links) == [Link(uri='http://example.org/2003/12/13/lost')]) assert entries[1].id == 'urn:uuid:b12f2c10-ffc1-11d9-8cd6-0800200c9a66' assert entries[1].updated_at == datetime.datetime(2003, 12, 13, 18, 30, 2, tzinfo=utc) assert entries[1].summary == Text(value="Don't Panic!") assert len(entries) == 2
def test_link_list_permalink(fx_feed_links): links = fx_feed_links.links other_link = Link(relation='other', uri='http://example.com/') html_link = Link(relation='other', mimetype='text/html', uri='http://example.com/') links.extend([other_link, html_link]) assert links.permalink is links[1] del links[1:3] assert links.permalink is html_link del links[-1] assert links.permalink is links[0] del links[:-1] assert links.permalink is None
def fx_feed_links(fx_feed): fx_feed.links.extend([ Link(relation='alternate', mimetype='text/html', uri='http://example.com/index.html'), Link(relation='alternate', mimetype='text/html', uri='http://example.com/index2.html'), Link(relation='alternate', mimetype='text/xml', uri='http://example.com/index.xml'), Link(relation='alternate', mimetype='application/json', uri='http://example.com/index.json'), Link(relation='alternate', mimetype='text/javascript', uri='http://example.com/index.js'), Link(relation='alternate', mimetype='application/xml+atom', uri='http://example.com/index.atom'), Link(mimetype='application/xml+rss', uri='http://example.com/index.atom'), Link(relation='icon', mimetype='image/png', uri='http://example.com/favicon.png') ]) return fx_feed
def test_link_html_method(): link = Link( uri='http://dahlia.kr/', relation='alternate', ) assert link.__html__() == '<link rel="alternate" href="http://dahlia.kr/">' link = Link(uri='http://dahlia.kr/', relation='alternate', mimetype='text/html', title="Hong Minhee's website", language='en') assert (link.__html__() == '<link rel="alternate" type="text/html" hreflang="en" ' 'href="http://dahlia.kr/" title="Hong Minhee\'s website">')
def test_link_str(): link = Link( uri='http://dahlia.kr/', relation='alternate', mimetype='text/html', title="Hong Minhee's website" ) assert text_type(link) == 'http://dahlia.kr/'
def test_add_as_subscription(subs): feed = Feed(id='urn:earthreader:test:test_subscription_set_subscribe', title=Text(value='Feed title'), links=[ Link(relation='self', mimetype='application/atom+xml', uri='http://example.com/atom.xml') ]) result = CrawlResult('http://example.com/atom.xml', feed, hints={}, icon_url='http://example.com/favicon.ico') sub = result.add_as_subscription(subs) assert len(subs) == 1 assert next(iter(subs)) is sub assert sub.feed_uri == result.url assert sub.label == feed.title.value assert sub.icon_uri == result.icon_url
def test_link_list_favicon(fx_feed_links): links = fx_feed_links.links assert links.favicon is links[-1] links[-1] = Link(relation='shortcut icon', uri='http://example.com/favicon.ico') assert links.favicon is links[-1]