位置: 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(反射怎么解释)

  • 怎么在手机上开通快捷支付功能(怎么在手机上开通手机银行)

    怎么在手机上开通快捷支付功能(怎么在手机上开通手机银行)

  • 两台苹果手机怎么转移通讯录(两台苹果手机怎么传输数据)

    两台苹果手机怎么转移通讯录(两台苹果手机怎么传输数据)

  • iphone提醒事项会响吗(iPhone提醒事项会提醒吗)

    iphone提醒事项会响吗(iPhone提醒事项会提醒吗)

  • 米家车载空气净化器怎么连接(米家车载空气净化器)

    米家车载空气净化器怎么连接(米家车载空气净化器)

  • vivox27白屏了怎么办(vivo白屏了怎么办)

    vivox27白屏了怎么办(vivo白屏了怎么办)

  • ctex是什么平台

    ctex是什么平台

  • vivi手机是哪个公司的(vivi手机哪个系列不好)

    vivi手机是哪个公司的(vivi手机哪个系列不好)

  • 知乎怎么看自己的匿名回答(知乎怎么看自己的浏览记录)

    知乎怎么看自己的匿名回答(知乎怎么看自己的浏览记录)

  • 快手消息怎么看不到(快手消息怎么看不太清)

    快手消息怎么看不到(快手消息怎么看不太清)

  • 文件aaa.exe是一个什么文件(aaa是什么文件夹)

    文件aaa.exe是一个什么文件(aaa是什么文件夹)

  • 注销手机号需要本人去吗(注销手机号需要解绑哪些东西)

    注销手机号需要本人去吗(注销手机号需要解绑哪些东西)

  • 计算机病毒最主要的特征是(电脑病毒之王)

    计算机病毒最主要的特征是(电脑病毒之王)

  • 手机铃声响三秒就停了(手机铃声响几秒就不响了,怎么回事?)

    手机铃声响三秒就停了(手机铃声响几秒就不响了,怎么回事?)

  • 华为p40能无线充电么(华为p60可以无线充电么)

    华为p40能无线充电么(华为p60可以无线充电么)

  • 苹果耳机怎么看电量是否充满(苹果耳机怎么看电池还有多少电量)

    苹果耳机怎么看电量是否充满(苹果耳机怎么看电池还有多少电量)

  • 华为语音读屏怎么关闭(华为语音朗读屏幕)

    华为语音读屏怎么关闭(华为语音朗读屏幕)

  • 快手加粉丝团是什么意思(快手加粉丝团是免费的吗)

    快手加粉丝团是什么意思(快手加粉丝团是免费的吗)

  • iphone11怎么连接蓝牙耳机(iphone11怎么连接电脑)

    iphone11怎么连接蓝牙耳机(iphone11怎么连接电脑)

  • soul拉黑对方知道吗(soul拉黑对方还能看到我发的信息吗)

    soul拉黑对方知道吗(soul拉黑对方还能看到我发的信息吗)

  • 导航浮窗是什么意思(导航浮标是什么)

    导航浮窗是什么意思(导航浮标是什么)

  • word上标怎么弄(word中的上标怎么弄)

    word上标怎么弄(word中的上标怎么弄)

  • 什么是观点明确(什么是观点明确?)

    什么是观点明确(什么是观点明确?)

  • 拼多多会员名在哪里看(拼多多会员名是昵称吗)

    拼多多会员名在哪里看(拼多多会员名是昵称吗)

  • 抖音如何加群(抖音上加微信怎么加)

    抖音如何加群(抖音上加微信怎么加)

  • 微信不可解封是永久吗(微信 不可解封)

    微信不可解封是永久吗(微信 不可解封)

  • YOLOv3&YOLOv5输出结果说明(yolov5 c)

    YOLOv3&YOLOv5输出结果说明(yolov5 c)

  • 增值税查询校验码是什么
  • 个税申报人员报送成功怎么删除
  • 代开了专票,但是销售额没有超过30万怎么处理
  • 企业资产重组是不定期清查吗
  • 公司授权给公司有风险吗?
  • 再保后赔款支出
  • 外币报表折算差额在会计报表中应作为
  • 开票与实际收款不一致有什么风险
  • 将自制的一批新产品用于对外投资,生产成本为300000
  • 长期待摊费用计提摊销的会计分录
  • 资产减值准备的会计科目
  • 合作保证金可以退吗
  • 一般纳税人没有开票要交税吗
  • 农产品发票有抵税吗
  • 清包工开票详细名称
  • 土地使用税每个月都要计提吗
  • 发票分票怎么处理违章
  • 外派人员计算个人所得税可否有附加扣除
  • 销售额的意思
  • 企业社会贡献总结怎么写
  • windows11怎么设置壁纸
  • 网页老是自己跳出来
  • biospwds最新版
  • 账套没有以前年度调整
  • 企业并购效益
  • 远程主机强迫关闭了现有连接我的世界
  • 在windows7操作具有什么特点
  • 跨年的收入可以在次年冲吗
  • dgservice.exe是什么
  • uniapp intent
  • 用公司资质应交什么费用
  • 发票开了对方未付款
  • chat function
  • 阿伦河在哪
  • Spring Security(七)-- AuthenticationProvider
  • 前端es6是什么意思
  • 让我看看他们
  • 分享项目成果
  • 行人重识别map
  • vue有哪些方法
  • 学习率设置
  • php显示图片代码
  • python输入三个数输出最小的
  • 未核定月数是什么
  • 进项发票和销项发票统计
  • 建筑企业预缴所得税款税率
  • 冲销去年暂估成本对企业所得税的影响
  • cms采集网站
  • PostgreSQL教程(二):模式Schema详解
  • SqlServer与MongoDB结合使用NHibernate
  • 抚恤金发放标准2019年
  • 劳务报酬收入是否含税
  • 人工费用计入
  • 汇算清缴可以不调整吗
  • 城镇土地使用税怎么算
  • 以前多计提的税款怎么办
  • 收到免费赠送的产品怎么做账
  • 汇率调节主要手段
  • 长期借款工程验收会计分录怎么做
  • 金税盘每年服务费可以抵扣吗
  • 公司股东借款转私人账户
  • 如何办icp许可证
  • 建账初期账务处理程序
  • 个体户建账吗
  • linux下apache、mysql、php安装配置详细笔记
  • mysql日志的作用
  • mysql查询结果是什么类型
  • windows server 2008 64位MySQL5.6免安装版本配置方法图解
  • ubuntu20.04设置
  • winxp系统怎么设置开机密码
  • ubuntu touch怎么刷入
  • centos7搭建frp
  • win10系统ie浏览器不见了
  • opengl视角跟随鼠标方向移动
  • TypeScript Type Innference(类型判断)
  • socketdescriptor
  • 缓动函数网站
  • js实现点击按钮移动滑块到另一个按钮的方法
  • javascript的理解
  • 吉林税务网上办事大厅
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设