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

Flask GET and POST in two functions - testing

import calculator
import pytest


def test_main_page():
    web = calculator.app.test_client()

    rv = web.get('/')
    assert rv.status == '200 OK'
    assert b'<a href="/calc">calc</a>' == rv.data

def test_calculator_get():
    web = calculator.app.test_client()

    rv = web.get('/calc')
    assert rv.status == '200 OK'
    assert b'<form method="POST" action="/calc"' in rv.data

def test_calculator_post():
    web = calculator.app.test_client()

    rv = web.post('/calc', data={'a': 7, 'b': 11})
    assert rv.status == '200 OK'
    assert b'18.0' == rv.data