Re: Changing the language in test client

2009-02-15 Thread peschler

>
> You are misunderstanding what the set_language view does. That view sets
> up the client's locale cookie so that whenever a view is processed for
> that particular web client, it will be done in the locale of "de" (in
> your case).

Ok. Thanks for making this clear.

>
> It does not change the global locale of the entire Django process, or
> the test framework or anything like that. If you are wanting to run a
> particular test in a certain locale, you will have to call
> translation.activate() at the start of the function and
> translation.deactivate() at the end -- don't forget the second one or
> other tests will fail due to being in an unexpected locale.

That's exactly the information I needed. I already hunted it down to
the Translation class but your information is right on spot.

Thanks for the fast answer.

Regards,
Peter Eschler

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Changing the language in test client

2009-02-15 Thread Malcolm Tredinnick

On Sun, 2009-02-15 at 13:29 -0800, peschler wrote:
> Hi,
> 
> i'm currently writing unit tests for an application where I need to
> change the language in the test client.
> 
> I tried using the "django.views.i18n.set_language" view within a test
> case like so:
> 
> ---
> def setUp(self):
> self.client.post('/set_language/', data={'language': 'de'})
> 
> def tearDown(self):
> pass
> 
> def test_registration(self):
> # This is just a duplicate to the above, to sanity check if
> this needs to be
> # called from within each test (unfortunately no..)
> self.client.post('/set_language/', data={'language': 'de'})
> print "get_lang", get_language()
> --
> 
> The url "/set_language/" maps correctly to the
> "django.views.i18n.set_language" view, but the language printed in the
> test case after being set to 'de' is still 'en-us'.

You are misunderstanding what the set_language view does. That view sets
up the client's locale cookie so that whenever a view is processed for
that particular web client, it will be done in the locale of "de" (in
your case). 

It does not change the global locale of the entire Django process, or
the test framework or anything like that. If you are wanting to run a
particular test in a certain locale, you will have to call
translation.activate() at the start of the function and
translation.deactivate() at the end -- don't forget the second one or
other tests will fail due to being in an unexpected locale.

If you are wanting to test the data returned for a particular client
request in a given locale, then using set_language and then making the
request will be the right approach. But it's not a "control the global
locale" function (after all, a single Django install could well be
serving content in many languages simultaneously).

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Changing the language in test client

2009-02-15 Thread peschler

Hi,

i'm currently writing unit tests for an application where I need to
change the language in the test client.

I tried using the "django.views.i18n.set_language" view within a test
case like so:

---
def setUp(self):
self.client.post('/set_language/', data={'language': 'de'})

def tearDown(self):
pass

def test_registration(self):
# This is just a duplicate to the above, to sanity check if
this needs to be
# called from within each test (unfortunately no..)
self.client.post('/set_language/', data={'language': 'de'})
print "get_lang", get_language()
--

The url "/set_language/" maps correctly to the
"django.views.i18n.set_language" view, but the language printed in the
test case after being set to 'de' is still 'en-us'.
Can anybody help me here?
My projects settings.py contains the following variables:
---
LANGUAGE_CODE = 'de-de'

# Languages for modeltranslations
gettext = lambda s: s
LANGUAGES = (
('de', gettext('German')),
('en', gettext('English')),
)
---
As "en-us" is nowhere used here I don't quite understand where the
get_language() call is getting the value from.

Regards,
Peter Eschler
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---