Skip to content

Commit

Permalink
Use httpx_mock
Browse files Browse the repository at this point in the history
  • Loading branch information
Csaba Zsolnai authored and Csaba Zsolnai committed Dec 2, 2024
1 parent 3c9f73b commit 8c66c33
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion swarm_copy/tools/bluenaas_memodel_getall.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class InputMEModelGetAll(BaseModel):
page_size: int = Field(
default=20, description="Number of results returned by the API."
)
simulation_type: Literal["single-neuron-simulation", "synaptome-simulation"] = (
memodel_type: Literal["single-neuron-simulation", "synaptome-simulation"] = (
Field(
default="single-neuron-simulation",
description="Type of simulation to retrieve.",
Expand Down
4 changes: 2 additions & 2 deletions swarm_copy/tools/bluenaas_memodel_getone.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MEModelGetOneMetadata(BaseMetadata):
class InputMEModelGetOne(BaseModel):
"""Inputs for the BlueNaaS single-neuron simulation."""

simulation_id: str = Field(
memodel_id: str = Field(
description="ID of the model to retrieve. Should be an https link."
)

Expand All @@ -45,7 +45,7 @@ async def arun(self) -> MEModelResponse:
)

response = await self.metadata.httpx_client.get(
url=f"{self.metadata.bluenaas_url}/neuron-model/{self.metadata.vlab_id}/{self.metadata.project_id}/{quote_plus(self.input_schema.simulation_id)}",
url=f"{self.metadata.bluenaas_url}/neuron-model/{self.metadata.vlab_id}/{self.metadata.project_id}/{quote_plus(self.input_schema.memodel_id)}",
headers={"Authorization": f"Bearer {self.metadata.token}"},
)

Expand Down
2 changes: 0 additions & 2 deletions swarm_copy_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
import pytest
import pytest_asyncio
from fastapi.testclient import TestClient
from httpx import AsyncClient
from sqlalchemy import MetaData
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine

from swarm_copy.app.config import Settings
from swarm_copy.app.dependencies import get_kg_token, get_settings
from swarm_copy.app.main import app
from swarm_copy.tools import GetMorphoTool


@pytest.fixture(name="app_client")
Expand Down
18 changes: 9 additions & 9 deletions swarm_copy_tests/tools/test_literature_search_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@

class TestLiteratureSearchTool:
@pytest.mark.asyncio
async def test_arun(self):
url = "http://fake_url"
async def test_arun(self, httpx_mock):
url = "http://fake_url?query=covid+19&retriever_k=100&use_reranker=true&reranker_k=5"
reranker_k = 5

client = httpx.AsyncClient()
client.get = AsyncMock()
response = Mock()
response.status_code = 200
client.get.return_value = response
response.json.return_value = [
fake_response = [
{
"article_title": "Article title",
"article_authors": ["Author1", "Author2"],
Expand All @@ -32,11 +27,16 @@ async def test_arun(self):
for _ in range(reranker_k)
]

httpx_mock.add_response(
url=url,
json=fake_response,
)

tool = LiteratureSearchTool(
input_schema=LiteratureSearchInput(query="covid 19"),
metadata=LiteratureSearchMetadata(
literature_search_url=url,
httpx_client=client,
httpx_client=httpx.AsyncClient(),
token="fake_token",
retriever_k=100,
use_reranker=True,
Expand Down

0 comments on commit 8c66c33

Please sign in to comment.