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

  • 苹果13自带手机膜吗(苹果13自带手机壳不)

    苹果13自带手机膜吗(苹果13自带手机壳不)

  • 爱奇艺多屏互动怎么用(爱奇艺多屏互动怎么连接电视)

    爱奇艺多屏互动怎么用(爱奇艺多屏互动怎么连接电视)

  • iphone11微信录屏怎么操作(苹果11微信录屏怎么没有声音)

    iphone11微信录屏怎么操作(苹果11微信录屏怎么没有声音)

  • 荣耀30pro+屏幕大小(荣耀30pro屏幕尺寸比例)

    荣耀30pro+屏幕大小(荣耀30pro屏幕尺寸比例)

  • 微信群如何升级到500人(微信群如何升级多个管理员)

    微信群如何升级到500人(微信群如何升级多个管理员)

  • 手机上的hd怎么取消(手机上hd什么意思)

    手机上的hd怎么取消(手机上hd什么意思)

  • 苹果x蓝牙打不开咋办(苹果X蓝牙打不开怎么办)

    苹果x蓝牙打不开咋办(苹果X蓝牙打不开怎么办)

  • 三星s10更新25w快充了吗(三星s10更新后续航)

    三星s10更新25w快充了吗(三星s10更新后续航)

  • 苹果手机id提示无法验证身份(苹果手机id提示确定密码)

    苹果手机id提示无法验证身份(苹果手机id提示确定密码)

  • 苹果11时间旁边有个箭头(苹果11时间旁边有个小飞机图标怎么关)

    苹果11时间旁边有个箭头(苹果11时间旁边有个小飞机图标怎么关)

  • 华为nova7se防水等级(华为nova7se防水性)

    华为nova7se防水等级(华为nova7se防水性)

  • 腾讯会议有时长记录吗(腾讯会议有时长吗怎么看)

    腾讯会议有时长记录吗(腾讯会议有时长吗怎么看)

  • 华为摄像头碎了保修吗(华为摄像头碎了能换吗)

    华为摄像头碎了保修吗(华为摄像头碎了能换吗)

  • iphone没有红外线怎么当遥控器(iphone没有红外线功能可以开空调吗)

    iphone没有红外线怎么当遥控器(iphone没有红外线功能可以开空调吗)

  • 快手私信为什么不能删除(快手私信为什么有时候收不到信息)

    快手私信为什么不能删除(快手私信为什么有时候收不到信息)

  • hp电池耗尽无法充电(惠普电池报错)

    hp电池耗尽无法充电(惠普电池报错)

  • 个人热点频率什么意思(热点频段越高越好吗)

    个人热点频率什么意思(热点频段越高越好吗)

  • 陌陌用微信登录好友会知道吗(陌陌用微信登录后好友都能看到)

    陌陌用微信登录好友会知道吗(陌陌用微信登录后好友都能看到)

  • mate30pro屏幕容易碎吗(Mate30pro屏幕容易坏)

    mate30pro屏幕容易碎吗(Mate30pro屏幕容易坏)

  • ipad怎么绑定微信支付(苹果ipad怎么绑定微信支付)

    ipad怎么绑定微信支付(苹果ipad怎么绑定微信支付)

  • 手机怎么连接路由器(手机怎么连接路由器2.4g网络)

    手机怎么连接路由器(手机怎么连接路由器2.4g网络)

  • 抖音私信有撤回功能吗(抖音私信撤回了算一条吗)

    抖音私信有撤回功能吗(抖音私信撤回了算一条吗)

  • beatsx怎么恢复出厂

    beatsx怎么恢复出厂

  • 内存g和gb一样吗(内存g和内存gb哪个更大)

    内存g和gb一样吗(内存g和内存gb哪个更大)

  • nova4e上市时间(nova4e上市时间年月日)

    nova4e上市时间(nova4e上市时间年月日)

  • 计算机领域各大顶会顶刊集合梳理(计算机领域划分)

    计算机领域各大顶会顶刊集合梳理(计算机领域划分)

  • 退税收入如何做账
  • 什么叫做负税
  • 工程施工的材料购进计入哪里
  • 网银制单了没有审核有影响吗
  • 小规模纳税人应交增值税怎么算
  • 职工交的商业保险怎么做账
  • 员工垫资报销记账
  • 厨房酒店用品
  • 出纳单据交接表怎么填写
  • 购置办公用品有什么好处
  • 转让实物资产税务处理
  • 承兑汇票贴现计算公式
  • 招聘发票可以抵扣吗
  • 跨年度取得增值税发票
  • 变更法人税务怎么变更
  • 建筑业差额征税的账务处理
  • 企业发生的销售折让
  • 增资印花税增加哪个税目
  • 在境外施工由国家承担吗
  • 机械租赁费如何入账科目
  • 建筑业调试费进什么科目?
  • 会计分录如何试算出来的
  • 当月增加的固定资产
  • 公司生产的产品
  • 新会计制度下如何做账
  • 房产税的征收范围为
  • 收到员工的罚款的会计科目
  • 注册资金没有的怎么做账
  • Linux中stat命令显示文件的基本使用教程
  • win10您需要权限来执行删除
  • 仓储服务和不动产租赁
  • laravel 使用redis
  • 购买原材料月末需要结转吗
  • 浅谈php表单提交的问题
  • php重定向伪造referer
  • php面向对象编程
  • php 命名空间 通俗易懂
  • 增值税进项税额能不能抵扣
  • 上个月发票税率怎么查
  • 在sqlserver2008中
  • 可转债可以不卖吗
  • 查财务报表的网站有哪些
  • 中国移动发票抬头开错了可以重开吗
  • ip地址跳转域名
  • 酒店购买天然气开票的摘要写什么
  • 商业汇票贴现条件有哪些
  • 附加税税率是指
  • 旅行社增值税2020
  • 支付结算规定的基本要求
  • 公司开发的app费用怎么算
  • 资产负债表货币资金怎么填
  • 关于文化事业建设费的说法错误的是
  • 工程施工间接费用明细
  • 购买固定资产的账务处理
  • 年底未分配利润在贷方
  • 会计错账的更正方法
  • 权益性投资包括哪些
  • 启动sqlserver服务的命令
  • mysql设置唯一值
  • mysql中存储引擎
  • windows预览版和正式版区别
  • windows 安装app
  • macbookpro日历
  • 苹果发布首款MR头显
  • linux shell 数字转字符串
  • 电脑系统 win7
  • 运维是什么的
  • node.js连接数据库的代码
  • vuex的作用和使用场景
  • css中清除浮动的目的有哪些
  • shell正则表达式语法
  • 详细解读了
  • android使用方法
  • 安卓屏幕适配详解
  • flask框架下使用scrapy框架
  • java多线程编程实战指南
  • 高速通行费发票查验
  • 工商与税务合并了吗
  • 增值税进项发票勾选时间
  • 宣城市有什么好玩的景区
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设