Generate an empty response object for testing

Is there a way to create an empty response object with all attributes, or do I need to create a class myself?

I just need something for a flash application that is cleaner than something like this:

    class fake_request():
        status_code = None
        text = None
    response = fake_request()
+4
source share
3 answers

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

from flask import Response

response = Response()

?

Jar Documentation - Response Object

+3
source

If you are referring to instantiation of an inline object, you can use this syntax

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

Refresh The user added a link to the flask after this answer, leaving for reference

+1
source

, ?

import flask
class FakeResponse(flask.Response):
    def __init__(self, response=None, status=None, headers=None, mimetype=None, content_type=None, direct_passthrough=False):
        self.headers = {}
        self.status_code = 200
        self.text = ""

FakeResponse Response ( ).

+1
source

Source: https://habr.com/ru/post/1623821/


All Articles