(test_apps)
| 174 | |
| 175 | |
| 176 | def test_templates_and_static(test_apps): |
| 177 | from blueprintapp import app |
| 178 | |
| 179 | client = app.test_client() |
| 180 | |
| 181 | rv = client.get("/") |
| 182 | assert rv.data == b"Hello from the Frontend" |
| 183 | rv = client.get("/admin/") |
| 184 | assert rv.data == b"Hello from the Admin" |
| 185 | rv = client.get("/admin/index2") |
| 186 | assert rv.data == b"Hello from the Admin" |
| 187 | rv = client.get("/admin/static/test.txt") |
| 188 | assert rv.data.strip() == b"Admin File" |
| 189 | rv.close() |
| 190 | rv = client.get("/admin/static/css/test.css") |
| 191 | assert rv.data.strip() == b"/* nested file */" |
| 192 | rv.close() |
| 193 | |
| 194 | # try/finally, in case other tests use this app for Blueprint tests. |
| 195 | max_age_default = app.config["SEND_FILE_MAX_AGE_DEFAULT"] |
| 196 | try: |
| 197 | expected_max_age = 3600 |
| 198 | if app.config["SEND_FILE_MAX_AGE_DEFAULT"] == expected_max_age: |
| 199 | expected_max_age = 7200 |
| 200 | app.config["SEND_FILE_MAX_AGE_DEFAULT"] = expected_max_age |
| 201 | rv = client.get("/admin/static/css/test.css") |
| 202 | cc = parse_cache_control_header(rv.headers["Cache-Control"]) |
| 203 | assert cc.max_age == expected_max_age |
| 204 | rv.close() |
| 205 | finally: |
| 206 | app.config["SEND_FILE_MAX_AGE_DEFAULT"] = max_age_default |
| 207 | |
| 208 | with app.test_request_context(): |
| 209 | assert ( |
| 210 | flask.url_for("admin.static", filename="test.txt") |
| 211 | == "/admin/static/test.txt" |
| 212 | ) |
| 213 | |
| 214 | with app.test_request_context(): |
| 215 | with pytest.raises(TemplateNotFound) as e: |
| 216 | flask.render_template("missing.html") |
| 217 | assert e.value.name == "missing.html" |
| 218 | |
| 219 | with flask.Flask(__name__).test_request_context(): |
| 220 | assert flask.render_template("nested/nested.txt") == "I'm nested" |
| 221 | |
| 222 | |
| 223 | def test_default_static_max_age(app): |
nothing calls this directly
no test coverage detected