How to test render_to_response in Pyramid Python
<p>I have a piece of code that calls Pyramid's render_to_response.  I am not quite sure how to test that piece.  In my test, the request object that is sent in is a DummyRequest by Pyramid. How can I capture <code>to_be_rendered</code>.</p>

<pre><code>from pyramid.renderers import render_to_response

def custom_adapter(response):
    data = {
        'message': response.message
    }

    to_be_rendered = render_to_response(response.renderer, data)

    to_be_rendered.status_int = response.status_code
    return to_be_rendered
</code></pre>

<p>I believe <code>render_to_response</code> should return a <a href="http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/webob.html#response" rel="nofollow">response</a> object.  You should be able to call <code>custom_adapter</code> directly in your unit test, providing a <code>DummyRequest</code> and make assertions on the <code>Response</code> object returned by your <code>custom_adapter</code></p>

<pre><code>def test_custom_adapter(self):
   dummy = DummyRequest() # not sure of the object here
   response = custom_adapter(dummy)
   self.assertEqual(response.status, 200)
</code></pre>

python unit-testing py.test