位置: IT常识 - 正文

Testing Applications with WebTest¶

编辑:rootadmin
Testing Applications with WebTest — WebTest 1.3.2 documentationTesting Applications with WebTest&#18 Testing Applications with WebTest¶ author:Ian Bicking <ianb@colorstudy.com>maintainer:Gael Pasgrimaud <gael@gawel.org>NewsLicensewebtest – Functional Testing of Web Applicationswebtest.sel – Functional Testing with Selenium

Contents

Testing Applications with WebTest

Status & LicenseInstallationWhat This DoesTestApp

Making Requests

Modifying the Environment & Simulating AuthenticationWhat Is Tested By DefaultThe Response ObjectForm SubmissionsParsing the BodyFramework HooksStatus & License¶

推荐整理分享Testing Applications with WebTest¶,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

WebTest is an extraction of paste.fixture.TestApp, rewriting portions to use WebOb. It is under active development as part of the Paste cloud of packages.

Feedback and discussion should take place on the Paste list, and bugs should go into the Bitbucket tracker.

This library is licensed under an MIT-style license.

WebTest is in a mercurial repository at http://bitbucket.org/ianb/webtest. You can check it out with:

$ hg clone https://bitbucket.org/ianb/webtest WebTestInstallation¶

You can use pip or easy_install to get the latest stable release:

$ pip install WebTest$ easy_install WebTest

Or if you want the development version:

$ pip install "http://bitbucket.org/ianb/webtest/get/tip.tar.gz#egg=WebTest"What This Does¶

WebTest helps you test your WSGI-based web applications. This can be any application that has a WSGI interface, including an application written in a framework that supports WSGI (which includes most actively developed Python web frameworks – almost anything that even nominally supports WSGI should be testable).

With this you can test your web applications without starting an HTTP server, and without poking into the web framework shortcutting pieces of your application that need to be tested. The tests WebTest runs are entirely equivalent to how a WSGI HTTP server would call an application. By testing the full stack of your application, the WebTest testing model is sometimes called a functional test, integration test, or acceptance test (though the latter two are not particularly good descriptions). This is in contrast to a unit test which tests a particular piece of functionality in your application. While complex programming tasks are often is suited to unit tests, template logic and simple web programming is often best done with functional tests; and regardless of the presence of unit tests, no testing strategy is complete without high-level tests to ensure the entire programming system works together.

WebTest helps you create tests by providing a convenient interface to run WSGI applications and verify the output.

TestApp¶Testing Applications with WebTest¶

The most important object in WebTest is TestApp, the wrapper for WSGI applications. To use it, you simply instantiate it with your WSGI application. (Note: if your WSGI application requires any configuration, you must set that up manually in your tests.)

>>> from webtest import TestApp>>> from webtest.debugapp import debug_app>>> app = TestApp(debug_app)>>> res = app.get('/form.html')>>> res.status'200 OK'>>> res.form<Form />Making Requests¶

To make a request, use:

app.get('/path', [headers], [extra_environ], ...)

This does a request for /path, with any extra headers or WSGI environment keys that you indicate. This returns a response object, based on webob.Response. It has some additional methods to make it easier to test.

If you want to do a POST request, use:

app.post('/path', {'vars': 'values'}, [headers], [extra_environ], [upload_files], ...)

Specifically the second argument is the body of the request. You can pass in a dictionary (or dictionary-like object), or a string body (dictionary objects are turned into HTML form submissions).

You can also pass in the keyword argument upload_files, which is a list of [(fieldname, filename, fild_content)]. File uploads use a different form submission data type to pass the structured data.

For other verbs you can use:

app.put(path, params, ...)app.delete(path, ...)

These do PUT and DELETE requests.

Modifying the Environment & Simulating Authentication¶

The best way to simulate authentication is if your application looks in environ['REMOTE_USER'] to see if someone is authenticated. Then you can simply set that value, like:

app.get('/secret', extra_environ=dict(REMOTE_USER='bob'))

If you want all your requests to have this key, do:

app = TestApp(my_app, extra_environ=dict(REMOTE_USER='bob'))What Is Tested By Default¶

