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

  • 红米10x支持屏幕指纹吗(红米10x啥屏幕)

    红米10x支持屏幕指纹吗(红米10x啥屏幕)

  • 知道抖音号却搜索不出来(知道抖音号却搜索不到对方)

    知道抖音号却搜索不出来(知道抖音号却搜索不到对方)

  • p40pro什么时候上市(p40pro什么时候出)

    p40pro什么时候上市(p40pro什么时候出)

  • 开性能模式对手机有害吗(性能模式开还是不开)

    开性能模式对手机有害吗(性能模式开还是不开)

  • nova7微信视频怎么美颜(nova7微信视频怎么不清楚)

    nova7微信视频怎么美颜(nova7微信视频怎么不清楚)

  • 手机保存不了视频怎么回事(手机保存不了视频只能收藏怎么回事)

    手机保存不了视频怎么回事(手机保存不了视频只能收藏怎么回事)

  • 钉钉定位是手机卡位置还是手机位置(钉钉定位是手机还是电脑)

    钉钉定位是手机卡位置还是手机位置(钉钉定位是手机还是电脑)

  • airpods和pro的区别(airpods和pro差别)

    airpods和pro的区别(airpods和pro差别)

  • 微信加人显示操作频繁多久恢复(微信加人显示操作太频繁,请稍后再试怎么办)

    微信加人显示操作频繁多久恢复(微信加人显示操作太频繁,请稍后再试怎么办)

  • 你拨打的用户尚未登录什么意思(你拨打的用户尚未登录)

    你拨打的用户尚未登录什么意思(你拨打的用户尚未登录)

  • 快手作品推广会不会显示出来(快手作品推广会被别人看见吗)

    快手作品推广会不会显示出来(快手作品推广会被别人看见吗)

  • 苹果xr掉水里立马拿出来有影响吗(苹果xr掉水里立马拿出来多久能充电)

    苹果xr掉水里立马拿出来有影响吗(苹果xr掉水里立马拿出来多久能充电)

  • hdmi和av线接哪个(avg和hdmi)

    hdmi和av线接哪个(avg和hdmi)

  • 技嘉主板进入bios按什么键(技嘉主板进入bios黑屏)

    技嘉主板进入bios按什么键(技嘉主板进入bios黑屏)

  • 关联qq为什么看不到对方聊天记录(关联QQ为什么看不到对方消息记录)

    关联qq为什么看不到对方聊天记录(关联QQ为什么看不到对方消息记录)

  • ps磁性套索工具怎么用(ps磁性套索工具怎么把图抠出来)

    ps磁性套索工具怎么用(ps磁性套索工具怎么把图抠出来)

  • 苹果手机画图功能在哪(苹果手机画图在哪里画)

    苹果手机画图功能在哪(苹果手机画图在哪里画)

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

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

  • vivonfc功能在哪里打开(vivo手机的nfc功能在哪)

    vivonfc功能在哪里打开(vivo手机的nfc功能在哪)

  • 苹果就寝怎么重新设置(iphone就寝在哪)

    苹果就寝怎么重新设置(iphone就寝在哪)

  • a57桌面插件怎么添加(桌面插件在哪里打开)

    a57桌面插件怎么添加(桌面插件在哪里打开)

  • 苹果手机pin码在哪里能看到(苹果手机PIN码在哪里关闭)

    苹果手机pin码在哪里能看到(苹果手机PIN码在哪里关闭)

  • 电话总是在通话中怎么了(打电话总在通话中怎么办)

    电话总是在通话中怎么了(打电话总在通话中怎么办)

  • 蓝牙耳机有杂音怎么解决(蓝牙耳机有杂音是怎么回事)

    蓝牙耳机有杂音怎么解决(蓝牙耳机有杂音是怎么回事)

  • 12g内存和8g内存区别(12g内存和8g内存区别电脑)

    12g内存和8g内存区别(12g内存和8g内存区别电脑)

  •  西瓜视频如何下载到手机(西瓜视频如何取消关注)

    西瓜视频如何下载到手机(西瓜视频如何取消关注)

  • win11怎么设置最佳性能模式? windows11开启最佳性能模式的技巧(win11怎么设置最佳能效模式)

    win11怎么设置最佳性能模式? windows11开启最佳性能模式的技巧(win11怎么设置最佳能效模式)

  • Win11提示“为了对电脑进行保护,已经阻止此应用”解决方法(ie11已经为了帮助保护您的计算机而关闭此网页)

    Win11提示“为了对电脑进行保护,已经阻止此应用”解决方法(ie11已经为了帮助保护您的计算机而关闭此网页)

  • 居民企业投资收益免征企业所得税
  • 固定资产清理借方余额是加还是减
  • 实际已缴纳所得税额在汇算清缴报告里怎么看
  • 印花税减半征收吗
  • 单位多久查一次征信
  • 残保基金的计算公式
  • 增值税一般纳税人是什么意思
  • 固定资产大修理支出标准
  • 企业所得税按月还是按季度申报
  • 商贸企业出口退税计算公式
  • 外币账户收款如何做账务处理呢?
  • 车船使用税应该交哪里的税
  • 某企业原材料采用实际成本核算,2019年6月
  • 应收账款补提坏账是什么意思
  • 退回剩余工程物资计入什么科目
  • 小规模纳税人应纳税额减征额怎么算
  • 小规模企业所得税优惠政策最新2023
  • 计提坏账准备需要纳税调增吗
  • 外贸企业支付境外佣金
  • 企业做账会计需要什么资质
  • 定金转为货款金额需要特别约定吗?
  • 在建工程抵工程款
  • 期初存货余额在哪张表里
  • 个体工商户怎么交税
  • bios中关闭软盘
  • 资产利润率和资本利润率监管标准
  • 企业所得税什么时候交
  • 如何安全的处置电子邮件
  • 怎么更改定位位置信息
  • 工程结算的账务处理
  • 计提劳务派遣人员社保收到发票后没有付款的会计分录
  • win10怎么启用
  • 包装物逾期是什么意思
  • 小规模纳税人销售自己使用过固定资产
  • 发票备注栏可以写详见清单吗
  • 篱笆的样子
  • 政府购买企业服务是否交税
  • phptoken验证原理
  • _ html
  • springboot整合websocket怎么接受图片消息
  • bert的原理
  • 导入vue.js
  • dd命令拷贝磁盘
  • 固定资产支出计入什么科目
  • 一般户需要做账报税吗
  • 物流公司账务处理特点
  • 帝国cms视频教程
  • 家居办公装修
  • 使用二氧化碳灭火器时人应该站在什么位置
  • 百旺连接服务器失败,是否使用离线文件进行更新
  • 专用发票金额与专票不符
  • 受让应收账款的账务处理
  • 小规模纳税人开票限额是多少
  • 母公司收取子公司利润
  • 残保金属期是当年还是上年
  • 个人提供劳务增值税专用发票
  • 免税商品外汇业务
  • 入库单金额写错可以改吗
  • 处置固定资产会计处理
  • 委托加工农产品的扣除率
  • 工程开票金额大写怎么写
  • 房地产开发企业增值税怎么算
  • mysql实时监控工具
  • windows server2008系统弹出今天必须修改密码该怎么处理?
  • win7系统打开计算机的管理出现正在向控制台添加属性
  • 政府禁用windows8
  • ubuntu桌面右键
  • linux git教程
  • centos下虚拟机
  • linux系统中怎么输入中文
  • win10系统桌面怎么设置密码
  • Android游戏开发教程
  • qt_5 not found
  • sed配合grep
  • perl -p -i
  • python中input的用法
  • 江苏省国家税务局总局官网
  • 淘宝店铺过户后身份证是谁的
  • 处室岗位是什么意思
  • 山西省地方税务局通用定额发票
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设