On 4/13/10 7:17 PM, Chris McDonough wrote:
> On 4/13/10 7:03 PM, Iain Duncan wrote:
>> Hi, I have some custom middleware that is intended to use the same ZCA
>> registry as my bfg app. I've altered the run.py in the bfg app to tell
>> it to use the global site manager, and the middleware looks up utilities
>> by doing
>> self.gsm = getGlobalSiteManager()
>> self.gsm.queryUtility etc
>> This is all working fine for the app. But recently my isolated tests
>> stopped working. I know the environment is different now, new bfg, newer
>> release of zope.component, but I can't figure out how to make them work
>> anymore. I want the following to give me a registry populated from the
>> configure.zcml file in the pets packag, but instead it seems to be empty:
>> def test_gsm_setup(self):
>> "test_gsm_setup - test that we can setup a zca registry from the model
>> file"
>> import pets
>> xmlconfig.file('configure.zcml', package=pets)
>> gsm = getGlobalSiteManager()
>> assert sm._utility_registrations
> Use the pattern from
> http://docs.repoze.org/bfg/1.2/narr/unittesting.html#test-set-up-and-tear-down
> instead, but extend it just like you did for your BFG app at startup
> time, e.g.:
> def test_gsm_setup(self):
> from repoze.bfg.configuration import Configurator
> from zope.component import getGlobalSiteManager
> gsm = getGlobalSiteManager()
> self.config.begin()
> self.config.load_zcml('pets:configure.zcml')
> self.config.end()
> assert gsm._utility_registrations
> - C

Crap.  There should be a self.config = Configurator() in there.  Hopefully you 
get the idea.

- C

Chris McDonough
Agendaless Consulting, Fredericksburg VA
The repoze.bfg Web Application Framework Book: http://bfg.repoze.org/book
Repoze-dev mailing list

Reply via email to