Re: [Repoze-dev] functional testing with @bfg_view

2010-06-30 Thread Chris Withers
Alex Marandon wrote:
> 
> 
> On 29 June 2010 04:44, Chris Withers  > wrote:
> 
> But now what's the "right" way to actually get the to render the html,
> preferably also testing the path dispatch to '/' at the same time?
> 
> 
> I'm not sure if it's the "right" way, but I use WebTest, a generic WSGI 
> testing framework:  http://pythonpaste.org/webtest/

FWIW, this his the spot with me...

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] functional testing with @bfg_view

2010-06-29 Thread Chris McDonough
On Wed, 2010-06-30 at 06:50 +0100, Chris Withers wrote:
> Chris McDonough wrote:
> > ... in the test setup.  If so, you actually need to do:
> > 
> > config.scan('mypackage')
> > 
> > .. where mypackage is the name of the Python package holding the
> > application you're trying to test.
> 
> That won't help, since the ViewIntegrationTests linked to my Alex still 
> call the view directly, which won't trigger any of the stuff that 
> venusian does, or any imperative configuration, or even anything 
> configured via zcml unless `my_view` happens to render its own template 
> inside the body of the function, which I'd guess most views avoid doing 
> as it makes them harder to unit test...

True.  I guess Alex' statement about "works via ZCML only"  made me
offer the above suggestion as a
hail-mary-aha-this-is-obvious-and-maybe-I-dont-need-to-think-very-hard-about-helping-here
 answer. ;-)  But alas, ZCML vs. scanning isn't the difference at all, so I'm 
not sure what worked via ZCML and what didn't work via scanning at all.

As far as integration testing of a view, you might be able to use the
render_view API if you can arrange for the context, request, and view
name to be right:
http://docs.repoze.org/bfg/1.3/api/view.html#repoze.bfg.view.render_view


- C


___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] functional testing with @bfg_view

2010-06-29 Thread Chris Withers
Chris McDonough wrote:
> ... in the test setup.  If so, you actually need to do:
> 
> config.scan('mypackage')
> 
> .. where mypackage is the name of the Python package holding the
> application you're trying to test.

That won't help, since the ViewIntegrationTests linked to my Alex still 
call the view directly, which won't trigger any of the stuff that 
venusian does, or any imperative configuration, or even anything 
configured via zcml unless `my_view` happens to render its own template 
inside the body of the function, which I'd guess most views avoid doing 
as it makes them harder to unit test...

cheers,

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] functional testing with @bfg_view

2010-06-29 Thread Chris McDonough
On Wed, 2010-06-30 at 12:02 +0700, Alex Marandon wrote:
> 
> 
> On 29 June 2010 04:44, Chris Withers  wrote:
> But now what's the "right" way to actually get the to render
> the html,
> preferably also testing the path dispatch to '/' at the same
> time?
> 
> 
> I'm not sure if it's the "right" way, but I use WebTest, a generic
> WSGI testing framework:  http://pythonpaste.org/webtest/
> 
> 
> The method described at
> http://docs.repoze.org/bfg/current/narr/unittesting.html#creating-integration-tests
>  didn't work for me (ie: I'm still getting a dict, instead of a response 
> object). I believe it doesn't work with decorators scanning, only with what 
> is configured in the zcml file.

When you say scanning doesn't work, it's likely you're doing:

config.scan()

... in the test setup.  If so, you actually need to do:

config.scan('mypackage')

.. where mypackage is the name of the Python package holding the
application you're trying to test.

- C



___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] functional testing with @bfg_view

2010-06-29 Thread Alex Marandon
On 29 June 2010 04:44, Chris Withers  wrote:
>
> But now what's the "right" way to actually get the to render the html,
> preferably also testing the path dispatch to '/' at the same time?
>

I'm not sure if it's the "right" way, but I use WebTest, a generic WSGI
testing framework:  http://pythonpaste.org/webtest/

The method described at
http://docs.repoze.org/bfg/current/narr/unittesting.html#creating-integration-testsdidn't
work for me (ie: I'm still getting a dict, instead of a response
object). I believe it doesn't work with decorators scanning, only with what
is configured in the zcml file.

Good luck,
Alex
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


[Repoze-dev] functional testing with @bfg_view

2010-06-28 Thread Chris Withers
Hi All,

I have a view that starts like this:

@bfg_view(renderer='templates/control.pt')
class Control:

 def __init__(self,request):
 self.request = request

 def __call__(self):
 ...
 return dict(
 ...
 )


I'd like to do a functional test, in particular checking that the 
template has no syntax errors in it and contains the data it should do 
by checking for strings in the returned response.

I got this far:

class TestView(TestCase):

 def setUp(self):
 self.request = testing.DummyRequest()
 self.config = Configurator()
 self.config.begin(request=self.request)
 self.config.scan(myapp)

 def tearDown(self):
 self.config.end()


 def test_render(self):
 view = Control(self.request)

But now what's the "right" way to actually get the to render the html, 
preferably also testing the path dispatch to '/' at the same time?

cheers,

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
 - http://www.simplistix.co.uk
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev