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

fix(compat): support httpx 0.28 #340

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
317 changes: 177 additions & 140 deletions poetry.lock

Large diffs are not rendered by default.

19 changes: 8 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ readme = "README.md"
python = "^3.9"
pydantic = "^2.9.2"
fastapi = "^0.115.0"
uvicorn = '^0.22'
pandas = '^2.0'
aiofile = '^3.8'
uvicorn = "^0.22"
pandas = "^2.0"
aiofile = "^3.8"
numpy = "^1.24"
scipy = "^1.9"
rapidfuzz = "^3.0"
Expand All @@ -21,17 +21,15 @@ importlib-metadata = "^6.6.0"
pyyaml = "^6.0"
toml = "^0.10.2"


[tool.poetry.group.dev]
optional = true

[tool.poetry.group.dev.dependencies]
pytest = '*'
pytest-asyncio = '*'
atomicwrites = "*"
httpx = '*'
requests = '*'

pytest = "^8.3.4"
pytest-asyncio = "^0.24.0"
atomicwrites = "^1.4.1"
httpx = "^0.28.1"
requests = "^2.32.3"

[tool.poetry.group.docs]
optional = true
Expand All @@ -42,7 +40,6 @@ mkdocs-material = "^9.4.4"
mkdocs-render-swagger-plugin = "^0.1.0"
mkdocs-macros-plugin = "^1.0.4"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
11 changes: 7 additions & 4 deletions tests/api/test_cloud.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport

from boaviztapi.main import app

Expand Down Expand Up @@ -31,7 +31,8 @@ async def check_result(self):
url = self.request.to_url()
body = self.request.to_dict()

async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
if self.request.use_url_params:
res = await ac.get(url)
else:
Expand Down Expand Up @@ -134,7 +135,8 @@ async def test_empty_usage_with_url_params_r5ad():

@pytest.mark.asyncio
async def test_wrong_input():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post(
"/v1/cloud/instance?verbose=false",
json={"provider": "test", "instance_type": "a1.4xlarge", "usage": {}},
Expand All @@ -144,7 +146,8 @@ async def test_wrong_input():

@pytest.mark.asyncio
async def test_wrong_input_1():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post(
"/v1/cloud/instance?verbose=false",
json={"provider": "aws", "instance_type": "test", "usage": {}},
Expand Down
44 changes: 29 additions & 15 deletions tests/api/test_component.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport

from boaviztapi.main import app

Expand All @@ -8,7 +8,8 @@

@pytest.mark.asyncio
async def test_complete_cpu():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=false', json={"core_units": 12, "die_size_per_core": 24.5})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -39,7 +40,8 @@ async def test_complete_cpu():

@pytest.mark.asyncio
async def test_complete_cpu_verbose():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=true', json={"core_units": 12, "die_size_per_core": 24.5})

assert res.json() == {'impacts': {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -172,7 +174,8 @@ async def test_complete_cpu_verbose():

@pytest.mark.asyncio
async def test_complete_cpu_with_low_precision():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=false', json={"core_units": 12, "die_size_per_core": 20})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -203,7 +206,8 @@ async def test_complete_cpu_with_low_precision():

@pytest.mark.asyncio
async def test_empty_cpu():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=false', json={})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -234,7 +238,8 @@ async def test_empty_cpu():

@pytest.mark.asyncio
async def test_multiple_cpu():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=false', json={
"units": 3, "core_units": 12, "die_size_per_core": 24.5})

Expand Down Expand Up @@ -268,7 +273,8 @@ async def test_multiple_cpu():

@pytest.mark.asyncio
async def test_incomplete_cpu_verbose():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=true', json={
"core_units": 24, "family": "Skylake"})

Expand Down Expand Up @@ -400,7 +406,8 @@ async def test_incomplete_cpu_verbose():

@pytest.mark.asyncio
async def test_incomplete_cpu_verbose_2():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/cpu?verbose=true', json={
"core_units": 24, "family": "skylak"})

Expand Down Expand Up @@ -533,7 +540,8 @@ async def test_incomplete_cpu_verbose_2():

@pytest.mark.asyncio
async def test_complete_ram():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ram?verbose=false', json={"units": 12, "capacity": 32, "density": 1.79})

assert res.json() == {'impacts': {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -572,7 +580,8 @@ async def test_complete_ram():

@pytest.mark.asyncio
async def test_empty_ram():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ram?verbose=false', json={})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -609,7 +618,8 @@ async def test_empty_ram():

@pytest.mark.asyncio
async def test_wrong_manuf_ram():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ram?verbose=false', json={"manufacturer": "oieoiudhehz"})

assert res.json() == {'impacts': {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -648,7 +658,8 @@ async def test_wrong_manuf_ram():

@pytest.mark.asyncio
async def test_wrong_manuf_ssd():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ssd?verbose=false', json={"manufacturer": "oieoiudhehz"})

assert res.json() == {'impacts': {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -694,7 +705,8 @@ async def test_wrong_manuf_ssd():

@pytest.mark.asyncio
async def test_complete_ssd():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ssd?verbose=false', json={"capacity": 400, "density": 50.6})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -725,7 +737,8 @@ async def test_complete_ssd():

@pytest.mark.asyncio
async def test_empty_ssd():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/ssd?verbose=false', json={})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -765,7 +778,8 @@ async def test_empty_ssd():

@pytest.mark.asyncio
async def test_empty_blade():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/component/case?verbose=false', json={"case_type": "blade"})

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down
7 changes: 4 additions & 3 deletions tests/api/test_cp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport

from boaviztapi.main import app

Expand All @@ -8,7 +8,8 @@

@pytest.mark.asyncio
async def test_complete_cpu():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/consumption_profile/cpu', json={"cpu": {"name": "intel xeon gold 6134", "tdp": 130}})

assert res.json() == {'a': 35.5688, 'b': 0.2438, 'c': 9.6694, 'd': -0.6087}
assert res.json() == {'a': 35.5688, 'b': 0.2438, 'c': 9.6694, 'd': -0.6087}
17 changes: 11 additions & 6 deletions tests/api/test_iot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport

from boaviztapi.main import app

Expand All @@ -8,7 +8,8 @@

@pytest.mark.asyncio
async def test_empty_iot_device():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.get('/v1/iot/iot_device?verbose=false')

assert res.json() == {"impacts": {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -62,7 +63,8 @@ async def test_empty_iot_device():

@pytest.mark.asyncio
async def test_drone_mini():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.get('/v1/iot/iot_device?verbose=false&archetype=drone_mini&criteria=gwp')

assert res.json() == {"impacts": {'gwp': {'description': 'Total climate change',
Expand All @@ -82,7 +84,8 @@ async def test_drone_mini():

@pytest.mark.asyncio
async def test_drone_mini_verbose():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.get('/v1/iot/iot_device?verbose=true&archetype=drone_mini')

assert res.json() == {'impacts': {'adp': {'description': 'Use of minerals and fossil ressources',
Expand Down Expand Up @@ -425,7 +428,8 @@ async def test_drone_mini_verbose():

@pytest.mark.asyncio
async def test_drone_mini_costume_usage():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/iot/iot_device?verbose=false&archetype=drone_mini&duration=1', json={
"usage": {
"avg_power": 100,
Expand Down Expand Up @@ -465,7 +469,8 @@ async def test_drone_mini_costume_usage():

@pytest.mark.asyncio
async def test_custom_iot():
async with AsyncClient(app=app, base_url="http://test") as ac:
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as ac:
res = await ac.post('/v1/iot/iot_device?verbose=false&criteria=lu', json={
"functional_blocks": [
{
Expand Down
Loading
Loading