def generate_nav_catalog(subsections, is_root=False): links = [] if is_root: links.append({'type': 'application/atom+xml', 'rel': 'self', 'href': reverse('pathagar.books.views.root')}) links.append({'title': 'Home', 'type': 'application/atom+xml', 'rel': 'start', 'href': reverse('pathagar.books.views.root')}) feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \ atom_id = 'pathagar:full-catalog', subtitle = \ 'OPDS catalog for the Pathagar book server', \ extra_attrs = ATTRS, hide_generator=True, links=links) for subsec in subsections: feed.add_item(subsec['id'], subsec['title'], subsec['updated'], links=subsec['links']) s = StringIO() feed.write(s, 'UTF-8') return s.getvalue()
def generate_catalog(request, page_obj): attrs = {} attrs[u'xmlns:dcterms'] = u'http://purl.org/dc/terms/' attrs[u'xmlns:opds'] = u'http://opds-spec.org/' attrs[u'xmlns:dc'] = u'http://purl.org/dc/elements/1.1/' attrs[u'xmlns:opensearch'] = 'http://a9.com/-/spec/opensearch/1.1/' links = [] if page_obj.has_previous(): previous_page = page_obj.previous_page_number() links.append({'title': 'Previous results', 'type': 'application/atom+xml', 'rel': 'previous', 'href': page_qstring(request, previous_page)}) if page_obj.has_next(): next_page = page_obj.next_page_number() links.append({'title': 'Next results', 'type': 'application/atom+xml', 'rel': 'next', 'href': page_qstring(request, next_page)}) feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \ atom_id = 'pathagar:full-catalog', subtitle = \ 'OPDS catalog for the Pathagar book server', \ extra_attrs = attrs, hide_generator=True, links=links) for book in page_obj.object_list: if book.cover_img: linklist = [{'rel': \ 'http://opds-spec.org/acquisition', 'href': \ reverse('pathagar.books.views.download_book', kwargs=dict(book_id=book.pk)), 'type': __get_mimetype(book)}, {'rel': \ 'http://opds-spec.org/cover', 'href': \ book.cover_img.url }] else: linklist = [{'rel': \ 'http://opds-spec.org/acquisition', 'href': \ reverse('pathagar.books.views.download_book', kwargs=dict(book_id=book.pk)), 'type': __get_mimetype(book)}] add_kwargs = { 'content': book.a_summary, 'links': linklist, 'authors': [{'name' : book.a_author}], 'dc_publisher': book.dc_publisher, 'dc_issued': book.dc_issued, 'dc_identifier': book.dc_identifier, } if book.dc_language is not None: add_kwargs['dc_language'] = book.dc_language.code feed.add_item(book.a_id, book.a_title, book.a_updated, **add_kwargs) s = StringIO() feed.write(s, 'UTF-8') return s.getvalue()
def generate_catalog(books, q=None): attrs = {} attrs[u'xmlns:dcterms'] = u'http://purl.org/dc/terms/' attrs[u'xmlns:opds'] = u'http://opds-spec.org/' attrs[u'xmlns:dc'] = u'http://purl.org/dc/elements/1.1/' attrs[u'xmlns:opensearch'] = 'http://a9.com/-/spec/opensearch/1.1/' links = [] if books.has_previous(): if q: links.append({'title':'Previous results', 'type':'application/atom+xml', \ 'rel':'previous','href':'?page=' + str(books.previous_page_number()) + '&q=' + q }) else: links.append({'title':'Previous results', 'type':'application/atom+xml', \ 'rel':'previous','href':'?page=' + str(books.previous_page_number())}) if books.has_next(): if q: links.append({'title':'Next results', 'type':'application/atom+xml', \ 'rel':'next','href':'?page=' + str(books.next_page_number()) + '&q=' + q }) else: links.append({'title':'Next results', 'type':'application/atom+xml', \ 'rel':'next','href':'?page=' + str(books.next_page_number())}) feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \ atom_id = 'pathagar:full-catalog', subtitle = \ 'OPDS catalog for the Pathagar book server', \ extra_attrs = attrs, hide_generator=True, links=links) for book in books.object_list: if book.cover_img: linklist = [{'rel': \ 'http://opds-spec.org/acquisition', 'href': \ book.file.url, 'type': __get_mimetype(book)}, {'rel': \ 'http://opds-spec.org/cover', 'href': \ book.cover_img.url }] else: linklist = [{'rel': \ 'http://opds-spec.org/acquisition', 'href': \ book.file.url, 'type': __get_mimetype(book)}] feed.add_item(book.a_id, book.a_title, book.a_updated, \ content=book.a_summary, links = linklist, \ authors = [{'name' : book.a_author}], \ dc_language=book.dc_language.code, dc_publisher=book.dc_publisher, \ dc_issued=book.dc_issued, dc_identifier=book.dc_identifier) s = StringIO() feed.write(s, 'UTF-8') return s.getvalue()
def get_feed(self, extra_params=None): if extra_params: try: obj = self.get_object(extra_params.split('/')) except (AttributeError, LookupError): raise LookupError('Feed does not exist') else: obj = None feed = AtomFeed( atom_id = self.__get_dynamic_attr('feed_id', obj), title = self.__get_dynamic_attr('feed_title', obj), updated = self.__get_dynamic_attr('feed_updated', obj), icon = self.__get_dynamic_attr('feed_icon', obj), logo = self.__get_dynamic_attr('feed_logo', obj), rights = self.__get_dynamic_attr('feed_rights', obj), subtitle = self.__get_dynamic_attr('feed_subtitle', obj), authors = self.__get_dynamic_attr('feed_authors', obj, default=[]), categories = self.__get_dynamic_attr('feed_categories', obj, default=[]), contributors = self.__get_dynamic_attr('feed_contributors', obj, default=[]), links = self.__get_dynamic_attr('feed_links', obj, default=[]), extra_attrs = self.__get_dynamic_attr('feed_extra_attrs', obj), hide_generator = self.__get_dynamic_attr('hide_generator', obj, default=False) ) items = self.__get_dynamic_attr('items', obj) if items is None: raise LookupError('Feed has no items field') for item in items: feed.add_item( atom_id = self.__get_dynamic_attr('item_id', item), title = self.__get_dynamic_attr('item_title', item), updated = self.__get_dynamic_attr('item_updated', item), content = self.__get_dynamic_attr('item_content', item), published = self.__get_dynamic_attr('item_published', item), rights = self.__get_dynamic_attr('item_rights', item), source = self.__get_dynamic_attr('item_source', item), summary = self.__get_dynamic_attr('item_summary', item), authors = self.__get_dynamic_attr('item_authors', item, default=[]), categories = self.__get_dynamic_attr('item_categories', item, default=[]), contributors = self.__get_dynamic_attr('item_contributors', item, default=[]), links = self.__get_dynamic_attr('item_links', item, default=[]), extra_attrs = self.__get_dynamic_attr('item_extra_attrs', item, default={}), ) if self.VALIDATE: feed.validate() return feed
def get(self, api_key=None): db = client.articles feed = AtomFeed(title='Articles Feed', link_self='somelink', feed_id='someid', author='NY Media', entries=None) articles = db.articles.find().limit(15) for article in articles: feed.add(article['entryTitle'], unicode(article['excerpt']), content_type='html', author=article.get('authoredBy', ''), url=article['canonicalUrl'], updated=article.get('publishDate', ''), published=article.get('publishDate', '')) return dumps(feed.to_string())
def atom(): feed = AtomFeed(author='postmarketOS bloggers', feed_url=request.url, icon=url_for('logo_svg', _external=True), title='postmarketOS Blog', url=url_for('blog', _external=True)) for year, posts in get_posts(external_links=True).items(): for post in posts: feed.add( content=post['html'], content_type='html', title=post['title'], url=post['url'], # midnight updated=datetime.combine(post['date'], datetime.min.time())) return feed.get_response()
def edge_atom(): feed = AtomFeed(author='postmarketOS', feed_url=request.url, icon=url_for('logo_svg', _external=True), title='Breaking updates in pmOS edge', url=url_for('edge', _external=True)) for year, posts in get_posts(external_links=True, dir=EDGE_CONTENT_DIR).items(): for post in posts: feed.add( content=post['html'], content_type='html', title=post['title'], url=post['url'], # midnight updated=datetime.combine(post['date'], datetime.min.time())) return feed.get_response()
def getFeedFromNode(self, feedNode, gui): feedVersion = feedNode.getAttribute("type") if (feedVersion == "rss"): feed = RssFeed() if (feedVersion == "atom"): feed = AtomFeed() feed.loadFromNode(feedNode, gui) feed.feedVersion = feedVersion return feed
def getFeedFromState(self, feedState, gui): feedVersion = feedState.feedVersion if (feedVersion == "rss"): feed = RssFeed() if (feedVersion == "atom"): feed = AtomFeed() feed.loadFromState(feedState, gui) feed.feedVersion = feedVersion return feed
def generate_nav_catalog(subsections, is_root=False, links=None): if links is None: links = [] if is_root: links.append({'type': 'application/atom+xml;profile=opds-catalog;kind=navigation', 'rel': 'self', 'href': reverse('pathagar.books.views.root')}) links.append({'type': 'application/opensearchdescription+xml', 'rel': 'search', 'href': reverse('opensearch_description') }) links.append({'title': 'Home', 'type': 'application/atom+xml;profile=opds-catalog;kind=navigation', 'rel': 'start', 'href': reverse('root_feed')}) icon = None; if is_root: icon = FEED_ICON_LOCATION feed = AtomFeed(title = FEED_TITLE, atom_id = 'pathagar:full-catalog', subtitle = FEED_DESCRIPTION, extra_attrs = ATTRS, hide_generator=True, links=links, icon=icon) for subsec in subsections: content = None if 'content' in subsec: content = subsec['content'] feed.add_item( subsec['id'], subsec['title'], subsec['updated'], content=content, links=subsec['links'], ) s = StringIO() feed.write(s, 'UTF-8') return s.getvalue()
def generate_nav_catalog(subsections, is_root=False): links = [] if is_root: links.append({ 'type': 'application/atom+xml', 'rel': 'self', 'href': reverse('pathagar.books.views.root') }) links.append({ 'title': 'Home', 'type': 'application/atom+xml', 'rel': 'start', 'href': reverse('pathagar.books.views.root') }) feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \ atom_id = 'pathagar:full-catalog', subtitle = \ 'OPDS catalog for the Pathagar book server', \ extra_attrs = ATTRS, hide_generator=True, links=links) for subsec in subsections: feed.add_item(subsec['id'], subsec['title'], subsec['updated'], links=subsec['links']) s = StringIO() feed.write(s, 'UTF-8') return s.getvalue()
def generate_catalog(request, page_obj): links = [] links.append({'title': 'Home', 'type': 'application/atom+xml', 'rel': 'start', 'href': reverse('root_feed')}) if page_obj.has_previous(): previous_page = page_obj.previous_page_number() links.append( {'title': 'Previous results', 'type': 'application/atom+xml', 'rel': 'previous', 'href': page_qstring(request, previous_page)}) if page_obj.has_next(): next_page = page_obj.next_page_number() links.append({'title': 'Next results', 'type': 'application/atom+xml', 'rel': 'next', 'href': page_qstring(request, next_page)}) feed = AtomFeed(title='Pathagar Bookserver OPDS feed', atom_id='pathagar:full-catalog', subtitle='OPDS catalog for the Pathagar book server', extra_attrs=ATTRS, hide_generator=True, links=links) for book in page_obj.object_list: if book.cover_img: linklist = [{'rel': 'http://opds-spec.org/acquisition', 'href': reverse('book_download', kwargs=dict(book_id=book.pk)), 'type': __get_mimetype(book)}, {'rel': 'http://opds-spec.org/cover', 'href': book.cover_img.url}] else: linklist = [{'rel': 'http://opds-spec.org/acquisition', 'href': reverse('book_download', kwargs=dict(book_id=book.pk)), 'type': __get_mimetype(book)}] add_kwargs = { 'content': book.summary, 'links': linklist, 'authors': [{'name': a.name} for a in book.authors.all()], 'dc_publisher': [p.name for p in book.publishers.all()], 'dc_issued': book.dc_issued, 'dc_identifier': book.dc_identifier, } if book.dc_language is not None: add_kwargs['dc_language'] = book.dc_language.code feed.add_item(book.a_id, book.title, book.a_updated, **add_kwargs) s = StringIO() feed.write(s, 'UTF-8') return s.getvalue()
def generate_catalog(request, page_obj): attrs = {} attrs[u'xmlns:dcterms'] = u'http://purl.org/dc/terms/' attrs[u'xmlns:opds'] = u'http://opds-spec.org/' attrs[u'xmlns:dc'] = u'http://purl.org/dc/elements/1.1/' attrs[u'xmlns:opensearch'] = 'http://a9.com/-/spec/opensearch/1.1/' links = [] if page_obj.has_previous(): previous_page = page_obj.previous_page_number() links.append({ 'title': 'Previous results', 'type': 'application/atom+xml', 'rel': 'previous', 'href': page_qstring(request, previous_page) }) if page_obj.has_next(): next_page = page_obj.next_page_number() links.append({ 'title': 'Next results', 'type': 'application/atom+xml', 'rel': 'next', 'href': page_qstring(request, next_page) }) feed = AtomFeed(title = 'Pathagar Bookserver OPDS feed', \ atom_id = 'pathagar:full-catalog', subtitle = \ 'OPDS catalog for the Pathagar book server', \ extra_attrs = attrs, hide_generator=True, links=links) for book in page_obj.object_list: if book.cover_img: linklist = [{'rel': \ 'http://opds-spec.org/acquisition', 'href': \ reverse('pathagar.books.views.download_book', kwargs=dict(book_id=book.pk)), 'type': __get_mimetype(book)}, {'rel': \ 'http://opds-spec.org/cover', 'href': \ book.cover_img.url }] else: linklist = [{'rel': \ 'http://opds-spec.org/acquisition', 'href': \ reverse('pathagar.books.views.download_book', kwargs=dict(book_id=book.pk)), 'type': __get_mimetype(book)}] add_kwargs = { 'content': book.a_summary, 'links': linklist, 'authors': [{ 'name': book.a_author }], 'dc_publisher': book.dc_publisher, 'dc_issued': book.dc_issued, 'dc_identifier': book.dc_identifier, } if book.dc_language is not None: add_kwargs['dc_language'] = book.dc_language.code feed.add_item(book.a_id, book.a_title, book.a_updated, **add_kwargs) s = StringIO() feed.write(s, 'UTF-8') return s.getvalue()
def test26(self): # content with a src attribute requires there be a summary element too feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'src': 'http://example.com/image.png' }, None), summary='Some Image.') feed.validate()
def test30(self): # Base64 content requires there be a summary element too feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'type': 'image/png' }, '...some base64...'), summary='Some Image.') feed.validate()
def test31(self): # invalid content type feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'type': 'foo' }, '...some foo content...')) self.assertRaises(ValidationError, feed.validate)
def test29(self): # Base64 content requires there be a summary element too feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'type': 'application/xml' }, '...not base64...')) feed.validate()
def generate_catalog(request, page_obj): links = [] links.append({'title': 'Home', 'type': 'application/atom+xml;profile=opds-catalog;kind=navigation', 'rel': 'start', 'href': reverse('pathagar.books.views.root')}) if page_obj.has_previous(): previous_page = page_obj.previous_page_number() links.append({'title': 'Previous results', 'type': 'application/atom+xml;profile=opds-catalog;kind=acquisition', 'rel': 'previous', 'href': request.path + page_qstring(request, previous_page)}) if page_obj.has_next(): next_page = page_obj.next_page_number() links.append({'title': 'Next results', 'type': 'application/atom+xml;profile=opds-catalog;kind=acquisition', 'rel': 'next', 'href': request.path + page_qstring(request, next_page)}) feed = AtomFeed(title = FEED_TITLE, atom_id = 'pathagar:full-catalog', subtitle = FEED_DESCRIPTION, extra_attrs = ATTRS, hide_generator=True, links=links, openSearch_totalResults=page_obj.paginator.count, openSearch_itemsPerPage=page_obj.paginator.num_pages, ) bbparser = fimfic_bbcode.Parser() for book in page_obj.object_list: linklist = [ { 'rel': 'http://opds-spec.org/acquisition', 'href': reverse('pathagar.books.views.download_book', kwargs=dict(book_id=book.pk, filename=book.a_title+".epub" )), 'type': 'application/epub+zip' }, { 'rel': 'http://opds-spec.org/acquisition', 'href': reverse('pathagar.books.views.download_book', kwargs=dict(book_id=book.pk, filename=book.a_title+".mobi" )), 'type': 'application/x-mobipocket-ebook' }, { 'href': book.getOnlineViewingUrl(), }, ] if book.getCoverImageUrl(): # We are stripping everything past the question mark. guess_type fails in some cases otherwise. mimetype, encoding = mimetypes.guess_type( book.getCoverImageUrl().split('?')[0], strict=False ) if mimetype is None: mimetype = 'image/*' linklist.append( { 'rel': 'http://opds-spec.org/image', 'type': mimetype, 'href': book.getCoverImageUrl() }, ) if book.getThumbnailUrl(): # We are stripping everything past the question mark. guess_type fails in some cases otherwise. mimetype, encoding = mimetypes.guess_type( book.getThumbnailUrl().split('?')[0], strict=False ) if mimetype is None: mimetype = 'image/*' linklist.append( { 'rel': 'http://opds-spec.org/image/thumbnail', 'type': mimetype, 'href': book.getThumbnailUrl() }, ) authors = [] for author in book.a_authors.all(): authors.append( { 'name':author.name, 'uri':author.getLink(), }) categories = [] for category in book.a_categories.all(): categories.append(category.category) add_kwargs = { 'summary': book.a_summary, # The Unicode concatenation forces the output of bbparser to Unicode. # bbparser outputs a string instead of Unicode if the input is a empty Unicode/string object 'content': ( {'type':'html'}, u"" + bbparser.format(book.a_content) ), 'links': linklist, 'authors': authors, 'categories': categories, 'published': book.a_published, 'dc_publisher': book.dc_publisher, 'dc_issued': str(book.dc_issued), 'dc_identifier': book.dc_identifier, } if book.dc_language is not None: add_kwargs['dc_language'] = book.dc_language.code feed.add_item( book.getUUID(), book.a_title, book.updated, # A items atom:updated should refer to the time the item was update on THIS server. **add_kwargs ) s = StringIO() feed.write(s, 'UTF-8') return s.getvalue()
def test7(self): # entry summary type one of text, html, xhtml feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', summary=('foo', 'test entry summary'), updated=datetime(2007, 8, 1), content='Some content.') self.assertRaises(ValidationError, feed.validate)
def test1(self): # minimal sunny day feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content='Some content.') feed.validate()
def test23(self): # content with a src attribute must be empty feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'src': 'http://example.com/image.png' }, ''), summary='Some image.') feed.validate()
def test13(self): # an entry can override feed author feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry1_id', title='test entry1 title', updated=datetime(2007, 8, 1), content='Some content.') feed.add_item(atom_id='test_entry2_id', title='test entry2 title', updated=datetime(2007, 8, 1), authors=[{'name': 'Someone Else'}], content='Some content.') feed.validate()
def test12(self): # entry can have author feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1)) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}], content='Some content.') feed.validate()
def test10(self): # source rights type one of text, html, xhtml feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', source={'rights': ('foo', 'test source title')}, updated=datetime(2007, 8, 1), content='Some content.') self.assertRaises(ValidationError, feed.validate)
def test24(self): # content with a src attribute must be empty feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'src': 'http://example.com/image.png' }, "Shouldn't' be here."), summary='Some image.') self.assertRaises(ValidationError, feed.validate)
def test20(self): # entries without a content element must have a link rel="alternate" feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), links=[{'rel': 'alternate', 'href': 'http://example.com/entry/1/'}]) feed.validate()
def test19(self): # entries without a content element must have a link rel="alternate" feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1)) self.assertRaises(ValidationError, feed.validate)
def test32(self): # content with a src attribute can not have a type of text, html or xhtml feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'src': 'http://example.com/image.png', 'type': 'text'}, None), summary='Some Image.') self.assertRaises(ValidationError, feed.validate)
def test22(self): # entries must not contain more than one link rel="alternate" that has the same combination of type and hreflang values feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), links=[{'rel': 'alternate', 'type': 'text/html', 'hreflang': 'en'}, {'rel': 'alternate', 'type': 'text/html', 'hreflang': 'en'}]) self.assertRaises(ValidationError, feed.validate)
def test15(self): # if no feed author, all entries must have author, possibly in a source feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1)) feed.add_item(atom_id='test_entry1_id', title='test entry1 title', updated=datetime(2007, 8, 1), source={'authors': [{'name': 'Someone Else'}]}, content='Some content.') feed.add_item(atom_id='test_entry2_id', title='test entry2 title', updated=datetime(2007, 8, 1), authors=[{'name': 'Someone Else'}], content='Some content.') feed.validate()
def test16(self): # feeds must not contain more than one link rel="alternate" that has the same combination of type and hreflang values feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}], links=[{'rel': 'alternate', 'type': 'text/html', 'hreflang': 'en'}, {'rel': 'alternate', 'type': 'text/html', 'hreflang': 'fr'}]) feed.validate()
def test18(self): # entries without a content element must have a link rel="alternate" feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content='Test content.') feed.validate()
def test14(self): # if no feed author, all entries must have author feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1)) feed.add_item(atom_id='test_entry1_id', title='test entry1 title', updated=datetime(2007, 8, 1), content='Some content.') feed.add_item(atom_id='test_entry2_id', title='test entry2 title', updated=datetime(2007, 8, 1), authors=[{'name': 'Someone Else'}], content='Some content.') self.assertRaises(ValidationError, feed.validate)
def test27(self): # Base64 content requires there be a summary element too feed = AtomFeed(atom_id='test_feed_id', title='test feed title', updated=datetime(2007, 8, 1), authors=[{'name': 'James Tauber'}]) feed.add_item(atom_id='test_entry_id', title='test entry title', updated=datetime(2007, 8, 1), content=({'type': 'image/png' }, '...some base64...')) self.assertRaises(ValidationError, feed.validate)