Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ chardet==4.0.0
click==8.1.3
coverage==6.4.2
Flask==2.1.2
flask-talisman==1.0.0
gunicorn==20.1.0
iniconfig==1.1.1
itsdangerous==2.1.2
Expand Down
17 changes: 14 additions & 3 deletions tests/test_integrations/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def test_document_found(client) -> None:
Args:
client (test_client): The test client for the Flask application.
"""
assert client.get("/").status_code == 200
assert client.get(
"/",
follow_redirects=True,
).status_code == 200

def test_document_not_found(client) -> None:
"""
Expand All @@ -37,7 +40,10 @@ def test_document_not_found(client) -> None:
Args:
client (test_client): The test client for the Flask application.
"""
assert client.get("/notfound").status_code == 404
assert client.get(
"/notfound",
follow_redirects=True,
).status_code == 404

@pytest.mark.parametrize("name, content", [
("viewport", "width=device-width, initial-scale=1"),
Expand All @@ -54,4 +60,9 @@ def test_document_meta_element(name: str, content: str, client) -> None:
content (str): The content of the meta element.
client (test_client): The test client for the Flask application.
"""
assert client.get('/').data.decode().find(f"<meta name=\"{name}\" content=\"{content}\">") > 0
assert client.get(
'/',
follow_redirects=True,
).data.decode().find(
f"<meta name=\"{name}\" content=\"{content}\">"
) > 0
10 changes: 8 additions & 2 deletions tests/test_integrations/test_faq.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def test_faq(client):
Args:
client (test_client): The test client.
"""
response = client.get('/faq')
response = client.get(
'/faq',
follow_redirects=True,
)

assert response.status_code == 200
assert 'Frequently Asked Questions' in response.text
Expand All @@ -51,6 +54,9 @@ def test_faq_questions(client, question: str):
client (test_client): The test client.
question (str): The question to test.
"""
response = client.get('/faq')
response = client.get(
'/faq',
follow_redirects=True,
)

assert question in response.text
10 changes: 8 additions & 2 deletions tests/test_snapshots/test_articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def test_article_found(article_slug: str, client) -> None:
article_slug (str): The slug of the article to find.
client (website.app.test_client): The test client for the Flask application.
"""
assert client.get(f"/{article_slug}").status_code == 200
assert client.get(
f"/{article_slug}",
follow_redirects=True,
).status_code == 200

@pytest.mark.parametrize("article_slug", ARTICLE_SLUGS)
def test_article_snapshots(article_slug: str, client, snapshot) -> None:
Expand All @@ -48,7 +51,10 @@ def test_article_snapshots(article_slug: str, client, snapshot) -> None:
snapshot (pytest_snapshot.plugin.Snapshot): The snapshot plugin.
"""
snapshot.snapshot_dir = "tests/snapshots"
html = client.get(f"/{article_slug}").text
html = client.get(
f"/{article_slug}",
follow_redirects=True,
).text
soup = bs4.BeautifulSoup(html, "html.parser")

snapshot.assert_match(
Expand Down
12 changes: 12 additions & 0 deletions website/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,23 @@

import flask
import markdown
from flask_talisman import Talisman

from website.repositories import Repository, blog_repositories

app = flask.Flask(__name__)

csp = {
'default-src': [
'\'self\'',
'cdn.jsdelivr.net',
]

}
Talisman(app, content_security_policy=csp)

app.jinja_env.add_extension('pypugjs.ext.jinja.PyPugJSExtension')

blog_repo = blog_repositories.PostRepository('blog')

@app.route('/')
Expand Down