[笨方法学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 ...
随机推荐
- 零元学Expression Blend 4 - Chapter 17 用实例了解互动控制项「CheckBox」I
原文:零元学Expression Blend 4 - Chapter 17 用实例了解互动控制项「CheckBox」I 本章将教大家如何运用CheckBox做实作上的变化:教你如何把CheckBox变 ...
- C# 委托参数方法实例
/// <summary> /// 方法委托 /// </summary> /// <param name="dwEnrollNum">< ...
- Portal for ArcGIS 资源承载数据类型
在Portal中数据主要分为两大类:Web内容与桌面内容.对于Web内容与桌面内容中的每个项目(item)又被具体分为maps,layers, styles, tools,applications,和 ...
- PowerDesigner逆向工程导入MYSQL数据库总结(不容易,感谢前者们)
原文:PowerDesigner逆向工程导入MYSQL数据库总结(不容易,感谢前者们) 参考来源: http://blog.csdn.net/chamtianjiao/article/details/ ...
- 了解Service
多线程编程: 线程的基本用法: 1. class MyThread extends Thread{ @Override public void run() { //处理具体逻辑 } } new MyT ...
- 程序的开机关机重启,开机启动,休眠功能delphi实现(使用AdjustTokenPrivileges提升权限)
TShutDownStatus = (sdShutDown,sdReboot,sdLogOff,sdPowerOff); procedure ShutDown(sdStatus : TShutDown ...
- .NET重思(一)sealed和interface
博主这几天正好闲着,砸砸基础,毕竟自学,基础不牢靠很致命,要踏实啊~~~ 1.sealed关键字修饰一个类,也可以修饰实现方法或者属性.当sealed用于修饰一个类时,这个类不可以被继承,因此,这个类 ...
- Qt实现长文件名(字符串)在QLabel中自适应缩短
一.应用场景简述 当在有限宽度的QLable中显示很长的文件名/字符串时,超出QLabel宽度部分将不会显示,此时采取缩短文件名策略(也可实现为字符串滚动动画)可以缓解这一问题.在实现这一想法的过程中 ...
- iOS11中iOS处理GIF图片的方式
GIF 五部走如下 : 1 从相册中取出GIF图的Data 2 通过腾讯的IM发送Gif图 3 展示GIF图 4 GIF图URL缓存机制 5 将展示的GIF图存到相册中 一 从相册中 ...
- 云计算核心技术Docker的探索
首先通过一个简单的场景来看一下为什么Docker这么火? 开发人员在开发的时候是有一套开发环境,包括运行的操作系统,依赖的服务比如WebLogic.Java,一些特定的配置,比如JVM大小.字符集,操 ...