I want to write a unit test than checks where I was redirected.
There are 2 behaviours depending on number of players in a room. I want to check this function:
@login_required
def game_join(request, id):
game = Game.objects.get(pk=id)
if game.players_ready == game.max_players:
return redirect('home',name="full")
else:
return redirect('detail', game.id)
Test:
def test_join_empty_room(self):
game = Game.objects.create(name='empty',host='dottore',is_played=False,max_players=4,players_ready=0)
self.join_url_empty = reverse('game_join', args=[game.id])
response = self.client.get(self.join_url_empty, follow=True)
print(response.redirect_chain)
self.assertEquals(response.status_code,200)
Test answer is ok.
Redirect chain: [('/player/login?next=/game/1/join', 302)]
So it gives me no info, since url patterns are like this:
path('<int:id>/', detail, name = 'detail'),
path('<int:id>/join', game_join, name = 'game_join'),
So correct answer should be sth like:
http://127.0.0.1:8000/game/64/
How to do that correctly?