File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 22pytest-cov
33flask-wtf
44flask-sqlalchemy
5+ beautifulsoup4
Original file line number Diff line number Diff line change 1+ import pytest
2+ from bs4 import BeautifulSoup
3+ from flask import Flask , render_template_string
4+
5+
6+ @pytest .fixture
7+ def app ():
8+ app = Flask (__name__ )
9+ app .secret_key = "test"
10+ return app
11+
12+
13+ def test_cdn_integrity (app ):
14+ @app .route ("/" )
15+ def index ():
16+ return render_template_string (
17+ "{{ bootstrap.load_css() }}{{ bootstrap.load_js() }}"
18+ )
19+
20+ client = app .test_client ()
21+ response = client .get ("/" )
22+ html = response .get_data (as_text = True )
23+ soup = BeautifulSoup (html , "html.parser" )
24+
25+ css = soup .find ("link" , rel = "stylesheet" )
26+ js = soup .find ("script" , src = lambda s : s and "bootstrap" in s )
27+
28+ bootstrap = app .extensions ["bootstrap" ]
29+ assert css ["integrity" ] == bootstrap .bootstrap_css_integrity
30+ assert js ["integrity" ] == bootstrap .bootstrap_js_integrity
31+ assert css ["crossorigin" ] == "anonymous"
32+ assert js ["crossorigin" ] == "anonymous"
You can’t perform that action at this time.
0 commit comments