Giter Site home page Giter Site logo

Comments (2)

pcrespov avatar pcrespov commented on June 1, 2024

A small test that illustrates it (in case is useful)

import pytest
from aiohttp import ClientSession
from aioresponses import aioresponses


@pytest.fixture
def mock_aioresponse():
    with aioresponses() as m:
        m.get("http://example.com/foo", status=200)
        yield m


async def test_with_full_url(mock_aioresponse: aioresponses):
    async with ClientSession() as session:
        async with session.get("http://example.com/foo") as response:
            assert response.ok


async def test_with_relative_url(mock_aioresponse: aioresponses):
    async with ClientSession(base_url="http://example.com") as session:
        async with session.get("/foo") as response:
            assert response.ok
test_aioreponses.py::test_with_full_url PASSED                                                                                                                                                                                                                                                 
test_aioreponses.py::test_with_relative_url FAILED 

from aioresponses.

rsaleev avatar rsaleev commented on June 1, 2024

A dirty hack solves the problem.

       # construct URL with ClientSession._base_url
        if orig_self._base_url:
            url_origin = f"{orig_self._base_url}/{url}"
            url = f"{orig_self._base_url}/{url}"
        url = normalize_url(merge_params(url, kwargs.get('params')))
        url_str = str(url)
        for prefix in self._passthrough:
            if url_str.startswith(prefix):
                return (await self.patcher.temp_original(
                    orig_self, method, url_origin, *args, **kwargs
                ))
        # add ClientSession headers
        if orig_self.headers:
            kwargs['headers'] = orig_self.headers
        key = (method, url)
        self.requests.setdefault(key, [])
        request_call = self._build_request_call(method, *args, ,**kwargs)
        self.requests[key].append(request_call)

        response = await self.match(method, url, **kwargs)

from aioresponses.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.