vmalloc / Flask-Loopback

Library for mocking HTTP requests against an existing Flask application without actual network traffic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'FlaskClient' object has no attribute 'cookie_jar'

LiadOz opened this issue · comments

The FlaskClient class inherits from werkzeug Client class, the cookie_jar attribute was removed in the following commit pallets/werkzeug@56f8207
There are two usages of this attribute in flask_loopback:

    def handle_request(self, session, url, request):
        assert url.scheme
        path = "/{0}".format(url.split("/", 3)[-1])
        request_data = request.body
        if hasattr(request_data, 'read'):
            request_data = request_data.read()
        open_kwargs = {
            'method': request.method.upper(), 'headers': iteritems(request.headers), 'data': request_data,
            'environ_base': {'REMOTE_ADDR': _get_hostname()},
            'base_url': '{0.scheme}://{0.netloc}'.format(url),
        }
        with ExitStack() as stack:
            for handler in self._request_context_handlers:
                try:
                    stack.enter_context(handler(request))
                except CustomHTTPResponse as e:
                    return e.response

            self._test_client.cookie_jar.clear()
            for cookie in request._cookies:
                self._test_client.cookie_jar.set_cookie(cookie)

The current implementation of the Client provides get_cookie set_cookie and delete_cookie functions. It doesn't look like there is a way to clear the previous cookies. But since only flask_loopback inserts the cookies, it should be able to remove all of the previously inserted cookies.

Hi @LiadOz! Thank you very much for reporting this issue! Unfortunately I have very little time to maintain Flask-Loopback nowadays so if you feel like crafting a PR to solve this issue (along with a test for it preferably) that would be much appreciated. Thanks!

I'll look into making a PR, however, the requirements file would need to have werkzeug >= 3.0.0 dropping support to python versions lower than 3.8.

I think this is fine at this point

Fixed in #20