I wrote a blog project in Django,in some pages i used loginrequierdmixin to make sure user is loged in but in test i got error
test:
def test_get_profile_unauthenticated(self):
response = self.client.get(self.profile_url)
self.assertEqual(response.status_code, 302)
expected_url = f"{self.register_url}?next={self.profile_url}"
self.assertRedirects(response, expected_url)
AssertionError: 302 != 200 : Couldn't retrieve redirection page '/accounts/register/': response code was 302 (expected 200)
i print response:
<HttpResponseRedirect status_code=302, "text/html; charset=utf-8", url="/accounts/register/?next=/en/accounts/profile/1/">
and my exepted url:
/en/accounts/register/?next=/en/accounts/profile/1/
i asked chatGPT and here is response:
def test_get_profile_unauthenticated(self):
self.client.cookies.clear()
with translation.override('en'):
response = self.client.get(self.profile_url, HTTP_ACCEPT_LANGUAGE='en')
self.assertEqual(response.status_code, 302)
expected_url = f"{self.register_url}?next={self.profile_url}"
self.assertRedirects(response, expected_url)
New contributor
ParsaM is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.