tg.app_globals is a good place usually, if you need to access it from
outside a request you can use tg.config['tg.app_globals']
In test units you can use self.app.get('/_test_vars') to create the request
context before calling the things that depend on it:
http://turbogears.readthedocs.org/en/development/turbogears/testing.html?highlight=testing#testing-outside-controllers
Just make sure "debug" option is True when running the tests, otherwise it
won't preserve the request context.
This has changed in 2.3.5 which will always preserve the context in tests,
but is not yet released, so in the meanwhile ensure debug=true is in your
test.ini or development.ini
On Fri, Feb 20, 2015 at 10:44 AM, NIWDEK <[email protected]> wrote:
> Hello,
>
> I am implementing a simple pet project with TG2. I am new to this python
> framework. I need to use GCM to send message to devices. I googled and
> found that python-gcm is a good library for me (
> https://pypi.python.org/pypi/python-gcm). According to the doc, I need to
> create GCM() instance. I wonder where should I put the initialization code:
> - in app_globals? I tried but it seems it is quite difficult for me to
> write the test case as app_globals are available in requests only.
> - in controller method? I think I need one gcm instance only within
> the application. I don't think create GCM() object for each request is a
> good solution.
>
> I briefly read the doc of TG2, but still can't find any relevant
> information. Anyone helps? Thanks
>
>
> --
> 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.
>
--
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.