我想试用我的应用程序,这是测试代码:
import sys
import pytest
from flask_simplelogin import SimpleLogin
sys.path.insert(1, '')
from app import app as myapp
#---------------------------------------------------
#SETUP
#---------------------------------------------------
myapp.config['SECRET_KEY'] = 'something-secret'
myapp.config['SIMPLELOGIN_USERNAME'] = 'admin'
myapp.config['SIMPLELOGIN_PASSWORD'] = 'secret'
SimpleLogin(myapp)
@pytest.fixture
def app():
return myapp
@pytest.fixture
def setup_url():
return "http://127.0.0.1:8080/"
def login(client):
return client.post("http://127.0.0.1:8080/login", data=dict(
username="admin",
password="secret"
))
#---------------------------------------------------
#TESTS
#---------------------------------------------------
def test_get_list_campagne(client,setup_url):
resp = login(client)
assert resp.status_code==200
resp = client.get("/Campagne")
assert resp.status_code==200
Run Code Online (Sandbox Code Playgroud)
但它返回一个永久重定向,所以我尝试使用属性“follow_redirects=True”:
def login(client):
return client.post("http://127.0.0.1:8080/login", data=dict(
username="admin",
password="taleinfo"
), follow_redirects=True)
Run Code Online (Sandbox Code Playgroud)
但我认为这只是解决问题的一种方法,我认为在那之后我不会登录。
这里的错误:E AssertionError: assert 308 == 200 …