接口 mock 实战 [二]作业

  1. 利用 mitmproxy 的 mitmdump 实现对雪球页面的 maplocal 功能: 将股价进行修改
  2. 体会证书的过程

image


src:https://github.com/yanxuping/My_Test_Project/blob/main/test_API/API_MOCK/api_mock.py#L9
data:https://github.com/yanxuping/My_Test_Project/blob/main/test_API/API_MOCK/quote.json



代码路径:https://github.com/zhangguili123/pytestDemo/tree/master/testproxy
张贵丽提交作业

https://github.com/XFbeibei/HogwartsLagoutesting/tree/master/http

from mitmproxy import http


def request(flow: http.HTTPFlow) -> None:
    # pretty_url takes the "Host" header of the request into account, which
    # is useful in transparent mode where we usually only have the IP otherwise.

    if "quote.json" in flow.request.pretty_url and "x=" in flow.request.pretty_url:
        with open("D:/ProgramWorkspace/TestingDemo/test_mitmproxy/stock2.json",encoding="utf-8") as f:
            flow.response = http.HTTPResponse.make(
                200,  # (optional) status code
                f.read(),  # (optional) content
                {"Content-Type": "application/json"}  # (optional) headers

xueqiu-stock2