Comments (2)
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.
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)
- 0.7.4 pypi sdist includes what looks like py.typed from a local venv
- Assert called #133 incomplete
- Function `normalize_url` doubly encodes query string in some cases.
- `repeat` option in get(), post(), etc. also accept int
- `aioresponses` reorders query params
- `aioresponses` drops empty query params
- assert_any_call expects the method in the self.requests object to be uppercase HOT 1
- Missing setuptools as dependency
- Add assert_any_call_with
- aioresponses ignores custom response_class provided to aiohttp.ClientSession constructor HOT 3
- release aioresponses.assert_* feature? HOT 1
- Can we get a 0.7.5 release? HOT 1
- aiohttp.TraceConfig signals not being fired
- [BUG aiohttp 3.9] await self._writer TypeError: object Mock can't be used in 'await' expression HOT 7
- RFE: is it possible to restart making github releases?🤔
- Cannot use module on a vanilla Python 3.9 Docker container or venv due to No module named 'packaging' error HOT 1
- Enhancement request: allow removal of repeat=True HOT 2
- Proposal: implement aioresponses.assert_has_calls HOT 2
- release is version 0.7.4 however latest tag is 0.7.6 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aioresponses.