Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test render_to_response in Pyramid Python

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 to_be_rendered.

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
like image 400
DLS Avatar asked May 15 '26 04:05

DLS


1 Answers

I believe render_to_response should return a response object. You should be able to call custom_adapter directly in your unit test, providing a DummyRequest and make assertions on the Response object returned by your custom_adapter

def test_custom_adapter(self):
   dummy = DummyRequest() # not sure of the object here
   response = custom_adapter(dummy)
   self.assertEqual(response.status, 200)
like image 181
dm03514 Avatar answered May 16 '26 18:05

dm03514



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!