Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用pytest测试我的flask应用程序时,如何修复身份验证头/cookies丢失问题? 导入pytest 导入应用程序 @pytest.u夹具 def client(): application=app.app() client=application.create_app(flask_config_name='testing').test_client() 收益客户 def测试和创建人员(客户): rv=client.post('/api/v1/staff',json={ “姓”:“V”, “名称”:“Vasu”, “角色”:“管理员”, “雇用id”:vasu@rossum.io", “密码”:“字符串”, “电话”:“9848664982”, “电子邮件”:vinthavasu@gmail.com" }) 如果“成功”不在rv数据中: 提出断言错误(rv.数据) @pytest.yield_夹具(scope=“function”) def测试验证登录(客户端): rv=client.post('/api/v1/auth/login',json={ “用户名”:”vasu@rossum.io", “密码”:“字符串”}) 打印(rv.cookie[''u id']) 如果b'Vasu'不在rv数据中: 提出断言错误(rv.数据) def测试列表公司(客户): rv=client.get(“/api/v1/company”) 如果rv.data中没有b“[]”: 提出断言错误(rv.数据) 如果rv.status_代码!=200: 提出断言错误(rv.状态代码) 平台linux——Python 3.6.7、pytest-4.4.1、py-1.8.0、pluggy-0.9.0——/home/vasu/venv sri/bin/python3 cachedir:.pytest\u缓存 rootdir:/home/vasu/Desktop/pytest 插件:xdist-1.28.0、reorder-0.1.1、forked-1.0.2、cov-2.7.1 收集了3个项目 app/api/tests/test\u api.py::test\u get\u api[2019-05-06 09:45:51743]初始化中的信息:已创建模块 [2019-05-06 09:45:51753]初始化中的信息:应用程序已启动 通过 app/api/staff/tests/test\u staff.py::test\u create\u staff[2019-05-06 09:45:51794]初始模块中的信息:已创建模块 [2019-05-06 09:45:51797]初始化中的信息:应用程序已启动 [2019-05-06 09:45:52426]控制器中的信息:创建员工记录:成功 通过 app/api/company/tests/test_company.py::test_list_companys[2019-05-06 09:45:52437]初始模块中的信息:已创建模块 [2019-05-06 09:45:52442]初始化中的信息:应用程序已启动 失败 ============================故障=========== _________________________测试上市公司________________________ 客户= def测试列表公司(客户): rv=client.get(“/api/v1/company”) 如果rv.data中没有b“[]”: >提出断言错误(rv.数据) E断言错误:b'{\n“msg”:“标头或cookie中缺少JWT(缺少cookie\\“访问\u令牌\u cookie\\”;缺少授权标头)”\n}\n app/api/company/tests/test_company.py:4:AssertionError_Flask_Pytest_Jwt Auth - Fatal编程技术网 提出断言错误(rv.数据) E断言错误:b'{\n“msg”:“标头或cookie中缺少JWT(缺少cookie\\“访问\u令牌\u cookie\\”;缺少授权标头)”\n}\n app/api/company/tests/test_company.py:4:AssertionError,flask,pytest,jwt-auth,Flask,Pytest,Jwt Auth" /> 提出断言错误(rv.数据) E断言错误:b'{\n“msg”:“标头或cookie中缺少JWT(缺少cookie\\“访问\u令牌\u cookie\\”;缺少授权标头)”\n}\n app/api/company/tests/test_company.py:4:AssertionError,flask,pytest,jwt-auth,Flask,Pytest,Jwt Auth" />

在使用pytest测试我的flask应用程序时,如何修复身份验证头/cookies丢失问题? 导入pytest 导入应用程序 @pytest.u夹具 def client(): application=app.app() client=application.create_app(flask_config_name='testing').test_client() 收益客户 def测试和创建人员(客户): rv=client.post('/api/v1/staff',json={ “姓”:“V”, “名称”:“Vasu”, “角色”:“管理员”, “雇用id”:vasu@rossum.io", “密码”:“字符串”, “电话”:“9848664982”, “电子邮件”:vinthavasu@gmail.com" }) 如果“成功”不在rv数据中: 提出断言错误(rv.数据) @pytest.yield_夹具(scope=“function”) def测试验证登录(客户端): rv=client.post('/api/v1/auth/login',json={ “用户名”:”vasu@rossum.io", “密码”:“字符串”}) 打印(rv.cookie[''u id']) 如果b'Vasu'不在rv数据中: 提出断言错误(rv.数据) def测试列表公司(客户): rv=client.get(“/api/v1/company”) 如果rv.data中没有b“[]”: 提出断言错误(rv.数据) 如果rv.status_代码!=200: 提出断言错误(rv.状态代码) 平台linux——Python 3.6.7、pytest-4.4.1、py-1.8.0、pluggy-0.9.0——/home/vasu/venv sri/bin/python3 cachedir:.pytest\u缓存 rootdir:/home/vasu/Desktop/pytest 插件:xdist-1.28.0、reorder-0.1.1、forked-1.0.2、cov-2.7.1 收集了3个项目 app/api/tests/test\u api.py::test\u get\u api[2019-05-06 09:45:51743]初始化中的信息:已创建模块 [2019-05-06 09:45:51753]初始化中的信息:应用程序已启动 通过 app/api/staff/tests/test\u staff.py::test\u create\u staff[2019-05-06 09:45:51794]初始模块中的信息:已创建模块 [2019-05-06 09:45:51797]初始化中的信息:应用程序已启动 [2019-05-06 09:45:52426]控制器中的信息:创建员工记录:成功 通过 app/api/company/tests/test_company.py::test_list_companys[2019-05-06 09:45:52437]初始模块中的信息:已创建模块 [2019-05-06 09:45:52442]初始化中的信息:应用程序已启动 失败 ============================故障=========== _________________________测试上市公司________________________ 客户= def测试列表公司(客户): rv=client.get(“/api/v1/company”) 如果rv.data中没有b“[]”: >提出断言错误(rv.数据) E断言错误:b'{\n“msg”:“标头或cookie中缺少JWT(缺少cookie\\“访问\u令牌\u cookie\\”;缺少授权标头)”\n}\n app/api/company/tests/test_company.py:4:AssertionError

在使用pytest测试我的flask应用程序时,如何修复身份验证头/cookies丢失问题? 导入pytest 导入应用程序 @pytest.u夹具 def client(): application=app.app() client=application.create_app(flask_config_name='testing').test_client() 收益客户 def测试和创建人员(客户): rv=client.post('/api/v1/staff',json={ “姓”:“V”, “名称”:“Vasu”, “角色”:“管理员”, “雇用id”:vasu@rossum.io", “密码”:“字符串”, “电话”:“9848664982”, “电子邮件”:vinthavasu@gmail.com" }) 如果“成功”不在rv数据中: 提出断言错误(rv.数据) @pytest.yield_夹具(scope=“function”) def测试验证登录(客户端): rv=client.post('/api/v1/auth/login',json={ “用户名”:”vasu@rossum.io", “密码”:“字符串”}) 打印(rv.cookie[''u id']) 如果b'Vasu'不在rv数据中: 提出断言错误(rv.数据) def测试列表公司(客户): rv=client.get(“/api/v1/company”) 如果rv.data中没有b“[]”: 提出断言错误(rv.数据) 如果rv.status_代码!=200: 提出断言错误(rv.状态代码) 平台linux——Python 3.6.7、pytest-4.4.1、py-1.8.0、pluggy-0.9.0——/home/vasu/venv sri/bin/python3 cachedir:.pytest\u缓存 rootdir:/home/vasu/Desktop/pytest 插件:xdist-1.28.0、reorder-0.1.1、forked-1.0.2、cov-2.7.1 收集了3个项目 app/api/tests/test\u api.py::test\u get\u api[2019-05-06 09:45:51743]初始化中的信息:已创建模块 [2019-05-06 09:45:51753]初始化中的信息:应用程序已启动 通过 app/api/staff/tests/test\u staff.py::test\u create\u staff[2019-05-06 09:45:51794]初始模块中的信息:已创建模块 [2019-05-06 09:45:51797]初始化中的信息:应用程序已启动 [2019-05-06 09:45:52426]控制器中的信息:创建员工记录:成功 通过 app/api/company/tests/test_company.py::test_list_companys[2019-05-06 09:45:52437]初始模块中的信息:已创建模块 [2019-05-06 09:45:52442]初始化中的信息:应用程序已启动 失败 ============================故障=========== _________________________测试上市公司________________________ 客户= def测试列表公司(客户): rv=client.get(“/api/v1/company”) 如果rv.data中没有b“[]”: >提出断言错误(rv.数据) E断言错误:b'{\n“msg”:“标头或cookie中缺少JWT(缺少cookie\\“访问\u令牌\u cookie\\”;缺少授权标头)”\n}\n app/api/company/tests/test_company.py:4:AssertionError,flask,pytest,jwt-auth,Flask,Pytest,Jwt Auth,我使用jwt身份验证在flask restplus中编写了一个程序。为此,我们尝试执行pytest来检查代码的功能。当我尝试时, JWT athentication测试通过,但当我尝试访问JWT athentication安全记录的公司详细信息时,它表示缺少身份验证头/cookie。如果可以,请任何人向我建议解决方案。您可以在测试客户机请求中设置标题。你可以在这里看到一个例子: import pytest import app @pytest.yield_fixture def client(

我使用jwt身份验证在flask restplus中编写了一个程序。为此,我们尝试执行pytest来检查代码的功能。当我尝试时,
JWT athentication测试通过,但当我尝试访问JWT athentication安全记录的公司详细信息时,它表示缺少身份验证头/cookie。如果可以,请任何人向我建议解决方案。

您可以在测试客户机请求中设置标题。你可以在这里看到一个例子:

import pytest
import app

@pytest.yield_fixture
def client():
    application = app.App()
    client = application.create_app(flask_config_name='testing').test_client()
    yield client

def test_create_staff(client):
    rv = client.post('/api/v1/staff', json={
    "surname": "V",
    "name": "Vasu",
    "role": "administrator",
    "employ_id": "vasu@rossum.io",
    "password": "string",
    "phone": "9848664982",
    "email": "vinthavasu@gmail.com"
})
    if b'Successful' not in rv.data:
        raise AssertionError(rv.data)

@pytest.yield_fixture(scope="function")
def test_auth_login(client):
    rv = client.post('/api/v1/auth/login', json={
        "username": "vasu@rossum.io",
        "password": "string"})
    print(rv.cookie['_id'])
    if b'Vasu' not in rv.data:
        raise AssertionError(rv.data)


def test_list_companies(client): 
    rv = client.get('/api/v1/company')
    if b'[]' not in rv.data:
        raise AssertionError(rv.data)
    if rv.status_code != 200:
        raise AssertionError(rv.status_code)


platform linux -- Python 3.6.7, pytest-4.4.1, py-1.8.0, pluggy-0.9.0 -- /home/vasu/venv-sri/bin/python3
cachedir: .pytest_cache
rootdir: /home/vasu/Desktop/pytest
plugins: xdist-1.28.0, reorder-0.1.1, forked-1.0.2, cov-2.7.1
collected 3 items                                                                                                                            

app/api/tests/test_api.py::test_get_api [2019-05-06 09:45:51,743] INFO in __init__: Module created
[2019-05-06 09:45:51,753] INFO in __init__: Application started
PASSED
app/api/staff/tests/test_staff.py::test_create_staff [2019-05-06 09:45:51,794] INFO in __init__: Module created
[2019-05-06 09:45:51,797] INFO in __init__: Application started
[2019-05-06 09:45:52,426] INFO in controller: Creating Staff record : Successful
PASSED
app/api/company/tests/test_company.py::test_list_companies [2019-05-06 09:45:52,437] INFO in __init__: Module created
[2019-05-06 09:45:52,442] INFO in __init__: Application started
FAILED

====================FAILURES ===========
_________________________test_list_companies ________________________

client = <FlaskClient <Flask 'app'>>

    def test_list_companies(client):
        rv = client.get('/api/v1/company')
        if b'[]' not in rv.data:
>           raise AssertionError(rv.data)
E           AssertionError: b'{\n  "msg": "Missing JWT in headers or cookies (Missing cookie \\"access_token_cookie\\"; Missing Authorization Header)"\n}\n'

app/api/company/tests/test_company.py:4: AssertionError