简体   繁体   English

测试Django URL'名称'是正确的URL

[英]Test Django url 'name' is correct url

I think what I'm trying to is self evident: 我认为我要证明的是不言而喻的:

urls.py urls.py

urlpatterns = [
    path('', views.home_page, name='home_page'),
]

test.py test.py

def test_home_page_view_name_uses_correct_url(self):
    name = self.client.get(reverse('home_page'))
    path = self.client.get('/')

    self.assertEqual(name, path)

But I get this error: 但是我得到这个错误:

AssertionError: <HttpResponse status_code=200, "text/html; charset=utf-8">
             != <HttpResponse status_code=200, "text/html; charset=utf-8">

How can I test this correctly? 如何正确测试?

There doesn't seem to be any reason to involve the client here. 似乎没有任何理由让客户参与这里。

name = reverse('home_page')
path = '/'

self.assertEqual(name, path) self.assertEqual(名称,路径)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM