我正在调试一个导致某个页面出错的拉取请求:
该视图是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
如何在网页上发现这样的错误?