diff --git a/tests/app/conftest.py b/tests/app/conftest.py new file mode 100644 index 0000000..18cc99d --- /dev/null +++ b/tests/app/conftest.py @@ -0,0 +1,12 @@ +import pytest + +from pytest_mock import MockerFixture + + +@pytest.fixture(autouse=True) +def setup(mocker: MockerFixture): + mocked_engine = mocker.patch("sqlalchemy.ext.asyncio.create_async_engine") + MockedEngine = mocker.patch("sqlalchemy.ext.asyncio.AsyncEngine") + mocked_engine.return_value = MockedEngine.return_value + mocker.patch("fastapi.security.OAuth2AuthorizationCodeBearer") + mocker.patch("entities.engine.get_session") diff --git a/tests/app/test_dependencies.py b/tests/app/test_dependencies.py new file mode 100644 index 0000000..49c3d39 --- /dev/null +++ b/tests/app/test_dependencies.py @@ -0,0 +1,32 @@ +from unittest.mock import Mock +from pytest_mock import MockerFixture +from sqlalchemy.ext.asyncio import AsyncSession + +import pytest + + +@pytest.fixture +def mock_session(mocker: MockerFixture) -> AsyncSession: + return mocker.patch("sqlalchemy.ext.asyncio.AsyncSession").return_value + + +async def test_domain_denied(mocker: MockerFixture, mock_session: AsyncSession): + domain_allowed_mock = mocker.patch("entities.repos.institutions_repo.is_domain_allowed") + domain_allowed_mock.return_value = False + from dependencies import email_domain_denied + + denied_domain = "denied.domain" + + assert await email_domain_denied(mock_session, denied_domain) is True + domain_allowed_mock.assert_called_once_with(mock_session, denied_domain) + + +async def test_domain_allowed(mocker: MockerFixture, mock_session: AsyncSession): + domain_allowed_mock = mocker.patch("entities.repos.institutions_repo.is_domain_allowed") + domain_allowed_mock.return_value = True + from dependencies import email_domain_denied + + denied_domain = "allowed.domain" + + assert await email_domain_denied(mock_session, denied_domain) is False + domain_allowed_mock.assert_called_once_with(mock_session, denied_domain)