[笨方法学python]习题51自动化测试笔记
习题51
本节自动化测试部分看不大懂,自己每步都打印出来,帮助理解。(代码标红部分为自己加入调试为打印变量值所用)
tests/tools.py
from nose.tools import *
import re
def pt(resp,contains=None,matches=None,headers=None,status=None):
print 'resp:'.resp
print ' resp.data:',resp.data #个人加入调试,为打印出每次调用变量值
print 'contains:',contains
print 'matches:',matches
print 'headers:',headers
print 'status:',status
print '******************************************************************'
def assert_response(resp, contains=None, matches=None, headers=None, status="200"):
assert status in resp.status, "Expected response %r not in %r" % (status, resp.status)
if status == "200":
assert resp.data, "Response data is empty."
if contains:
assert contains in resp.data, "Response does not contain %r" % contains
if matches:
reg = re.compile(matches)
assert reg.matches(resp.data), "Response does not match %r" % matches
if headers:
assert_equal(resp.headers, headers)
tests/app_tests.py
from nose.tools import *
from bin.app import app
from tests.tools import assert_response
from tests.tools import pt #个人加入调试,为打印出每次调用变量值
def test_index():
# check that we get a 404 on the / URL
resp = app.request("/")
assert_response(resp, status="404")
pt(resp) #个人加入调试,为打印出每次调用变量值
# test our first GET request to /hello
resp = app.request("/hello")
assert_response(resp)
pt(resp) #个人加入调试,为打印出每次调用变量值
# make sure default values work for the form
resp = app.request("/hello", method="POST")
assert_response(resp, contains="Nobody")
pt(resp) #个人加入调试,为打印出每次调用变量值
# test that we get expected values
data = {'name': 'Zed', 'greet': 'Hola'}
resp = app.request("/hello", method="POST", data=data)
assert_response(resp, contains="Zed")
pt(resp) #个人加入调试,为打印出每次调用变量值
test_index() #个人加入调试,为打印出每次调用变量值
我将每一次调用assert_response(),各个变量的值打印出来:(**********表示第一次调用结束)
resp: <Storage {'status': '404 Not Found', 'headers': {'Content-Type': 'text/html'}, 'header_items': [('Content-Type', 'text/html')], 'data': 'not found'}>
resp.data: not found
contains: None
matches: None
headers: None
status: None
********************************************************
resp: <Storage {'status': '200 OK', 'headers': {'Content-Type': 'text/html; charset=utf-8'}, 'header_items': [('Content-Type', 'text/html; charset=utf-8')], 'data': '<h1>Fill Out This Form</h1>\n\n<form action="/hello" method="POST">\n A Greeting: <input type="text" name="greet">\n <br/>\n Your Name: <input type="text" name="name">\n <br/>\n <input type="submit">\n</form>\n'}>
resp.data: <h1>Fill Out This Form</h1>
<form action="/hello" method="POST">
A Greeting: <input type="text" name="greet">
<br/>
Your Name: <input type="text" name="name">
<br/>
<input type="submit">
</form>
contains: None
matches: None
headers: None
status: None
********************************************************
resp: <Storage {'status': '200 OK', 'headers': {'Content-Type': 'text/html; charset=utf-8'}, 'header_items': [('Content-Type', 'text/html; charset=utf-8')], 'data': '\nI just wanted to say <em style="color: green; font-size: 2em;">Hello, Nobody</em>.\n'}>
resp.data:
I just wanted to say <em style="color: green; font-size: 2em;">Hello, Nobody</em>.
contains: None
matches: None
headers: None
status: None
********************************************************
resp: <Storage {'status': '200 OK', 'headers': {'Content-Type': 'text/html; charset=utf-8'}, 'header_items': [('Content-Type', 'text/html; charset=utf-8')], 'data': '\nI just wanted to say <em style="color: green; font-size: 2em;">Hola, Zed</em>.\n'}>
resp.data:
I just wanted to say <em style="color: green; font-size: 2em;">Hola, Zed</em>.
contains: None
matches: None
headers: None
status: None
********************************************************
___________________________________________________
assert断言语句
assert 1==2,‘不等于!’
若表达式为真则无回显,若不为真,则抛出异常。
app.request("/"):为发送一个url请求后,值为服务器返回的响应。
[笨方法学python]习题51自动化测试笔记的更多相关文章
- "笨方法学python"
<笨方法学python>.感觉里面的方法还可以.新手可以看看... 本书可以:教会你编程新手三种最重要的技能:读和写.注重细节.发现不同.
- 笨方法学python 22,前期知识点总结
对笨方法学python,前22讲自己的模糊的单词.函数进行梳理总结如下: 单词.函数 含义 print() 打印内容到屏幕 IDLE 是一个纯Python下自带的简洁的集成开发环境 variable ...
- python--笨方法学python 习题52
笨方法学python是一本不错的python入门书籍.书的最后一节是一个web版的游戏程序,以下是程序代码: 1.项目的目录结构如下所示:skeleton\ app.py map.py templat ...
- 笨办法学Python - 习题1: A Good First Program
在windows上安装完Python环境后,开始按照<笨办法学Python>书上介绍的章节进行练习. 习题 1: 第一个程序 第一天主要是介绍了Python中输出函数print的使用方法, ...
- 笨方法学python学习笔记
创建于:2016-02-29 更新于:03-02 python版本:2.7 %r 用来做 debug 比较好,因为它会显示变量的原始数据(raw data),而其它的符号则是用来向用户展示输出的: 每 ...
- 笨方法学python笔记
编程是什么 编程就是通过输出一种语言给计算机"听",命令其去执行相应的操作. 我们称我们给计算机下达的命令称为指令.一般说程序就是有多个指令构成的. 计算机需要使用非常多的电路来实 ...
- [笨方法学Python]ImportError"No module named bin.app"【笔记】
运行nosetests时,出现:ImportError"No module named bin.app" 解决方法: 1.检查路径是否是bin/app.py 2.检查是否创建bin ...
- 《笨方法学Python》加分题28
#!usr/bin/python # -*-coding:utf-8-*- True and True print ("True") False and True print (& ...
- 《笨方法学Python》加分题16
基础部分 # 载入 sys.argv 模块,以获取脚本运行参数. from sys import argv # 将 argv 解包,并将脚本名赋值给变量 script :将参数赋值给变量 filena ...
随机推荐
- 微信小程序把玩(二十二)action-sheet组件
原文:微信小程序把玩(二十二)action-sheet组件 action-sheet组件是从底部弹出可选菜单项,估计也是借鉴IOS的设计添加的,action-sheet有两个子组件, action-s ...
- Advanced Installer 11.9基于IIS打包札记(For MySQL)
原文:Advanced Installer 11.9基于IIS打包札记(For MySQL) Mysql免安装前期部署 下载绿色命令行版本的mysql,将其放入到发布的程序发布包内,执行Update批 ...
- A Summaryof JDBC
Die Sonne gewinnen! I think it's easy to understand what is JDBC used for. Programer's program shoul ...
- File handling in Delphi Object Pascal(处理record类型)
With new users purchasing Delphi every single day, it’s not uncommon for me to meet users that are n ...
- 重写QLineEdit,实现编辑框内添加删除按钮的功能(随时把控件Move到一个地方,然后show就可以了,这是万能的办法)
http://www.qtcn.org/bbs/read-htm-tid-62265-ds-1-page-1.html#180286
- 15 款 jQuery 社交分享插件
过去几年中社交媒体越来越流行了,能够分享音乐.视频.图像甚至是其他的 docs 文档到互联网上去,这样子还能够提高页面的点击量.通常,一些社交媒体插件都能允许你的用户分享你网站上的内容到其他的社交平台 ...
- Kafka Topic的详细信息 捎带主要的安装步骤
1. 安装步骤 Kafka伪分布式安装的思路跟Zookeeper的伪分布式安装思路完全一样,不过比Zookeeper稍微简单些(不需要创建myid文件), 主要是针对每个Kafka服务器配置一个单独的 ...
- Spark之从hdfs读取数据
/user/hive/warehouse/ycapp.db/appindex") ), e(),e().toInt)) (String, String, String) ,,all_post ...
- 30443数据查询语言DQL
5.4 SQL的数据查询功能 数据查询是数据库最常用的功能.在关系数据库中,查询操作是由SELECT语句来完成.其语法格式如下: SELECT column_expression FROM table ...
- Servlet 3.0异步特性初探
Servlet 是 Java 为了编写服务端程序而定义的一个接口规范,在 Servlet 3.0 以后支持了异步的操作. 最近项目添加了一个代码热部署的功能,在客户端输入信号,信号到达 Web 服务器 ...