Skip to content

Commit

Permalink
fixup! ✅(api) fix httpx_mock usage in xi tools
Browse files Browse the repository at this point in the history
  • Loading branch information
wilbrdt committed Jan 22, 2024
1 parent 0a5befc commit ed86a12
Showing 1 changed file with 1 addition and 49 deletions.
50 changes: 1 addition & 49 deletions src/api/core/warren/tests/xi/client/test_crud_experience.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from warren.xi.client import CRUDExperience
from warren.xi.factories import ExperienceFactory
from warren.xi.models import ExperienceCreate, ExperienceRead, ExperienceReadSnapshot
from warren.xi.models import ExperienceCreate, ExperienceRead


@pytest.mark.anyio
Expand Down Expand Up @@ -57,54 +57,6 @@ async def test_crud_experience_read_empty(http_client: AsyncClient, monkeypatch)
assert experiences == []


@pytest.mark.anyio
async def test_crud_experience_get_from_iri_non_existing_experience(
http_client: AsyncClient, db_session: Session, monkeypatch
):
"""Test 'get_from_iri' for a non-existing experience."""
monkeypatch.setattr(CRUDExperience, "_base_url", "/api/v1/experiences")
crud_instance = CRUDExperience(client=http_client)

# Simulate not found experience by mocking the 'read' method
crud_instance.read = AsyncMock(return_value=[])
crud_instance.get = AsyncMock()

# Get random experience data
data = ExperienceFactory.build_dict()

# Attempt getting a non-existing experience
res = await crud_instance.get_from_iri(data["iri"])

assert res is None

crud_instance.read.assert_awaited_once()
crud_instance.get.assert_not_awaited()


@pytest.mark.anyio
async def test_crud_experience_get_from_iri_existing_experience(
http_client: AsyncClient, db_session: Session, monkeypatch
):
"""Test 'get_from_iri' for an existing experience."""
monkeypatch.setattr(CRUDExperience, "_base_url", "/api/v1/experiences")
crud_instance = CRUDExperience(client=http_client)

# Get random experience data
data = ExperienceFactory.build_dict(exclude={})

# Simulate not found experience by mocking the 'read' method
crud_instance.read = AsyncMock(return_value=[ExperienceReadSnapshot(**data)])
crud_instance.get = AsyncMock(return_value=ExperienceRead(**data))

# Attempt getting a non-existing experience
res = await crud_instance.get_from_iri(data["iri"])

assert isinstance(res, ExperienceRead)

crud_instance.read.assert_awaited_once()
crud_instance.get.assert_awaited_once()


@pytest.mark.anyio
async def test_crud_experience_create_or_update_new(
http_client: AsyncClient, db_session: Session, monkeypatch
Expand Down

0 comments on commit ed86a12

Please sign in to comment.