位置: 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怎么看历史壁纸)

  • 华为40w快充多久充满(华为40w快充多久充满p30pro)

    华为40w快充多久充满(华为40w快充多久充满p30pro)

  • iPhone8p快手怎么变黑色背景(苹果xr快手)

    iPhone8p快手怎么变黑色背景(苹果xr快手)

  • 快手怎样禁止别人下载自己的作品(快手怎样禁止别人看动态)

    快手怎样禁止别人下载自己的作品(快手怎样禁止别人看动态)

  • 华为mate30来信息指示灯在哪里设置(华为mate30来信息闪灯怎么设置)

    华为mate30来信息指示灯在哪里设置(华为mate30来信息闪灯怎么设置)

  • word表格怎么调整位置(word表格怎么调整某一个单元格)

    word表格怎么调整位置(word表格怎么调整某一个单元格)

  • 微信强提醒怎么设置24小时(微信强提醒怎么一直开着)

    微信强提醒怎么设置24小时(微信强提醒怎么一直开着)

  • 西瓜视频原创审核一般多久(西瓜视频原创审核 知乎)

    西瓜视频原创审核一般多久(西瓜视频原创审核 知乎)

  • 腾讯会议电脑版和手机版有什么区别(腾讯会议电脑版共享屏幕)

    腾讯会议电脑版和手机版有什么区别(腾讯会议电脑版共享屏幕)

  • 华为荣耀20s有红外线遥控吗(华为荣耀20s有红外遥控吗)

    华为荣耀20s有红外线遥控吗(华为荣耀20s有红外遥控吗)

  • 苹果8p尾插坏的表现(8p手机尾插坏了有什么症状)

    苹果8p尾插坏的表现(8p手机尾插坏了有什么症状)

  • uid是什么(uid是什么软件)

    uid是什么(uid是什么软件)

  • 支付宝更改手机号淘宝同步吗(支付宝更改手机号收不到验证码)

    支付宝更改手机号淘宝同步吗(支付宝更改手机号收不到验证码)

  • 屏幕录像在哪里打开(屏幕录像在哪里打开华为)

    屏幕录像在哪里打开(屏幕录像在哪里打开华为)

  • 华为超级充电怎么开启(华为超级充电怎么变成不是超充了怎么恢复)

    华为超级充电怎么开启(华为超级充电怎么变成不是超充了怎么恢复)

  • 苹果官网优惠码哪里可以得到(苹果官网优惠码输入口)

    苹果官网优惠码哪里可以得到(苹果官网优惠码输入口)

  • word里加参考文献(如何在word文档中添加参考文献)

    word里加参考文献(如何在word文档中添加参考文献)

  • mt712ch/a是不是国行(型号mt722ch/a)

    mt712ch/a是不是国行(型号mt722ch/a)

  • qq封号7天怎么解除(qq账号封停七天怎么解封)

    qq封号7天怎么解除(qq账号封停七天怎么解封)

  • 被恶意举报怎么申诉(被恶意举报怎么控告)

    被恶意举报怎么申诉(被恶意举报怎么控告)

  • 荣耀10游戏模式怎么开启(荣耀10游戏模式怎么开)

    荣耀10游戏模式怎么开启(荣耀10游戏模式怎么开)

  • airpods为什么不弹窗(airpods为什么不能连华为)

    airpods为什么不弹窗(airpods为什么不能连华为)

  • 手机网速测试怎么测?(手机网速测试怎么看多少兆网)

    手机网速测试怎么测?(手机网速测试怎么看多少兆网)

  • linux中gedit文本编辑器怎么设置自动保存文件内容?(linux中gedit命令)

    linux中gedit文本编辑器怎么设置自动保存文件内容?(linux中gedit命令)

  • 【已解决】探究CUDA out of memory背后原因,如何释放GPU显存?(想要探究的问题)

    【已解决】探究CUDA out of memory背后原因,如何释放GPU显存?(想要探究的问题)

  • 计提递延所得税资产
  • 进项税额属于什么账户
  • 简易计税方法能开专用发票吗
  • 烟叶增值税税率10%
  • 个税专项附加继续教育
  • 公积金个人缴纳多少
  • 个体户缴纳经营所得个税怎么算的
  • 四川网上电子税务局
  • 空调属于电子设备还是电气设备
  • 应付职工薪酬代扣款项账务处理
  • 期间费用包括资本公积吗
  • 股息红利所得如何缴纳个人所得税
  • 买赠活动怎么账务处理
  • 公司代缴的社保个人账户能不能查到
  • 销售库存商品计入什么科目
  • 结转应交所得税属于利润分配吗
  • 汇兑还款会计分录
  • 施工企业仪器设备入什么会计科目核算?
  • 子公司员工向母公司申请党员
  • 开普通发票现金走账怎样处理?
  • 建筑行业增值税税率是多少
  • 一般纳税人企业是什么意思
  • 农产品销售发票是什么?
  • 2018年建筑增值税税率表
  • 新股东入股怎么写记账凭证摘要
  • 对公账户转法人私人账户用途写什么
  • 企业的利润分配顺序
  • 减征资源税中是否包含水资源税?
  • 购买基金会计核算
  • 收入负数怎么分录
  • 物业公司物业费都交什么税
  • 回收站右键菜单修改
  • 公司产生的劳务费如何计算个人所得税
  • win7浏览器显示证书错误怎么解决
  • win11怎么清理内存
  • win11如何修复
  • 房地产企业出售土地交什么税
  • 盆栽月季花怎么修剪图解
  • 无损数据分区
  • 增值税有哪些类型的税种
  • 新会计准则关于公司装修费
  • thinkphp post
  • yii2框架漏洞
  • c++好学
  • 深度学习中的FPN详解
  • cssschool
  • vue watch
  • 被投资的公司注销后投资公司怎么处理
  • 新会计准则增加了哪些科目
  • 应付账款转入营业外收入会计分录
  • python中的logging记录日志
  • mongodb用法
  • 财务上大写数字420.1怎么写
  • 企业的利润分配包括哪些
  • 利润分配未分配利润在报表里怎么体现
  • 接待客人后的感受和过程
  • 租来的厂房如何交税
  • 固定资产损失税前扣除备查资料有哪些
  • 国库集中支付业务包括哪些
  • 跨年红字发票账务处理
  • 结转成本按照销售收入来结转,税要怎么算
  • 坏账准备具有哪些特征
  • 个体户开广告发票需要交税吗
  • 冲减应收账款是什么意思
  • 个体工商户个人经营所得税税率表
  • 用Autoconf检测MySQL软件包的教程
  • window10安装mysql5.7
  • LINUX操作系统的主要组成部分有
  • ubuntu photoshop
  • centos vncviewer
  • 怎么把硬盘安装到电脑上
  • get mac
  • win8系统摄像头在哪里打开
  • js定义函数的几种方法
  • javascript的核心
  • Android Studio Attach source code
  • vps 备份
  • [推荐]抖音上那些好看的视频和有才的帐号
  • python中文分词库
  • 国家税务局级别排名
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设