On Sat, Nov 09, 2013 at 12:27:11PM +0100, Gael Pasgrimaud wrote:
> Hi,
> 
> On Fri, Nov 08, 2013 at 08:06:09PM -0800, Kristian wrote:
> > I'm using webtest to test a functionality that send an email. I want to 
> > catch the email in my unittest and get a url in the mail to further test. 
> > Only problem, is I can't find how to get the mailer while using a webtest.
> > 
> > In my unittest, here's what I do:
> > 
> > res1 = self.testapp.get(url='/newuser', status=200)
> > form = res1.form
> > form['email'] = '[email protected]'
> > form['passwd'] = 'passwd'
> > form['passwd-confirm'] = 'passwd'
> > res2 = form.submit('submit', status=302)
> > mailer = get_mailer(*THIS NEEDS A REQUEST*)
> > 
> > Is there a way to find the request from res2 ? Or I cannot use webtest with 
> > pyramid_mailer ?
> 
> You can use res2.request. But this one is not the one used in pyramid
> internals. It may work if pyramid_mailer use request.environ to store its
> settings.

I don't think that will work.  Pyramid_mailer stores the mailer in the
registry, not the environ.

https://github.com/Pylons/pyramid_mailer/blob/master/pyramid_mailer/__init__.py#L33

Here's a possible (untested) solution.

Provide a way to pass an explicit registry to your application configuration.
E.g.

     def my_main(global_config, **settings):
         registry = settings.get('testing_registry', None)
         config = Configurator(registry=registry)

         # ...rest of app configuration...

         return config.make_wsgi_app()


Then in your test

     registry = pyramid.registry.Registry()
     app = my_main({}, registry=registry, **other_settings)
     testapp = TestApp(app)

     # ... do your tests with testapp

     # It looks like get_mailer is smart enough that you can pass
     # it either a request or a registry
     mailer = get_mailer(registry) 
    

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to