[笨方法学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 ...
随机推荐
- CROSS JOIN
原文:CROSS JOIN 最近在讲到T-SQL查询的Join部分时,一下子没有想起来CROSS JOIN的用法,因为其实平常也确实基本不用到.特意找了一个例子,以供参考 CROSS JOIN又称为笛 ...
- flume本地调试
本机idea远程调试flume:https://blog.csdn.net/u012373815/article/details/60601118 遇到 [root@hadoop02 bin]# ./ ...
- A simple in-process HTTP server for UWP
原文 http://www.dzhang.com/blog/2012/09/18/a-simple-in-process-http-server-for-windows-8-metro-apps 简单 ...
- firemonkey 手机屏幕自适应程序问题
我是新手.在我才学了2个星期的时候,那个白痴老板说什么手机屏幕自适应程序,我当时不能理解呀,觉得用Delphi的布局设计不就行了吗.结果他说:我就是想让控件内容什么的放在小屏幕手机上也不出来.我就说, ...
- JavaWeb实现上传文件
需要 commons-io与commons-fileupload 首先在jsp中创建一下布局 <%@ page contentType="text/html;charset=UTF-8 ...
- 虚拟机安装 ubuntu 后,更新源无效,以及无法联网安装软件的问题
问题: 虚拟机安装 ubuntu 后,更新源无效,以及无法联网安装软件: 错误提示: Err http://security.ubuntu.com/ubuntu/ trusty-security/un ...
- [2017.02.13] linux平台下统计C++项目文件个数和代码行数
#输出排序后文件名 file='find . -name "*.[ch]" | sort' #统计文件个数 filecnt='find . -name "*.[ch]&q ...
- Redis 学习笔记(篇三):跳表
跳表 跳表(skiplist)是一种有序的数据结构,是在有序链表的基础上发展起来的. 在 Redis 中跳表是有序集合(sort set)的底层实现之一. 说到 Redis 中的有序集合,是不是和 J ...
- C语言指针学习总结
上学的时候学习C语言,最烦的就是里面指针,可是指针也恰恰是C语言的灵魂. 最近在重温数据结构的内容,因为大多数据结构的教材都是用C语言描述的,而数据结构中也大量的用到了指针的内容,所以我就在这篇笔记中 ...
- spark 2.x在windows环境使用idea本地调试启动了kerberos认证的hive
1 概述 开发调试spark程序时,因为要访问开启kerberos认证的hive/hbase/hdfs等组件,每次调试都需要打jar包,上传到服务器执行特别影响工作效率,所以调研了下如何在window ...