Hi Alessandro, maybe a bit too late, but could that also be used to initialize a fake context when running some part of a TG2 project from outside of a web application? Like when there is a script to do some maintenance stuff that imports a file that imports ugettext, which will fail the same way as the OP posted.
Regards, Moritz On 14.01.2015 15:27, Alessandro Molina wrote: > I made a change in TG2.3.5 which will make easier to perform tests on > things outside controllers and wrote a short documentation on writing tests > with TurboGears: > http://turbogears.readthedocs.org/en/development/turbogears/testing.html > > This should greatly help people with most common issues with testing > TurboGears apps :) > > On Wed, Jan 7, 2015 at 7:12 PM, Alessandro Molina < > [email protected]> wrote: > >> This is something I have been thinking of for a bunch of weeks. >> >> The two options are: >> >> 1) Make possible to pass a base_url optional argument to tg.url which is >> used instead of the request for URL generation. This is a specific solution >> but less invasive. >> 2) Make a reusable method that initializes a fake TurboGears Context so >> that all request related features can work even outside a request. This is >> the most flexible solution but might actually create huge bugs and issues >> when misused. >> >> In the mean time you can probably achieve the same result by doing the >> same that ``tgshell`` command does, just create a TurboGears webapp (you >> should have it already in your test suite) and call >> ``test_app.get('/_test_vars')`` this will create a context that is >> permanently available for the whole process lifetime and so you can then >> call any context based function. >> >> >> >> On Tue, Dec 23, 2014 at 11:57 AM, lebouquetin <[email protected]> >> wrote: >> >>> Hi all, >>> >>> I have developed a serialization class which is based on tg.url(). When >>> trying to unit-test it using nose, I get the following error: >>> >>> ====================================================================== >>> ERROR: >>> tracim.tests.library.test_serializers.TestSerializers.test_serialize_Content_comment_THREAD >>> ---------------------------------------------------------------------- >>> Traceback (most recent call last): >>> File >>> "/home/damien/proj/tracim-app/pod/tg2env/lib/python3.2/site-packages/nose/case.py", >>> line 198, in runTest >>> self.test(*self.arg) >>> File >>> "/home/damien/proj/tracim-app/pod/tracim/tracim/tests/library/test_serializers.py", >>> line 117, in test_serialize_Content_comment_THREAD >>> res = Context(CTX.THREAD).toDict(obj) >>> File >>> "/home/damien/proj/tracim-app/pod/tracim/tracim/model/serializers.py", line >>> 191, in toDict >>> result = self.toDictSpecific(serializableObject) >>> File >>> "/home/damien/proj/tracim-app/pod/tracim/tracim/model/serializers.py", line >>> 205, in toDictSpecific >>> result = converter_function(serializableObject, self) # process the >>> object with the given serializer >>> File >>> "/home/damien/proj/tracim-app/pod/tracim/tracim/model/serializers.py", line >>> 409, in serialize_node_for_page >>> 'delete': >>> context.url('/workspaces/{wid}/folders/{fid}/{ctype}/{cid}/comments/{commentid}/put_delete'.format(wid >>> = item.workspace_id, fid=item.parent.parent_id, ctype=item.parent.type+'s', >>> cid=item.parent.content_id, commentid=item.content_id)) >>> File >>> "/home/damien/proj/tracim-app/pod/tracim/tracim/model/serializers.py", line >>> 142, in url >>> url = tg.url(base_url, params) >>> File >>> "/home/damien/proj/tracim-app/pod/tg2env/lib/python3.2/site-packages/TurboGears2-2.3.4-py3.2.egg/tg/controllers/util.py", >>> line 84, in url >>> req = tg.request._current_obj() >>> File >>> "/home/damien/proj/tracim-app/pod/tg2env/lib/python3.2/site-packages/TurboGears2-2.3.4-py3.2.egg/tg/request_local.py", >>> line 171, in _current_obj >>> return getattr(context, self.name) >>> File >>> "/home/damien/proj/tracim-app/pod/tg2env/lib/python3.2/site-packages/TurboGears2-2.3.4-py3.2.egg/tg/support/objectproxy.py", >>> line 19, in __getattr__ >>> return getattr(self._current_obj(), attr) >>> File >>> "/home/damien/proj/tracim-app/pod/tg2env/lib/python3.2/site-packages/TurboGears2-2.3.4-py3.2.egg/tg/support/registry.py", >>> line 69, in _current_obj >>> 'thread' % self.____name__) >>> *nose.proxy.TypeError: No object (name: context) has been registered for >>> this thread* >>> >>> Question is : how to use tg.url() in unit-tests (without to go through >>> http-like class). >>> Should I call load_app() ? >>> >>> Thank's >>> >>> >>> Damien >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "TurboGears" group. >>> To unsubscribe from this group and stop receiving emails from it, send an >>> email to [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at http://groups.google.com/group/turbogears. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> > -- Moritz Schlarb -- You received this message because you are subscribed to the Google Groups "TurboGears" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/turbogears. For more options, visit https://groups.google.com/d/optout.

