【问题标题】:How can I test Python Eve projections with pytest?如何使用 pytest 测试 Python Eve 预测?
【发布时间】:2020-03-13 12:35:53
【问题描述】:

我正在尝试以某种方式发出获取请求以测试 Eve 的烧瓶客户端:

@pytest.fixture(scope='session')
def client():
    app = a.create_app()
    app.debug = True
    client = app.test_client()
    return client

def animal_mes_id(client):
    #res = client.get('/my_col?where={"_name": "animal"}')
    res = client.get('/my_col', query_string={"_name": "animal"})
    print(res.data)
    return res.data......['_id'] # Schematic way to show I just want to get the _id

我无法通过一种方式,或以下几行中的另一种方式

 #res = client.get('/my_col?where={"_name": "animal"}')
 res = client.get('/my_col', query_string={"_name": "animal"})

传递--data-urlencode 'projection={"_id": 1}',因为它是documented

我尝试过类似的方法:

client.get('/my_col?where={"_name": "animal"} --data-urlencode \'projection={"_id": 1}\'')

【问题讨论】:

    标签: python flask pytest eve


    【解决方案1】:

    没关系,我太傻了。在进一步阅读文档后,我发现了:

    这是解决方案:

    res = client.get('/my_col', query_string='where={"_name": "animal"}&projection={"_id": 1}')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-21
      • 2021-04-02
      • 1970-01-01
      • 2021-09-13
      • 1970-01-01
      • 2019-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多