A key concept behind WebTest is that there’s lots of things you shouldn’t have to check everytime you do a request. It is assumed that the response will either be a 2xx or 3xx response; if it isn’t an exception will be raised (you can override this for a request, of course). The WSGI application is tested for WSGI compliance with a slightly modified version of wsgiref.validate (modified to support arguments to InputWrapper.readline) automatically. Also it checks that nothing is printed to the environ['wsgi.errors'] error stream, which typically indicates a problem (one that would be non-fatal in a production situation, but if you are testing is something you should avoid).

To indicate another status is expected, use the keyword argument status=404 to (for example) check that it is a 404 status, or status="*" to allow any status.

If you expect errors to be printed, use expect_errors=True.

本文链接地址:https://www.jiuchutong.com/zhishi/310596.html 转载请保留说明!

上一篇:mysql事务对效率的影响(mysql事务性能)

下一篇:day43-反射02(反射怎么解释)

  • 消费税退回退税流程
  • 买房子一定要交税吗
  • 报税是怎么操作的
  • 借款发生的利息费用
  • 公司给员工租的宿舍怎么交税
  • 负数怎么在excel里输入
  • 税务信用级别为m级
  • 生产企业发票单位
  • 为什么对子公司长投要用成本法
  • 收款收据是否可以做账
  • 转让土地及地上建筑物
  • 包装材料报废后如何做会计核算?
  • 研发新产品成功案例简短
  • 补税款的分录应该怎么写
  • 注册资本变更增加意味着什么
  • 出口退税可以用电子专用发票吗
  • 存货的进项税要计入成本吗
  • 滴滴普票可以抵扣进项么
  • 进口应税消费品所支付的金额不包括
  • 业务宣传费企业所得税扣除标准是多少
  • 发票和款未付可以抵扣吗
  • 玩穿越火线总是提示机器遇到
  • 小黑马下载
  • php require的用法
  • abm文件怎么打开
  • zmweb.exe是什么进程
  • PHP:pcntl_signal_dispatch()的用法_PCNTL函数
  • 财务人员如何审核招待费报销单
  • 备用金会涨额度吗
  • 公司电路改造费怎么账务处理
  • nvm for windows
  • ctrl ate del
  • 餐饮服务专票可以抵税吗
  • 计提的费用收到增值税专票
  • 营改增分录
  • 现金预算表中的归还借款和支付利息怎么算
  • SQL Server中的XML数据进行insert、update、delete
  • 资本公积的会计处理方法
  • 允许加计扣除的新技术研究开发费用是
  • 2020年混凝土增值税税率是多少
  • 个人社保应不应该缴纳
  • 水泥销售会计分录怎么做
  • 餐饮赠送的菜品需要缴税吗
  • 实收资本的入账金额包括消费税吗
  • 加计扣除所得税怎么算
  • 小规模购置金税盘抵税如何申报
  • 发票当月没开
  • 工程物资是
  • 融资租赁的固定资产可以一次性扣除吗
  • 开业赠送礼品会计属于什么费用
  • 行政事业单位福利费提取比例
  • 年平均资金占用额公式
  • 公司购入二手车没有发票怎么入账
  • 在建工程预付款怎么做账
  • 工业企业发生的各项费用都应计入产品成本对不对
  • sqlserver2005附加数据库错误1827
  • mysql中字符串类型
  • freebsd书籍
  • windows7与xp共享文件夹
  • linux vim 查找替换
  • SUSE Linux Enterprise Server 设置防火墙开启ssh远程端口的方法
  • windows8联网
  • centos安装详细
  • 怎么看win8.1的版本
  • windows10稳定版本
  • 重装win7旗舰版重启后黑屏
  • cocos2d-x windows开发环境配置
  • ping命令详解步骤
  • Unity3D游戏开发标准教程
  • Unable to execute dex: Multiple dex files define 解决方法
  • jquery和html的关系
  • angularjs教程
  • JavaScript mapreduce工作原理简析
  • 交互式shell是什么意思
  • BootStrap iCheck插件全选与获取value值的解决方法
  • Python的内置字典数据类型为___
  • jquery foreach循环
  • 税务部门行政审批
  • 河北耕地占用税最新规定
  • 重庆国税12316
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设