如何编写一个Django测试来检查页面上是否发生错误?

时间:2018-04-12 19:17:32

标签: python django unit-testing testing

我正在调试一个导致某个页面出错的拉取请求:

enter image description here

该视图是Django的通用Utility的子类,并且对应于UpdateView应用中check-ins的网址'family'标签:

dashboard

作为第一步,我想编写一个测试来捕获我看到的内容,即发生错误,以便在我修复之后我可以确定它再也不会发生。

怎么能实现这个目标?我尝试过以下测试用例,

url(
    r'^families/(?P<pk>[0-9]+)/'
    r'(?P<tab>case-management|scheduling|family-demographics|activation-payment|check-ins)$',
    views.FamilyUpdate.as_view(),
    name='family'),

其中from django.test import TestCase from django.urls import reverse from lucy_web.test_factories import FamilyFactory, UserFactory class TestDashboardNavigation(TestCase): '''Test class to simply navigate to pages and click the links, making sure no errors occur''' def setUp(self): self.client.force_login(UserFactory(is_superuser=True)) def test_family_navigation(self): family = FamilyFactory() for tab in ["case-management", "scheduling", "family-demographics", "activation-payment", "check-ins"]: url = reverse('dashboard:family', kwargs={'pk': family.id, 'tab': tab}) response = self.client.get(url) print(response.status_code) 是一个FamilyFactory测试夹具,用于创建factory_boy对象(Family的基础模型),但此测试只是通过:

UpdateView

如何在网页上发现这样的错误?

0 个答案:

没有答案