目前我正在做一个 Flask 项目,需要做一些测试。
我正在努力的测试是关于 Flask Sessions 的。
我有这样的看法:
@blue_blueprint.route('/dashboard')
"""Invoke dashboard view."""
if 'expires' in session:
if session['expires'] > time.time():
pass
else:
refresh_token()
pass
total_day = revenues_day()
total_month = revenues_month()
total_year = revenues_year()
total_stock_size = stock_size()
total_stock_value = stock_value()
mean_cost = total_stock_value/total_stock_size
return render_template('dashboard.html.j2', total_day=total_day, <br> total_month=total_month, total_year=total_year, total_stock_size=total_stock_size, total_stock_value=total_stock_value, mean_cost=mean_cost)
else:
return redirect(url_for('blue._authorization'))
Run Code Online (Sandbox Code Playgroud)
并进行此测试:
def test_dashboard(client):
with client.session_transaction(subdomain='blue') as session:
session['expires'] = time.time() + 10000
response = client.get('/dashboard', subdomain='blue')
assert response.status_code == 200
Run Code Online (Sandbox Code Playgroud)
我目前的 conftest.py 是:
@pytest.fixture
def app(): …Run Code Online (Sandbox Code Playgroud)