-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add domain checking unit tests
- Loading branch information
1 parent
297d3c4
commit 41ad531
Showing
2 changed files
with
44 additions
and
0 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
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") |
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,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) |