The web framework that scales with you. TurboGears 2.4.3 released https://github.com/TurboGears/tg2/releases/tag/tg2.4.3
brondsem on 0.12.0
brondsem on master
[#39] Removal of __future__ imp… [#39] pyupgrade --py37-plus run [#39] remove six dependency and 4 more (compare)
brondsem on master
helper to replace session - fro… test improvements - from #45 (compare)
@require(predicated.not_anonymous())
and the response from self.app.get("/the_url",extra_environ={'REMOTE_USER':'test_user'},response=200)
is always a 401.
@jknapka I suggest you verify the controller from which you are inheriting. There is a class attribute application_under_test
(or something similar) that specified which configuration should be used to create the application instance used for the tests.
By default there are two applications configured in test.ini
the main
and mainnoauth
(or something similar).
The noauth
one supports faking authentication with the REMOTE_USER
, while the other one requires you do to a self.app.post('/login_handler')
to actually log before your can call authenticated endpoints
main_without_authn
the app name that accepts REMOTE_USER
, just checked the name)
test_root
which uses main_without_authn
(actually doesn't specify anything and main_without_authn
is the default) and test_authentication
which has application_under_test = 'main'
at the begin of the controller.
test_root
can use REMOTE_USER
test_authentication
do use real authentication and cookies
Traceback (most recent call last):
File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/nose/case.py", line 198, in runTest
self.test(*self.arg)
File "/Users/jk/Software/unter/src/tg/unter/unter/tests/functional/test_multi_alerts.py", line 86, in test_0_oneVolunteerEvent
self.sendAlert(ev_id=1)
File "/Users/jk/Software/unter/src/tg/unter/unter/tests/functional/test_multi_alerts.py", line 82, in sendAlert
need.checkOneEvent(model.DBSession,ev_id=ev_id,honorLastAlertTime=False)
File "/Users/jk/Software/unter/src/tg/unter/unter/controllers/need.py", line 27, in checkOneEvent
debugTest(_("Checking need event {} {}").format(ev_id,notes))
File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/TurboGears2-2.4.0a1-py3.7.egg/tg/i18n.py", line 87, in ugettext
return tg.translator.gettext(value)
File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/TurboGears2-2.4.0a1-py3.7.egg/tg/support/objectproxy.py", line 19, in __getattr__
return getattr(self._current_obj(), attr)
File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/TurboGears2-2.4.0a1-py3.7.egg/tg/request_local.py", line 233, in _current_obj
return getattr(context, self.name)
File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/TurboGears2-2.4.0a1-py3.7.egg/tg/support/objectproxy.py", line 19, in __getattr__
return getattr(self._current_obj(), attr)
File "/Users/jk/Software/py3-venv-2/lib/python3.7/site-packages/TurboGears2-2.4.0a1-py3.7.egg/tg/support/registry.py", line 72, in _current_obj
'thread' % self.____name__)
TypeError: No object (name: context) has been registered for this thread
I don't know where to begin fixing this. Advice would be appreciated. Thanks!
lazy_ugettext()
should work without an active request. However, replacing all the _()
calls with l_()
calls in my utility code does not solve the problem. For the moment I've "solved" the problem by using my own _()
and l_()
functions that check whether a context exists, and if not, returns the untranslated string. This doesn't seem like an especially good solution, though.
lazy_ugettext
can solve that problem if you don't try to resolve the string. Like if you try to print, show or concatenate the string it will resolve it.
@jknapka another idea would be to mock-patch _()
in the "offending" module, e.g. like this (careful, untested):
from unittest.mock import patch
...
@patch('unter.controllers.need._', lambda x: x)
def test_0_oneVolunteerEvent(self, ..., patched_gettext):
...
self.sendAlert(ev_id=1)
...
This will replace _()
in unter.controllers.need
with a lambda that simply returns the untranslated text while the decorated test method is executed (and pass it into the method as patched_gettext
in case you want to inspect it in your test).
Ah, if we are talking about tests, I think this is what you are looking for: https://turbogears.readthedocs.io/en/latest/turbogears/testing.html#testing-outside-controllers
So that you have a translator in place even without a request