用于测试整个站点的django应用程序。
django-shotgun的Python项目详细描述
django霰弹枪
django-shotgun是一个django应用程序,它提供 在整个django应用程序中验证http状态代码。 django-shotgun由两部分组成,amanagement command 调用load_shotgun,用 要在Django test case中使用的数据库快照,以及 测试用例本身,它可以帮助Django站点测试有效的HTTP 它找到的每个url的状态代码。
安装
假设您已经安装了pip,最简单的方法是安装 直接从pypi运行以下命令:
$ pip install -U django-shotgun
否则,您可以直接签出源并通过:
$ python setup.py install
安装后,您可以将django_shotgun添加到 INSTALLED_APPS。
霰弹枪装填
django-shotgun与 真实的数据。这与django测试用例将 如果它故意不使用项目的真实数据库 运行测试。django-shotgun通过提供 名为load_shotgun的管理命令,它转储 数据库到名为shotgun.json的fixture。在引擎盖下, load_shotgun扩展了内置的dumpdata命令并支持 同样的选项,还有一个名为path的额外选项,它允许 您可以定义夹具文件的保存位置:
$ python manage.py load_shotgun --path=/path/to/fixtures/
如果省略path选项,fixture文件将保存到 当前项目的根目录。
散弹枪射击
django-shotgun测试用例是标准的django测试用例,并且 因此可以通过调用内置的testmanagement来运行 命令:
$ python manage.py test
django-shotgun测试用例将首先测试url/和 从结果响应中分析在<a>标记中找到的url。那么 对找到的每个url继续此过程,直到所有url 经过测试。<form>标记及其字段元素也被解析并 每个表单都使用GET和POST进行测试,首先不使用 任何字段数据,然后使用每个表单字段的测试值。测试 如果任何响应的状态代码不是200,则case将失败。
配置
可以在项目的^{tt23}中定义以下设置$ 控制django-shotgun行为的模块。
- ^{tt25}$ - A list of app names to exclude when generating the shotgun fixtures file. Defaults to ^{tt26}$.
- ^{tt27}$ - A list of URLs to exclude from checking. Defaults to ^{tt26}$.
- ^{tt29}$ - The name of the fixture file that will be saved and loaded from. Defaults to ^{tt10}$.
- ^{tt31}$ - The path to where the fixture file will be saved and loaded from. Defaults to the project’s root directory.
- ^{tt32}$ - The first URL that the test case will request. Defaults to ^{tt17}$.