cost 452 ms
在 requests_mock JSON 响应的 URI 端点中间使用通配符 - Using a wildcard in the middle of a URI endpoint for requests_mock JSON responses

我有一些我想测试的代码,它是一个相当普通的 GET 请求包装器,但它的实现使用不同的 ID 多次请求来自 API 的数据。 为测试添加模拟 JSON 响应是有问题的,因为有数百个带有这些 ID 的调用,我们想针对一个固定响应进行测试。 目标 URI 看起来像https://someurl.com/a ...

mock testing REST API如何在没有调用实际API的情况下测试API? - How does mock testing REST APIs test the API when the actual API is not called?

我正在学习对我的 FastAPI 端点使用模拟测试。 我对这个非常基本的问题感到困惑:如果没有进行实际的 HTTP 调用,模拟测试如何实际测试 API 响应? 我知道通过模仿预期的响应,我们可以避免调用实际的 API。但我想测试 API 是否可访问,响应是否正确,并发调用是否受限,是否存在任何其他 ...

在另一个夹具中使用 requests_mock 时,模拟的 URL 不会转发给处理程序 - Mocked URLs not being forward to handler when using requests_mock in another fixture

我正在创建自己的装置来模拟单元测试中所需的服务端点。 为了拦截 HTTP 请求,我使用 requests_mock 如下: 在Endpoint.__init__中,我执行以下操作: 在我的实际测试用例中,我注入端点并对其进行初始化: 实际上,它会初始化模拟端点,如果我在那里设置断点,我会看到Mock ...

使用 request_mock 根据请求动态设置响应 - Using request_mock to dynamically set response based on request

我正在尝试模拟一个简单的 POST 请求,该请求从请求正文创建资源,并返回创建的资源。 为简单起见,我们假设创建的资源与传入的完全相同,但在创建时给出了 ID。 这是我的代码: 我最终得到运行时错误JSONDecodeError('Expecting value: line 1 column 1 ( ...

`requests_mock` 适用于所有请求,即使它们未设置并抛出 NoMockAddress 异常 - `requests_mock` applies to all requests even if they are not set and throws NoMockAddress exception

我发现requests_mock用作pytest的夹具适用于所有请求,即使它们没有设置。 我不确定它是requests_mock / pytest错误还是我遗漏了什么。 最终,我不需要模拟 'api-b' 调用,但我不知道如何避免它。 我正在使用pytest 、 requests-mock和p ...

请求模拟:如何在模拟端点中匹配 POSTed 有效负载 - requests-mock: how can I match POSTed payload in a mocked endpoint

我做过什么 我编写了一个身份验证类,用于使用应用程序的API 密钥及其API 密钥秘密从 Twitter 获取应用程序的不记名令牌,如Twitter 开发人员文档中所示。 我以这种方式使用requests_mock模拟了适当的端点: 我的测试方法是: (其中TwitterBasicAut ...

为什么请求模拟装饰器模式会在 pytest 中抛出“找不到夹具‘m’”错误? - Why is the requests-mock decorator pattern throwing a "fixture 'm' not found" error with pytest?

我正在使用请求库发出 HTTP GET 请求。 例如(截断): requests.get("http://123-fake-api.com") 我已经按照请求模拟装饰器模式编写了一个测试。 import requests import requests_mock @requests_mock ...

使用 requests-mock 捕获 URL 参数 - Capture URL parameter with requests-mock

我正在使用requests-mock来模拟具有动态响应的外部服务。 该服务的 URL 类似于http://test/containers/test/1234 ,其中1234是我想要动态生成的对象 ID。 我已经尝试过正则表达式匹配器,但我似乎无法在动态响应回调中获取匹配对象。 有没有办法“捕获 ...


 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM