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

assert_any_call expects the method in the self.requests object to be uppercase #238

Open
CrypticGuru opened this issue May 10, 2023 · 1 comment

Comments

@CrypticGuru
Copy link

CrypticGuru commented May 10, 2023

Encountered on Ubuntu 22.04.
aiohttp version 3.8.4
aioresponses version 0.7.4

I encountered this when running python tests with pytest.
Consider the following file test_method_case_bug.py (note that I am supplying a lowercase parameter "get" to the session.request):

import pytest
import aiohttp
from aioresponses import aioresponses

@pytest.fixture
def mock_aioresponse():
    with aioresponses() as m:
        yield m

async def make_request():
    async with aiohttp.ClientSession() as session:
        async with session.request('get', 'http://localhost') as response:
            return response.ok

@pytest.mark.asyncio
async def test_request(mock_aioresponse):
    mock_aioresponse.get('http://localhost')
    await make_request()
    mock_aioresponse.assert_any_call('http://localhost')

If run with the command pytest test_method_case_bug.py, you will see that the assertion mock_aioresponse.assert_any_call('http://localhost') fails because it is expecting the method to be uppercase GET not lowercase get.

I suggest assigning the self.requests keys with an upper() call.
i.e. change https://github.com/pnuckowski/aioresponses/blob/master/aioresponses/core.py#L516 to be key = (method.upper(), url)

@Gotos
Copy link

Gotos commented May 30, 2023

Running into the same problem. I've got a working workaround, but I hope this can be fixed soon as it would be way more elegant :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants