return the proper atom and rss content types for the feeds

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
Brian S. Stephan 2023-12-30 15:31:18 -06:00
parent 575e2ad387
commit 30d6f99c9b
Signed by: bss
GPG Key ID: 3DE06D3180895FCB
2 changed files with 9 additions and 7 deletions

View File

@ -14,7 +14,7 @@ import os
import re
from feedgen.feed import FeedGenerator
from flask import Blueprint, abort
from flask import Blueprint, Response, abort
from flask import current_app as app
from incorporealcms.lib import instance_resource_path_to_request_path, parse_md
@ -61,9 +61,9 @@ def serve_feed(feed_type):
fe.content(content, type='html')
if feed_type == 'atom':
return fg.atom_str(pretty=True)
return Response(fg.atom_str(pretty=True), mimetype='application/atom+xml')
else:
return fg.rss_str(pretty=True)
return Response(fg.rss_str(pretty=True), mimetype='application/rss+xml')
def _generate_feed_id(feed_entry_path):

View File

@ -16,6 +16,7 @@ def test_atom_type_is_200(client):
"""Test that requesting an ATOM feed is found."""
response = client.get('/feed/atom')
assert response.status_code == 200
assert 'application/atom+xml' in response.content_type
print(response.text)
@ -23,6 +24,7 @@ def test_rss_type_is_200(client):
"""Test that requesting an RSS feed is found."""
response = client.get('/feed/rss')
assert response.status_code == 200
assert 'application/rss+xml' in response.content_type
print(response.text)
@ -30,13 +32,13 @@ def test_feed_generator_atom(app):
"""Test the root feed generator."""
with app.test_request_context():
content = serve_feed('atom')
assert b'<id>https://example.com/</id>' in content
assert b'<email>admin@example.com</email>' in content
assert b'<name>Test Name</name>' in content
assert b'<id>https://example.com/</id>' in content.data
assert b'<email>admin@example.com</email>' in content.data
assert b'<name>Test Name</name>' in content.data
def test_feed_generator_rss(app):
"""Test the root feed generator."""
with app.test_request_context():
content = serve_feed('rss')
assert b'<author>admin@example.com (Test Name)</author>' in content
assert b'<author>admin@example.com (Test Name)</author>' in content.data