Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aiohttp.test_utils.make_mocked_request should accept regular dict as headers [easy] #1068

Closed
rutsky opened this issue Aug 11, 2016 · 6 comments
Labels

Comments

@rutsky
Copy link
Member

rutsky commented Aug 11, 2016

Currently aiohttp.helpers.make_mocked_request doesn't support headers value type other than CIMultiDict. If you try to pass regular dict as headers and try to use such mocked request you will get error similar to:

test_aio.py:6: in handler
    assert request.headers.get('token') == 'x'
../../../stuff/aio-libs/aiohttp/aiohttp/helpers.py:442: in __get__
    val = self.wrapped(inst)
../../../stuff/aio-libs/aiohttp/aiohttp/web_reqrep.py:214: in headers
    return CIMultiDictProxy(self._message.headers)

TypeError: CIMultiDictProxy requires CIMultiDict instance, not <class 'dict'>

This can be easily fixed by adding here something like:

    if headers:
        hdrs = headers
        if not isinstance(hdrs, CIMultiDict)
           hdrs = CIMultiDict(hdrs)
        raw_hdrs = [
(k.encode('utf-8'), v.encode('utf-8')) for k, v in headers.items()]

plus add test for this case.

@jincreator
Copy link
Contributor

If nobody is working on it, I'll take it.

@jincreator
Copy link
Contributor

Seems someone else is already working on it...

@asvetlov
Copy link
Member

Fixed by #1073

@rutsky
Copy link
Member Author

rutsky commented Aug 15, 2016

@argaen, thanks!

@rutsky rutsky closed this as completed Aug 15, 2016
@argaen
Copy link
Member

argaen commented Aug 15, 2016

You're welcome :).

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants