每一个控制器,在tests/functional 目录下都一个对应的单元测试文件。 Pylons的单元测试是使用 paste.fixture 来模拟浏览器对Web服务器的访问, 通过对返回结果的检查实现测试。
测试用例的运行,还是使用nosetests,nosetests能够主动到tests目录下发现测试用例, 并运行。
在setup.cfg文件中,对nosetests进行设置。可以设置采用不同的pylons配置文件。
[nosetests] verbose=True verbosity=2 with-pylons=test.ini # 使用test.ini作为pylons的配置文件 detailed-errors=1 #with-doctest=1 # 不进行 doctest测试,因为依赖的confobj包的doctest不通过
res = self.app.get(url_for(controller='check')) assert res.status == 200 assert '''<input type="submit" name="submit" value='Check Permissions'>''' in res.body assert res.c.reposlist == ['/', u'repos1', u'repos2', u'repos3', u'document']
params = {
'userinput':'select',
'userselector':'user1',
'reposinput':'select',
'reposselector':'repos1',
'pathinput':'manual',
'pathname':'/trunk/src/test',
'abbr':'True',
}
res = self.app.get(url_for(controller='check', action='access_map'), params)
assert res.status == 200
assert '''<div id='acl_path_msg'>[repos1:/trunk/src/test] user1 =</div>''' in res.body, res.body
Copyright © 2006 WorldHello 开放文档之源 计划 |