--
Ticket URL: <https://code.djangoproject.com/ticket/19869>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Can you set the Accept-Language header in the request, or use your
website's "change language" feature?
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:1>
Comment (by void):
Selenium does not let you set custom request headers:
http://code.google.com/p/selenium/issues/detail?id=141.
I am actually trying to test django admin, it have no such "change
language" feature.
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:2>
* stage: Unreviewed => Accepted
Comment:
I think one good way of doing this is to add a new method
"`activate_live_server_locale(self, locale)`" to `LiveServerTestCase` that
would activate the locale in the separate thread. It would be even better
if it could work as a context manager like so:
{{{#!python
class MyTests(LiveServerTestcase):
def test_something(self):
with self.activate_live_server_locale('de'):
...
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:3>
Comment (by julien):
By the way, "activate_live_server_locale" is a bit of a mouthful, so
suggestions for beter names are welcome ;)
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:4>
Comment (by unaizalakain):
How would you modify the thread local of the live server thread from the
main thread?
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:5>
Comment (by void):
With some kind of message or signal, I think
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:6>
Comment (by unaizalakain):
I believe (though I may be wrong) that signals don't work across threads.
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:7>
* owner: nobody => unaizalakain
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:8>
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:9>
* has_patch: 0 => 1
Comment:
PR sent: https://github.com/django/django/pull/2021
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:10>
Comment (by unaizalakain):
The ``set_language`` view could be used to change the live test server
thread language but that would mean adding some kind of new method to the
test case and the inability to use the already defined methods
(`django.utils.translation.override`, `django.utils.translation.activate`,
etc).
Instead, the PR opts for making the thread local that holds the current
active language a non-local. This is done in the two threads so suddenly
one thread is capable of accessing the other one's active language. This
is afterwards reverted to thread locals again.
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:11>
* cc: apollo13 (added)
Comment:
I'd very much prefer a method which just sets the active language in the
other thread as suggested by julien. While the PR might work, it makes me
run away in fear.
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:12>
Comment (by unaizalakain):
Well, it surely isn't the most elegant way of doing it but defining some
special functions for changing the active language when those functions
already exist doesn't seem right to me either.
I think disabling the language thread-local in the testing environment
isn't too bad, after all, it's not needed.
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:13>
* needs_better_patch: 0 => 1
Comment:
If the patch makes apollo13 run, I guess it needs improvement. :-)
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:14>
* status: assigned => new
* needs_better_patch: 1 => 0
* has_patch: 1 => 0
* owner: unaizalakain =>
Comment:
Then more than an improvement, I think a totally different patch is
needed, although I don't understand the need for a language thread-local
in a testing environment that doesn't support multithreading.
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:15>
* owner: => gchp
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:16>
Comment (by void):
The initial goal of this ticket was to deal with issue that emerged while
working on the #18767.
That is, translation.override was not able to change thread-local state of
`LiveServerThread`, and it rendered everything in one language.
#18767 ticket is fixed now and thread-local issue resolved by introducing
settings_changed signal and its receivers, in particular to the
`trans_real._active = threading.local()` line in `django.test.signals`.
Therefore, I think it's safe to close this ticket as wontfix.
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:17>
* status: assigned => closed
* resolution: => wontfix
--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:18>