pnuckowski/aioresponses

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

Opened this issue · 1 comments

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 commented

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 :)