forked from orbit-oss/flask
parent
5b309831ec
commit
025589ee76
63 changed files with 3784 additions and 3459 deletions
|
|
@ -3,14 +3,14 @@ from flask import jsonify, render_template, request
|
|||
from js_example import app
|
||||
|
||||
|
||||
@app.route('/', defaults={'js': 'plain'})
|
||||
@app.route('/<any(plain, jquery, fetch):js>')
|
||||
@app.route("/", defaults={"js": "plain"})
|
||||
@app.route("/<any(plain, jquery, fetch):js>")
|
||||
def index(js):
|
||||
return render_template('{0}.html'.format(js), js=js)
|
||||
return render_template("{0}.html".format(js), js=js)
|
||||
|
||||
|
||||
@app.route('/add', methods=['POST'])
|
||||
@app.route("/add", methods=["POST"])
|
||||
def add():
|
||||
a = request.form.get('a', 0, type=float)
|
||||
b = request.form.get('b', 0, type=float)
|
||||
a = request.form.get("a", 0, type=float)
|
||||
b = request.form.get("b", 0, type=float)
|
||||
return jsonify(result=a + b)
|
||||
|
|
|
|||
|
|
@ -2,29 +2,21 @@ import io
|
|||
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
with io.open('README.rst', 'rt', encoding='utf8') as f:
|
||||
with io.open("README.rst", "rt", encoding="utf8") as f:
|
||||
readme = f.read()
|
||||
|
||||
setup(
|
||||
name='js_example',
|
||||
version='1.0.0',
|
||||
url='http://flask.pocoo.org/docs/patterns/jquery/',
|
||||
license='BSD',
|
||||
maintainer='Pallets team',
|
||||
maintainer_email='contact@palletsprojects.com',
|
||||
description='Demonstrates making Ajax requests to Flask.',
|
||||
name="js_example",
|
||||
version="1.0.0",
|
||||
url="http://flask.pocoo.org/docs/patterns/jquery/",
|
||||
license="BSD",
|
||||
maintainer="Pallets team",
|
||||
maintainer_email="contact@palletsprojects.com",
|
||||
description="Demonstrates making Ajax requests to Flask.",
|
||||
long_description=readme,
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
zip_safe=False,
|
||||
install_requires=[
|
||||
'flask',
|
||||
],
|
||||
extras_require={
|
||||
'test': [
|
||||
'pytest',
|
||||
'coverage',
|
||||
'blinker',
|
||||
],
|
||||
},
|
||||
install_requires=["flask"],
|
||||
extras_require={"test": ["pytest", "coverage", "blinker"]},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import pytest
|
|||
from js_example import app
|
||||
|
||||
|
||||
@pytest.fixture(name='app')
|
||||
@pytest.fixture(name="app")
|
||||
def fixture_app():
|
||||
app.testing = True
|
||||
yield app
|
||||
|
|
|
|||
|
|
@ -3,12 +3,15 @@ import pytest
|
|||
from flask import template_rendered
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('path', 'template_name'), (
|
||||
('/', 'plain.html'),
|
||||
('/plain', 'plain.html'),
|
||||
('/fetch', 'fetch.html'),
|
||||
('/jquery', 'jquery.html'),
|
||||
))
|
||||
@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
|
||||
|
|
@ -17,12 +20,9 @@ def test_index(app, client, path, template_name):
|
|||
client.get(path)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('a', 'b', 'result'), (
|
||||
(2, 3, 5),
|
||||
(2.5, 3, 5.5),
|
||||
(2, None, 2),
|
||||
(2, 'b', 2),
|
||||
))
|
||||
@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
|
||||
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