Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Calc path

from flask import Flask
app = Flask(__name__)

@app.route("/")
def main():
    return '''
Main<br>
<a href="/user/23">23</a><br>
<a href="/user/42">42</a><br>
<a href="/user/Joe">Joe</a><br>
'''

@app.route("/user/<int:uid>")
def api_info(uid):
    return str(uid)
import pytest
import app

def test_main():
    web = app.app.test_client()

    rv = web.get('/')
    assert rv.status == '200 OK'
    assert 'Main<br>' in rv.data.decode('utf-8')

@pytest.mark.parametrize('uid', ['23', '42'])
def test_user_number(uid):
    web = app.app.test_client()

    rv = web.get(f'/user/{uid}')
    assert rv.status == '200 OK'
    assert rv.data.decode('utf-8') == uid

@pytest.mark.parametrize('uid', ['Joe'])
def test_user_text(uid):
    web = app.app.test_client()

    rv = web.get(f'/user/{uid}')
    assert rv.status == '404 NOT FOUND'
    assert '<title>404 Not Found</title>' in rv.data.decode('utf-8')