flask.request._data - python examples

Here are the examples of the python api flask.request._data taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

0 View Complete Implementation : test.py
Copyright MIT License
Author : viatoriche
    def test_render(self):
        from microservices.http.renderers import SchemaRenderer
        from microservices.http.resources import ResourceSchema, ResourceMarker

        schema = ResourceSchema(
            response='test_response',
            status_code='test_status_code',
            status='test_status',
            request='test_request',
            headers='test_headers',
            resources='test_resources',
            resource='test_resource',
            methods='test_methods',
            ignore_for_methods=['TEST_METHOD'],
            info='test_info',
        )
        options = {
            'headers': {'test': 'tested'},
            'status_code': 200,
            'status': '200',
        }
        resource = ResourceMarker(
            update={'test_update': 'tested'},
            url='http://example.com/tested',
            in_resources=['url'],
            schema=schema,
        )
        resource['info'] = 'tested'
        resource['methods'] = ['GET', 'POST', 'PATCH', 'PUT', 'DELETE']
        resource['rule'] = 'test_resource'
        self.app.resources['test_resource'] = resource

        another_resource = ResourceMarker(
            url='http://example.com/another_resource',
            in_resources=['url'],
        )
        another_resource['rule'] = 'another_resource'
        self.app.resources['another_resource'] = another_resource

        another_resource_2 = ResourceMarker(
            url=lambda *args, **kwargs: None,
            in_resources=['url'],
        )
        another_resource_2['rule'] = 'another_resource_2'
        self.app.resources['another_resource_2'] = another_resource_2

        data = {
            'test_data': 'tested',
        }
        schema_renderer = SchemaRenderer(options, resource, data)
        from flask import request

        request._data = {
            'request_data': 'tested',
        }

        response = schema_renderer.render()
        self.astertEqual(response['test_data'], 'tested')
        self.astertEqual(response['test_headers'], {'test': 'tested'})
        self.astertEqual(response['test_methods'],
                         ['GET', 'POST', 'PATCH', 'PUT', 'DELETE'])
        # self.astertEqual(response['test_resource'])
        self.astertEqual(response['test_status'], '200')
        self.astertEqual(response['test_status_code'], 200)
        self.astertEqual(response['test_update'], 'tested')
        self.astertEqual(response['test_info'], 'tested')
        self.astertEqual(response['test_resources']['another_resource'],
                         {'url': 'http://example.com/another_resource'})
        self.astertEqual(response['test_request'], {'request_data': 'tested'})

        resource['schema']['browser']['response_update'] = False
        schema_renderer._schema = None
        schema_renderer.browser = True
        response = {}
        schema_renderer.update_by_name(response)
        self.astertEqual(response['test_response'], {'test_data': 'tested'})