Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generate a blank response object for testing

Is there a way to generate a blank response object with all the attributes, or do I have to create the class myself?

I just want something for a flask app that is cleaner than doing something like this:

    class fake_request():
        status_code = None
        text = None
    response = fake_request()
like image 628
Rob Avatar asked Mar 14 '23 15:03

Rob


2 Answers

I'm not sure I fully understand, but what's wrong with

from flask import Response

response = Response()

?

Flask documentation - Response object

like image 51
gorsky Avatar answered Apr 29 '23 01:04

gorsky


If you're referring to generating an instance of an object inline, you can use this syntax

response = type('obj', (object,), {'status_code' : None, 'text' : None})

Update User added flask reference after this answer, leaving for reference

like image 39
Juan Cortés Avatar answered Apr 29 '23 01:04

Juan Cortés