0

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?

Carl Brubaker
  • 1,602
  • 11
  • 26
  • You want to test that the URL is the same or you want to test that your '/' URL is rendering a certain view/template? – dfundako Jul 23 '18 at 21:51
  • I would recommend the testing goat free e-book and the chapter on unit testing your home page: https://www.obeythetestinggoat.com/book/chapter_unit_test_first_view.html – dfundako Jul 23 '18 at 21:53
  • I guess the same view. I want to make sure that when I use the name, the path is the same as using the hardcoded path – Carl Brubaker Jul 23 '18 at 21:54
  • I just finished that book. He didn't cover that specifically. Maybe it isn't necessary? @dfundako – Carl Brubaker Jul 23 '18 at 21:55

1 Answers1

1

There doesn't seem to be any reason to involve the client here.

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

self.assertEqual(name, path)

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895