1👍
✅
When you use a RequestFactory
you can give the request any request parameters. In this case you are looking for the request.LANGUAGE_CODE
so the solution is to set the LANGUAGE_CODE
in your test’s RequestFactory
.
You can see the documentation for the RequestFactory
here.
So solution is:
def test_anonymous(self):
req = RequestFactory().get('/')
# Here is the change.
req.LANGUAGE_CODE = "en"
resp = views.IndexView.as_view()(req)
assert resp.status_code == 200, 'Should be callable by anyone'
Source:stackexchange.com