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?

4
  • You want to test that the URL is the same or you want to test that your '/' URL is rendering a certain view/template? Commented Jul 23, 2018 at 21:51
  • I would recommend the testing goat free e-book and the chapter on unit testing your home page: obeythetestinggoat.com/book/chapter_unit_test_first_view.html Commented Jul 23, 2018 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 Commented Jul 23, 2018 at 21:54
  • I just finished that book. He didn't cover that specifically. Maybe it isn't necessary? @dfundako Commented Jul 23, 2018 at 21:55

1 Answer 1

1

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

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

self.assertEqual(name, path)

Sign up to request clarification or add additional context in comments.

1 Comment

Of course, it was so simple I couldn't think of it. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.