lundi 24 avril 2017

Django redirects with languages and urlresolvers.reverse

I'm trying to test a redirect to a login page but my desired expected test condition can't match the response.location because of the language settings.

For example, I want to do the following.

self.assertRedirects(response, "{0}?next={1}".format(reverse('auth_login'), reverse('profile')), status_code=302, target_status_code=302)

but the error is

AssertionError: Response redirected to '/accounts/login/?next=/en/profile', expected '/en/accounts/login/?next=/en/profile'

I don't know what the best practice is for this? Should I:

  • Hard code the expected url to '/accounts/login/?next=/en/profile' which is what seems to be implied by the django docs.
  • Make a custom reverse_no_il8n as suggested here that uses regex to chop off the language code from urlresolvers.reverse
  • Something else?

Aucun commentaire:

Enregistrer un commentaire