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

  • 增值税税率是怎么规定的
  • 个体工商户怎样纳税
  • 进项和销项必须在一个月吗
  • 知识产权申报费用多少钱
  • 个人房租费收入怎么做账
  • 职工食堂开支会计处理
  • 公司拓展训练入什么会计科目核算做分录?
  • 计提车间折旧费怎么写分录
  • 购买的固定资产没有使用,是否计提折旧
  • 金税盘维护费减免政策代码
  • 溢价或者折价购买债券的会计处理.
  • 简易分包抵减的增值税应纳税额怎么做会计分录?
  • 公司注销税务需要交多少钱
  • 项目收入怎么算
  • 银行利息收入要开发票吗
  • 为什么餐费不能计入在差旅费
  • 个人机械租赁费税率
  • 文化事业建设税征税范围
  • 营业外支出调减应该填在纳税调整项目明细表哪一项
  • 差旅费报销单填写模板
  • 支票付款的弊端
  • 民办非企业单位和私营单位的区别
  • win11任务栏如何设置在最左边
  • 预缴税款是否计入成本
  • 金银首饰在哪个软件买
  • vue路由点击没反应
  • springboot+vue+elementsUI 实现分角色注册登录界面
  • 小型企业的资产负债表
  • 蕾德纳斯
  • html扫码功能
  • codeigniter 教程
  • 查询的命令
  • 出口销售折扣怎么处理
  • 抄税清卡是一个意思吗
  • 律师事务所主要业务范围介绍
  • phpcms怎么用
  • 企业所得税不得核定征收行业
  • 充话费自定额
  • 个人独资企业取名规则
  • 一般纳税人材料票是几个点
  • 小企业会计准则季度报表
  • 定金罚则可以约定吗
  • 工会经费会计分录最新
  • 企业管理费用科目有哪些
  • 差旅费报销过程中会计和出纳分别做什么
  • 设备维修三种形式
  • 评估增值净利润调减
  • 单位租的个人房怎么入账
  • 应收应付款会计分录
  • 营改增后服务业账务处理
  • 个人工资怎么合理避税有什么方法
  • 运费不支付会怎么样
  • 进项税抵扣销项税算法
  • 利润分配和所有者权益的关系
  • 小规模纳税人附加税减半征收
  • 兼职费计入什么科目
  • 员工垫付的钱会计分录
  • 收到商业承兑汇票的会计分录
  • 换工作后个税app单位会自动更改吗
  • 公司现金支票取钱需要带什么资料
  • 投资入股行为
  • 准备金支出是否含税
  • 重组合并
  • win7系统怎么设置开机启动项
  • xp系统百度
  • Ubuntu安装ssh
  • win10预览版和正式版
  • win10升级20h
  • 电脑连不上网怎么回事 笔记本
  • opengl编程实例
  • 创建nodejs项目的步骤
  • python教程100例
  • jquery操作table
  • 安卓自定义acl文件
  • js如何修改style
  • unity2018预制体
  • android判断应用是否在前台
  • 云南发票网站
  • 中国税务客服工作时间
  • 出口退税函调不予退税的后果
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设