https://github.com/knightliao/pfrock
A plugin-based server for running fake HTTP and socket services (especially SOA service) using Python.
_ (`-.            _  .-')                          .-. .-')
  ( (OO  )          ( \( -O )                         \  ( OO )
 _.`     \   ,------.,------.  .-'),-----.    .-----. ,--. ,--.
(__...--''('-| _.---'|   /`. '( OO'  .-.  '  '  .--./ |  .'   /
 |  /  | |(OO|(_\    |  /  | |/   |  | |  |  |  |('-. |      /,
 |  |_.' |/  |  '--. |  |_.' |\_) |  |\|  | /_) |OO  )|     ' _)
 |  .___.'\_)|  .--' |  .  '.'  \ |  | |  | ||  |`-'| |  .   \
 |  |       \|  |_)  |  |\  \    `'  '-'  '(_'  '--'\ |  |\   \
 `--'        `--'    `--' '--'     `-----'    `-----' `--' '--'
python >=2.7
https://github.com/knightliao/pfrock/blob/master/README-en.md
也就是说,
通过此种方式, 我们可以以最低的侵入性, 实现为系统的部分或者全部接口进行 mock.
pip install pfrock==0.2.5
(pypi: https://pypi.python.org/pypi/pfrock)
- demo
    - mocks
        - handler
            - hello_world.py
            - __init__.py
        - static
            - a.json
            - b.json
        - __init__.py
    - __init__.py
    - pfrockfile.json
{
    "servers": [
        {
            "port": 8888,
            "routes": [
                {
                    "path": "/api1/(.*)",
                    "handler": "pfrock_static_plugin",
                    "options": {
                        "routes": [
                            {
                                "path": "json",
                                "file": "mocks/static/a.json"
                            },
                            {
                                "dir": "mocks/static"
                            }
                        ]
                    }
                },
                {
                    "path": "/api",
                    "methods": [
                        "GET"
                    ],
                    "handler": "pfrock_http_plugin",
                    "options": {
                        "handler": "mocks.handler.hello_world.HelloWorldHandler",
                        "query": "1!",
                        "pageno": 1
                    }
                },
                {
                    "path": ".*",
                    "methods": "any",
                    "handler": "pfrock_proxy_plugin",
                    "options": {
                        "url": "http://www.sov5.com"
                    }
                }
            ]
        }
    ]
}
➜  pfrock git:(master) ✗
➜  pfrock git:(master) ✗ cd demo
➜  demo git:(master) ✗ pfrockpy
   _ (`-.            _  .-')                          .-. .-')
  ( (OO  )          ( \( -O )                         \  ( OO )
 _.`     \   ,------.,------.  .-'),-----.    .-----. ,--. ,--.
(__...--''('-| _.---'|   /`. '( OO'  .-.  '  '  .--./ |  .'   /
 |  /  | |(OO|(_\    |  /  | |/   |  | |  |  |  |('-. |      /,
 |  |_.' |/  |  '--. |  |_.' |\_) |  |\|  | /_) |OO  )|     ' _)
 |  .___.'\_)|  .--' |  .  '.'  \ |  | |  | ||  |`-'| |  .   \
 |  |       \|  |_)  |  |\  \    `'  '-'  '(_'  '--'\ |  |\   \
 `--'        `--'    `--' '--'     `-----'    `-----' `--' '--'
pfrock version 0.2.2
[I 2016-03-04 14:07:05,231 pfrock.core MainThread __init__:19] started server 8888 with autoreload mod
➜  ~  curl http://localhost:8888/api1/json
{
  "a": "bddd33e34"
}%
➜  ~  curl -X POST -d {} http://localhost:8888/api1/json
{
  "a": "bddd33e34"
}%
➜  ~  curl http://localhost:8888/api1/b.json
{
    "b": "bbb"
}%
➜  ~  curl 'http://localhost:8888/api'
Hello, world 1! 1%                                                                                                                                            ➜  ~
那么, 除了上面这些 URL 之外, 没有被匹配的 URL 怎么办? 就用代理到默认的服务器上吧! 这在项目中经常会被用到.
➜  ~  curl 'http://localhost:8888/'
没有匹配到的 URL 自动被 路由到 设定的 域名和端口上.
这里是被路由到 http://www.sov5.com
https://github.com/knightliao/pfrock-demos
建议按以下方式进行敏捷开发
|      1ezreal      2016-03-04 18:30:54 +08:00 赞~ | 
|      2ezreal      2016-03-04 18:34:41 +08:00 但是怎么产品随机的模拟数据呢 | 
|  |      3knightliao OP @ezreal 那这个就是另外一个话题了。。关于如何产生 合格的 随机的 较大规模的 测试数据 | 
|  |      4knightliao OP @ezreal 最近还在为它开发一个插件 ,可以比较方便的根据用户规则 引擎来返回数据 | 
|      5ezreal      2016-03-05 20:16:05 +08:00 @knightliao 觉得应该把这个功能整合进去,不然功能太有限了 | 
|  |      6knightliao OP @ezreal 可以,回头我搞上 | 
|  |      7knightliao OP 支持具有参数规则引擎计算服务能力 https://github.com/knightliao/pfrock/wiki/Tutorial-5 |