[笨方法学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 ...
随机推荐
- 微信小程序把玩(三十四)Audio API
原文:微信小程序把玩(三十四)Audio API 没啥可值得太注意的地方 重要属性: 1. wx.getBackgroundAudioPlayerState(object) 获取播放状态 2.wx.p ...
- Android应用开机自启动问题
本文主要介绍Android应用如何实现开机自启动.自启动失败的原因以及通过ADB命令模拟发送BOOT_COMPLETED开机广播. 1.Android应用如何实现开机自启动 (1) 实现一个广播类,接 ...
- wchar_t string on Linux, OS X and Windows
Making wchar_t work on Linux, OS X and Windows for CMarkup release 10.1 I learned a couple of humble ...
- _stricmp, _wcsicmp, _mbsicmp, _stricmp_l, _wcsicmp_l, _mbsicmp_l 比较函数
https://msdn.microsoft.com/en-us/library/k59z8dwe.aspx
- 使用 acl 编写 UDP 网络程序(UDP 重传及可靠性机制)
在当今网络世界,虽然大部分网络应用都是基于 TCP 的,但有时 UDP 的网络通信也有用武之处.acl 的网络库中不仅提供了基于 TCP 的网络套接字流,同时也提供了 UDP 的网络库(目前 acl ...
- [每天记录一个Bug]Cell中由于block加载网络请求产生的复用
Bug 出现场景: cell中使用加载图片的网络请求出现复用,截图如下: 复用原因: Cell Model中只有一个用户的uid,所有用户相关信息:例如头像\名称\信息等是通过 ...
- C语言实现常用数据结构——链表
#include<stdio.h> #include<stdlib.h> typedef struct Node { int data; struct Node *next; ...
- python列表的内建函数
list.append(obj) 向列表中添加一个对象obj list.count(obj) 返回一个对象obj 在列表中出现的次数 list.extend(seq)a 把序列seq 的内容添加到列表 ...
- python+Django 下JWT的使用
figure:first-child { margin-top: -20px; } #write ol, #write ul { position: relative; } img { max-wid ...
- Mac下安装redis5.0 与命令
参考链接:https://blog.csdn.net/zyp1376308302/article/details/84257606 参开链接2:https://www.cnblogs.com/guan ...