add aiohttp encapsulation

This commit is contained in:
better629 2023-11-21 20:33:58 +08:00
parent b17846401e
commit c233699275
2 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,38 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Desc : unittest of ahttp_client
import pytest
from metagpt.utils.ahttp_client import apost, apost_stream
@pytest.mark.asyncio
async def test_apost():
result = await apost(
url="https://www.baidu.com/"
)
assert "百度一下" in result
result = await apost(
url="http://aider.meizu.com/app/weather/listWeather",
data={"cityIds": "101240101"},
as_json=True
)
assert result["code"] == "200"
@pytest.mark.asyncio
async def test_apost_stream():
result = apost_stream(
url="https://www.baidu.com/"
)
async for line in result:
assert len(line) >= 0
result = apost_stream(
url="http://aider.meizu.com/app/weather/listWeather",
data={"cityIds": "101240101"}
)
async for line in result:
assert len(line) >= 0