1. Mikhail Korobov
  2. django-webtest
  3. Issues
Issue #7 open

tested application language using WebTest

Rahal Aboulfeth
created an issue


I'm setting my application in french ( using LANGUAGE_CODE = 'fr-FR' ) and it is working OK ( in French ) .

However , my tested application ( while testing using WebTest class ) seems to be in english ( if I print the response, I see english translations.. ).

Anyways, thank you for the great tool.

Comments (5)

  1. Mikhail Korobov repo owner
    • changed status to open

    Hi there,

    Your "real" browser is sending Accept-Language header with your locale (I assume it is French) so app returns French version.

    I think that test client by default doesn't send this header (haven't checked this though) so the application falls back to default value and it seems to be English in your case - just like a browser without locale information.

    Can you confirm this? If this is not the case and test client sends English Accept-Language header then this is non-obvious behavior and it is worth mentioning in README.

    In order to force French locale you can use extra_environ option (it is in the first example in README):

    class MyTestCase(WebTest):
        extra_environ = {'HTTP_ACCEPT_LANGUAGE': 'fr'}

    this way French version should be returned.

    Suggestions/patches/pull requests with README improvements making this all more clear are welcome :)

  2. Rahal Aboulfeth reporter

    Thanks for the quick reply, but the HTTP_ACCEPT_LANGUAGE suggestion didn't work.

    My application is really a French only application, and I don't really need english.

    I also set up my browser (real) to request my pages in english ( Accept-Language ), and my application still shows up in French.

    It seems to me that the internationalization mechanism is Off somehow..

  3. qnub

    Same bug. Try extra_environ = {'HTTP_ACCEPT_LANGUAGE': 'ru'} and headers={'Accept-Language':'ru'} in self.app.get - haven't any effect. I use 'django-localeurl', and that module redirect if language not set in url like '/ru/path' and if make something like

    page = self.app.get('/').follow() #localeurl redirect from '/' to '/ru/'

    page have returned in default language

    But if i use 'reverse' from django.core.urlresolvers like

    page = self.app.get(reverse('view_name_from_urlconf')) #haven't redirect and language is set to 'en'

    project language set to 'en' and adding headers={'Accept-Language':'ru'} in that GET request haven't any effect...

  4. Anonymous

    Hi, As I thought, translation is inactive in test mode. To activate it, I had to add this before my tests :

    # To activate translation..
    from django.utils.translation import activate, deactivate
    # my tests
  5. Laurent Payot

    Same bug on my machine too. I'm using Ubuntu 13.04 64 bit and Python 3.3.1 with the last commit of django, the last commit of webtest and the last commit of django-webtest.

    Vadim shouldn't have to activate the translation language in django tests. Django should detect the language automatically from HTTP_ACCEPT_LANGUAGE. When I test it manually with Firefox the browser language is perfectly detected by Django. So there's definitely a bug. Maybe in webtest if not in django-webtest ??

  6. Log in to comment