python wrapper&utils,用于通过wire-test-double工具进行mountebank。

mbtest的Python项目详细描述


mbtest

用于Mountebankover the wire test double工具的自以为是的python包装器和实用程序。

包括pytest夹具和PyHamcrest匹配器。

made-with-pythonBuild StatusPyPi VersionPython VersionsLicenceGitHub all releasesGitHub forksGitHub starsGitHub watchersGitHub contributorsGitHub issuesGitHub issues-closedGitHub pull-requestsGitHub pull-requests closedCodacy BadgeCodacy CoverageLines of Code

设置

使用pip安装:

pip install mbtest

(与往常一样,建议使用venvvirtualenv。)还需要安装Mountebank

npm install mountebank@1.16 --production

基本示例

importrequestsfromhamcrestimportassert_that,is_frombrunns.matchers.responseimportresponse_withfrommbtest.matchersimporthad_requestfrommbtest.impostersimportImposter,Predicate,Response,Stubdeftest_request_to_mock_server(mock_server):# Set up mock server with required behaviorimposter=Imposter(Stub(Predicate(path="/test"),Response(body="sausages")))withmock_server(imposter)asserver:# Make request to mock server - exercise code under test hereresponse=requests.get("{}/test".format(imposter.url))assert_that("We got the expected response",response,is_(response_with(status_code=200,body="sausages")))assert_that("The mock server recorded the request",server,had_request(path="/test",method="GET"))

需要一个pytest fixture,最容易在^{}中定义:

importpytestfrommbtestimportserver@pytest.fixture(scope="session")defmock_server(request):returnserver.mock_server(request)

更复杂谓词的示例可以在integration tests中找到。

开发

需要maketox。runmake precommit告诉您是否可以提交。有关更多选项,请运行:

make help

释放

需要hubsetuptoolstwine。释放n.n.n

version="n.n.n" # Needs to match new version number in setup.py.
make precommit && git commit -am"Release $version" && git push # If not already all pushed, which it should be.
hub release create $version -m"Release $version"
python setup.py sdist bdist_wheel
twine upload dist/*$version*

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Clojure关键字在内存中的大小是多少?   Java中有固定长度的通用数组对象吗?   PostgreSQL:通过Java更新我的用户表   错误:使用java解析xml   java Json显示列表中对象的名称   java比较JodaTime时区   与JAVA中的API和包的区别?   java的int值在for循环中不改变   谷歌应用引擎中的java RSA   迁移到spring 5后出现java非法字符错误   java Websphere管理控制台不工作   JavaGSON如何始终在json中包含毫秒?   带有空格和双引号的windows Java ProcessBuilder命令参数失败   java错误:重复的zip条目[43.jar:org/apache/http/annotation/NotThreadSafe.class]