-
Notifications
You must be signed in to change notification settings - Fork 25
/
test.py
70 lines (50 loc) · 1.31 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from json import loads
from flask import Flask, jsonify
from pytest import fixture
from flask_htmlmin import HTMLMIN
app = Flask(__name__)
app.config['TESTING'] = True
app.config['MINIFY_HTML'] = True
htmlmin = HTMLMIN(app=app)
json_resp = dict(
resp='some unminified json response'
)
html_resp = '''<html>
<style>
.h {
width: 3em
}
</style>
<body>
<h1 style="width: 3em;;">
HTML
</h1>
</body>
</html>'''
@app.route('/')
def html():
return html_resp
@app.route('/json')
def json():
return jsonify(json_resp)
@app.route('/exempt')
@htmlmin.exempt
def exempt():
return html_resp
@fixture
def client():
client = app.test_client()
yield client
def test_html_minify(client):
""" testing HTML minified response """
resp = client.get('/').data
assert b'<html> <style>.h{width:3em}</style><body>\
<h1 style="width:3em"> HTML </h1> </body> </html>' == resp
def test_json_unminifed(client):
""" testing unminified Json response """
resp = client.get('/json').data
assert json_resp == loads(resp)
def test_exempt_routes(client):
""" testing exempt routes """
resp = client.get('/exempt').data
assert resp == html_resp.encode()