forked from orbit-oss/flask
add javascript ajax example
This commit is contained in:
parent
d8bf589d48
commit
fce1885f76
21 changed files with 341 additions and 13 deletions
15
examples/javascript/tests/conftest.py
Normal file
15
examples/javascript/tests/conftest.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import pytest
|
||||
|
||||
from js_example import app
|
||||
|
||||
|
||||
@pytest.fixture(name='app')
|
||||
def fixture_app():
|
||||
app.testing = True
|
||||
yield app
|
||||
app.testing = False
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(app):
|
||||
return app.test_client()
|
||||
28
examples/javascript/tests/test_js_example.py
Normal file
28
examples/javascript/tests/test_js_example.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import pytest
|
||||
|
||||
from flask import template_rendered
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('path', 'template_name'), (
|
||||
('/', 'plain.html'),
|
||||
('/plain', 'plain.html'),
|
||||
('/fetch', 'fetch.html'),
|
||||
('/jquery', 'jquery.html'),
|
||||
))
|
||||
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)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('a', 'b', 'result'), (
|
||||
(2, 3, 5),
|
||||
(2.5, 3, 5.5),
|
||||
(2, None, 2),
|
||||
(2, 'b', 2),
|
||||
))
|
||||
def test_add(client, a, b, result):
|
||||
response = client.post('/add', data={'a': a, 'b': b})
|
||||
assert response.get_json()['result'] == result
|
||||
Loading…
Add table
Add a link
Reference in a new issue