简体   繁体   中英

Test Django url 'name' is correct url

I think what I'm trying to is self evident:

urls.py

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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