How to Pact test a dictionary object

问题描述 投票:0回答:0

下面的测试将正确通过,但如果我发布

{"a different key" : 4.56}
的正文,它将失败,因为“键”是预期的。换句话说,字典键是不灵活的,只有浮点值。

我如何定义一个只有字典类型重要的协议,即键必须是字符串,值必须是浮点数? 文档没有说清楚:https://github.com/pact-foundation/pact-python

def test_case_1(pact, client):
   (
      pact.given("object does not exist")
      .upon_receiving("a new post request")
      .with_request(
         "post", 
         "/url/post/endpoint",
         body=Like({"key": 1.23})
      .will_respond_with(200, body={})
   )
   with pact:
      client.post(body={"key": 4.56})
python pact pact-python
© www.soinside.com 2019 - 2024. All rights reserved.