diff --git a/requirements/tests.in b/requirements/tests.in index e2b0472..0edb740 100644 --- a/requirements/tests.in +++ b/requirements/tests.in @@ -2,3 +2,4 @@ pytest pytest-cov flask-wtf flask-sqlalchemy +beautifulsoup4 diff --git a/requirements/tests.txt b/requirements/tests.txt index 2838994..b863001 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -1,10 +1,12 @@ -# SHA1:2bce3613bf781b5318773bbd23ef6330092309f9 +# SHA1:34838a637a8bb69340f90a1de71e46b007e4a5d6 # # This file is autogenerated by pip-compile-multi # To update, run: # # pip-compile-multi # +beautifulsoup4==4.13.4 + # via -r requirements/tests.in blinker==1.8.2 # via flask click==8.1.8 @@ -50,12 +52,16 @@ pytest-cov==5.0.0 # via -r requirements/tests.in sqlalchemy==2.0.38 # via flask-sqlalchemy +soupsieve==2.7 + # via beautifulsoup4 tomli==2.2.1 # via # coverage # pytest typing-extensions==4.12.2 - # via sqlalchemy + # via + # beautifulsoup4 + # sqlalchemy werkzeug==3.0.6 # via flask wtforms==3.1.2 diff --git a/tests/test_bootstrap5/test_integrity.py b/tests/test_bootstrap5/test_integrity.py new file mode 100644 index 0000000..dce9ee3 --- /dev/null +++ b/tests/test_bootstrap5/test_integrity.py @@ -0,0 +1,32 @@ +import pytest +from bs4 import BeautifulSoup +from flask import Flask, render_template_string + + +@pytest.fixture +def app(): + app = Flask(__name__) + app.secret_key = "test" + return app + + +def test_cdn_integrity(app): + @app.route("/") + def index(): + return render_template_string( + "{{ bootstrap.load_css() }}{{ bootstrap.load_js() }}" + ) + + client = app.test_client() + response = client.get("/") + html = response.get_data(as_text=True) + soup = BeautifulSoup(html, "html.parser") + + css = soup.find("link", rel="stylesheet") + js = soup.find("script", src=lambda s: s and "bootstrap" in s) + + bootstrap = app.extensions["bootstrap"] + assert css["integrity"] == bootstrap.bootstrap_css_integrity + assert js["integrity"] == bootstrap.bootstrap_js_integrity + assert css["crossorigin"] == "anonymous" + assert js["crossorigin"] == "anonymous"