2018-04-13 02:06:02 +08:00
|
|
|
import pytest
|
|
|
|
from flask import template_rendered
|
|
|
|
|
|
|
|
|
2019-05-07 03:39:41 +08:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("path", "template_name"),
|
|
|
|
(
|
2024-11-02 07:44:17 +08:00
|
|
|
("/", "fetch.html"),
|
2022-02-15 02:33:25 +08:00
|
|
|
("/plain", "xhr.html"),
|
2019-05-07 03:39:41 +08:00
|
|
|
("/fetch", "fetch.html"),
|
|
|
|
("/jquery", "jquery.html"),
|
|
|
|
),
|
|
|
|
)
|
2018-04-13 02:06:02 +08:00
|
|
|
def test_index(app, client, path, template_name):
|
|
|
|
def check(sender, template, context):
|
|
|
|
assert template.name == template_name
|
|
|
|
|
|
|
|
with template_rendered.connected_to(check, app):
|
|
|
|
client.get(path)
|
|
|
|
|
|
|
|
|
2019-05-07 03:39:41 +08:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("a", "b", "result"), ((2, 3, 5), (2.5, 3, 5.5), (2, None, 2), (2, "b", 2))
|
|
|
|
)
|
2018-04-13 02:06:02 +08:00
|
|
|
def test_add(client, a, b, result):
|
2019-05-07 03:39:41 +08:00
|
|
|
response = client.post("/add", data={"a": a, "b": b})
|
|
|
|
assert response.get_json()["result"] == result
|