-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1386 from ChildMindInstitute/feature/M2-6637-test…
…s-for-loris tests: BE tests for LORIS (M2-6637)
- Loading branch information
Showing
16 changed files
with
540 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import uuid | ||
from unittest.mock import AsyncMock, patch | ||
|
||
from fastapi import BackgroundTasks | ||
|
||
from apps.integrations.loris.api.applets import start_transmit_process | ||
from apps.shared.test.client import TestClient | ||
from apps.users.domain import User | ||
|
||
|
||
async def test_start_transmit_process(client: TestClient, user: User, uuid_zero: uuid.UUID, session): | ||
with patch("apps.authentication.deps.get_current_user", return_value=user): | ||
with patch("infrastructure.database.deps.get_session", return_value=session): | ||
with patch("apps.integrations.loris.api.applets.integration", new_callable=AsyncMock) as mock_integration: | ||
background_tasks = BackgroundTasks() | ||
|
||
response = await start_transmit_process( | ||
applet_id=uuid_zero, background_tasks=background_tasks, user=user, session=session | ||
) | ||
|
||
for task in background_tasks.tasks: | ||
await task() | ||
|
||
assert response.status_code == 202 | ||
mock_integration.assert_called_once_with(uuid_zero, session, user) |
127 changes: 127 additions & 0 deletions
127
src/apps/integrations/loris/tests/test_crud_relationship.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import uuid | ||
from unittest.mock import AsyncMock, MagicMock | ||
|
||
import pytest | ||
from sqlalchemy.exc import IntegrityError | ||
|
||
from apps.integrations.loris.crud.user_relationship import MlLorisUserRelationshipCRUD | ||
from apps.integrations.loris.db.schemas import MlLorisUserRelationshipSchema | ||
from apps.integrations.loris.domain import MlLorisUserRelationship | ||
from apps.integrations.loris.errors import MlLorisUserRelationshipError, MlLorisUserRelationshipNotFoundError | ||
|
||
|
||
@pytest.fixture | ||
def relationship_data(uuid_zero: uuid.UUID): | ||
return {"ml_user_uuid": uuid_zero, "loris_user_id": "loris_user_123"} | ||
|
||
|
||
@pytest.fixture | ||
def relationship_schema(relationship_data): | ||
return MlLorisUserRelationshipSchema(**relationship_data) | ||
|
||
|
||
@pytest.fixture | ||
def relationship_instance(relationship_data): | ||
return MlLorisUserRelationship(**relationship_data) | ||
|
||
|
||
@pytest.fixture | ||
async def crud(session): | ||
return MlLorisUserRelationshipCRUD(session) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_save(crud, relationship_schema, relationship_instance, mocker): | ||
mock_create = mocker.patch.object(crud, "_create", return_value=AsyncMock()) | ||
mock_create.return_value = relationship_schema | ||
|
||
result = await crud.save(relationship_schema) | ||
|
||
assert result == relationship_instance | ||
mock_create.assert_called_once_with(relationship_schema) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_save_integrity_error(crud, relationship_schema, mocker): | ||
mock_create = mocker.patch.object(crud, "_create", side_effect=IntegrityError("mock", "mock", "mock")) | ||
|
||
with pytest.raises(MlLorisUserRelationshipError): | ||
await crud.save(relationship_schema) | ||
|
||
mock_create.assert_called_once_with(relationship_schema) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_by_ml_user_id(crud, relationship_schema, relationship_instance, mocker): | ||
ml_user_uuid = relationship_schema.ml_user_uuid | ||
|
||
mock_execute = mocker.patch.object(crud, "_execute", return_value=MagicMock()) | ||
mock_scalars = mock_execute.return_value.scalars.return_value | ||
mock_scalars.one_or_none = MagicMock(return_value=relationship_schema) | ||
|
||
result = await crud.get_by_ml_user_id(ml_user_uuid) | ||
|
||
assert result == relationship_instance | ||
mock_execute.assert_called_once() | ||
mock_scalars.one_or_none.assert_called_once() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_by_ml_user_id_not_found(crud, relationship_schema, mocker): | ||
ml_user_uuid = relationship_schema.ml_user_uuid | ||
|
||
mock_execute = mocker.patch.object(crud, "_execute", return_value=MagicMock()) | ||
mock_scalars = mock_execute.return_value.scalars.return_value | ||
mock_scalars.one_or_none = MagicMock(return_value=None) | ||
|
||
with pytest.raises(MlLorisUserRelationshipNotFoundError): | ||
await crud.get_by_ml_user_id(ml_user_uuid) | ||
|
||
mock_execute.assert_called_once() | ||
mock_scalars.one_or_none.assert_called_once() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_by_loris_user_id(crud, relationship_schema, relationship_instance, mocker): | ||
loris_user_id = relationship_schema.loris_user_id | ||
|
||
mock_execute = mocker.patch.object(crud, "_execute", return_value=MagicMock()) | ||
mock_scalars = mock_execute.return_value.scalars.return_value | ||
mock_scalars.one_or_none = MagicMock(return_value=relationship_schema) | ||
|
||
result = await crud.get_by_loris_user_id(loris_user_id) | ||
|
||
assert result == relationship_instance | ||
mock_execute.assert_called_once() | ||
mock_scalars.one_or_none.assert_called_once() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_by_loris_user_id_not_found(crud, relationship_schema, mocker): | ||
loris_user_id = relationship_schema.loris_user_id | ||
|
||
mock_execute = mocker.patch.object(crud, "_execute", return_value=MagicMock()) | ||
mock_scalars = mock_execute.return_value.scalars.return_value | ||
mock_scalars.one_or_none = MagicMock(return_value=None) | ||
|
||
with pytest.raises(MlLorisUserRelationshipNotFoundError): | ||
await crud.get_by_loris_user_id(loris_user_id) | ||
|
||
mock_execute.assert_called_once() | ||
mock_scalars.one_or_none.assert_called_once() | ||
|
||
|
||
# @pytest.mark.asyncio | ||
# async def test_update(crud, relationship_schema, relationship_instance, mocker): | ||
# ml_user_uuid = relationship_schema.ml_user_uuid | ||
|
||
# mock_update_one = mocker.patch.object(crud, '_update_one', return_value=relationship_schema) | ||
|
||
# result = await crud.update(ml_user_uuid, relationship_instance) | ||
|
||
# assert result == relationship_instance | ||
# mock_update_one.assert_called_once_with( | ||
# lookup="ml_user_uuid", | ||
# value=ml_user_uuid, | ||
# schema=relationship_schema | ||
# ) |
Oops, something went wrong.