Skip to content

Commit

Permalink
fixup! ✨(api) introduce Moodle indexers
Browse files Browse the repository at this point in the history
  • Loading branch information
wilbrdt committed Jan 22, 2024
1 parent 97a5c5d commit edb24f4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 51 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
2 changes: 1 addition & 1 deletion src/api/core/warren/tests/xi/indexers/moodle/test_etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def test_course_content_factory(
)

# Attempt to build a 'CourseContent' indexer with a wrong iri
with pytest.raises(ValueError, match=f"Wrong course iri {wrong_iri}"):
with pytest.raises(ValueError, match=f"Wrong course IRI {wrong_iri}"):
await CourseContent.factory(
source=Moodle(),
target=ExperienceIndex(),
Expand Down
2 changes: 1 addition & 1 deletion src/api/core/warren/xi/indexers/moodle/etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def factory(
"""Instantiate the class after fetching the given course."""
course = await target.experience.get(course_iri)
if not course:
raise ValueError(f"Wrong course iri {course_iri}")
raise ValueError(f"Wrong course IRI {course_iri}")

return cls(lms=source, xi=target, course=course, **kwargs)

Expand Down

0 comments on commit edb24f4

Please sign in to comment.