Skip to content

Commit

Permalink
feat: add domain checking unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lchen-2101 committed Sep 29, 2023
1 parent 297d3c4 commit 41ad531
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/app/conftest.py
Original file line number Diff line number Diff line change
@@ -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")
32 changes: 32 additions & 0 deletions tests/app/test_dependencies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from unittest.mock import Mock

Check failure on line 1 in tests/app/test_dependencies.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

tests/app/test_dependencies.py:1:27: F401 `unittest.mock.Mock` imported but unused
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)

0 comments on commit 41ad531

Please sign in to comment.