I am a Django novice and I am trying to proceed with a simple application testing. One of my tests fails but I cannot find the reason why. I added several prints to clear what was going on.
The test function that fails is:
def test_board_topics_view_contains_navigation_links(self):
board_topics_url = reverse('board_topics', kwargs={'pk': 1})
print("49: board_topic = " + board_topics_url)
homepage_url = reverse('home')
print("51: homepage_url = " + homepage_url)
new_topic_url = reverse('new_topic', kwargs={'pk': 1})
print("53: new_topic_url = " + new_topic_url)
response = self.client.get(board_topics_url)
print("*****************\n")
print(response)
print('********************\n')
self.assertContains(response, 'href="{0}"'.format(homepage_url))
self.assertContains(response, 'href="{0}"'.format(new_topic_url))
Then I can see the output:
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
.49: board_topic = /boards/1/
51: homepage_url = /
53: new_topic_url = /boards/1/new/
*****************
<HttpResponseNotFound status_code=404, "text/html">
********************
It looks like board_topics_url is not working. But in my chrome explorer it works very good and returns a page with both links homepage_url = '/' and new_topic_url = '/boards/1/new/':
...
<li class="breadcrumb-item"><a href="/">Boards</a></li>
<li class="breadcrumb-item active">Django</li>
</ol>
<div class="mb-4">
<a href="/boards/1/new/" class="btn btn-primary">New topic</a>
</div>
...
Both links are working correctly.
Please, any idea what could be wrong? Thank you very much for any help.
Aucun commentaire:
Enregistrer un commentaire