python - Django - 测试页面的 500 状态

标签 python django unit-testing internal-server-error

我有一个项目,其中一些更改可能会导致某些 View 中的 500 状态。

什么是最优雅的单元测试方法来检查所有 View /页面(使用静态路由,当然没有 vars)是否返回 500 状态?

最佳答案

对于单元测试,您可以使用类似的东西:

from django import test
from django.core.urlresolvers import reverse
from page.urls import urlpatterns

class PageTest(test.TestCase):

   def test_responses(self):
       for url in urlpatterns:
           response = self.client.get(reverse(url.name))
           self.assertEqual(response.status_code, 200)

关于python - Django - 测试页面的 500 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13781563/

相关文章:

javascript - 显示评论而不刷新

python - python单元测试中的assertRaises没有捕获异常

c# - 使用反射在 C# 中引发事件的单元测试

python - 区分具有未知功能的产品 - sympy

python - 使用 python 子进程和 ssh 读取远程文件?

python - 使用 Python 将 JSON 字符串转换为 dict

django - 如何将所见即所得编辑器与 django flatpages 集成?

python - 动态服务 django docker 容器

php - 在 PHPUnit 测试中找不到 Slim/Http/Environment

python - CherryPy:创建在 apache2 后面运行的 Web 服务 (mod_wsgi)