Thank you for your clear answer Michael, much appriciated.

I re-factored the tests making use of "mockers" instead of real calls to 
the database. Will try to create some functional test using WebTest in the 
near future.

Kind regards,

Tjelvar

On Wednesday, April 3, 2013 4:00:06 PM UTC+1, Michael Merickel wrote:
>
> The triggering of things like this is done in Pyramid's real request 
> pipeline, which you are not simulating here by invoking the view directly. 
> The DummyRequest supports catching finished_callbacks so that you may see 
> what was added to the request, but it does not invoke them.
>
> If you want to simulate things like this you need to make a functional 
> test using something like WebTest that can shove a request through 
> Pyramid's router and invoking all machinery.
>
>
> On Wed, Apr 3, 2013 at 6:34 AM, Tjelvar <[email protected]<javascript:>
> > wrote:
>
>> Dear all,
>>
>> I'm not sure if this is the expected behaviour or not. In the 
>> documentation it states that DummyRequests implement add_finished_callback.
>>
>> http://docs.pylonsproject.org/projects/pyramid/en/latest/whatsnew-1.2.html
>>
>> However, to me it seems like the added callbacks never get called when I 
>> run the tests.
>>
>> What I did.
>>
>> 1. Created a new "starter" project using pcreate
>> 2. Modified the __init__.py file to include the lines
>>
>> from pyramid.events import NewRequest
>> from pyramid.events import subscriber
>>
>> @subscriber(NewRequest)
>> def new_request_subscriber(event):
>>     print 'In new request subscriber...'
>>     request = event.request
>>     print 'Request: %s' % request
>>     request.add_finished_callback(finished_callback)
>>
>> def finished_callback(request):
>>     print 'In finished_callback...'
>>
>> 3. Modified the test_my_view function in the tests.py file 
>>
>>     def test_my_view(self):
>>         from .views import my_view
>>         from pyramid.events import NewRequest
>>         from test_pyramid import new_request_subscriber
>>         request = testing.DummyRequest()
>>         
>>         self.config.testing_add_subscriber(NewRequest)
>>         event = NewRequest(request)
>>         self.config.registry.notify(new_request_subscriber(event))
>>
>>         info = my_view(request)
>>         self.assertEqual(info['project'], 'test_pyramid')
>>
>> 4. Ran the tests (python setup.py test -q)
>>
>> In new request subscriber...
>> Request: <pyramid.testing.DummyRequest object at 0x8f60a2c>
>> .
>> ----------------------------------------------------------------------
>> Ran 1 test in 0.008s
>>
>> OK
>>
>> Note that in the above the finished_callback was never triggered.
>>
>> This is a silly example, but the problem is that in my real application I 
>> need the test code to be able to close a handle to a database that I have 
>> opened using the new_request_subscriber.
>>
>> Any ideas how I can get the finished_callback to be triggered?
>>
>>
>>
>>
>>  -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to