-
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 associated institutions endpoint, refactored domain parsing (…
- Loading branch information
1 parent
6891a4f
commit e19d50e
Showing
11 changed files
with
139 additions
and
27 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 |
---|---|---|
|
@@ -14,15 +14,9 @@ def test_get_institutions_unauthed(self, app_fixture: FastAPI, unauthed_user_moc | |
res = client.get("/v1/institutions/") | ||
assert res.status_code == 403 | ||
|
||
def test_get_institutions_authed(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock): | ||
get_institutions_mock = mocker.patch("entities.repos.institutions_repo.get_institutions") | ||
get_institutions_mock.return_value = [ | ||
FinancialInstitutionDao( | ||
name="Test Bank 123", | ||
lei="TESTBANK123", | ||
domains=[FinancialInstitutionDomainDao(domain="test.bank", lei="TESTBANK123")], | ||
) | ||
] | ||
def test_get_institutions_authed( | ||
self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock, get_institutions_mock: Mock | ||
): | ||
client = TestClient(app_fixture) | ||
res = client.get("/v1/institutions/") | ||
assert res.status_code == 200 | ||
|
@@ -135,10 +129,46 @@ def test_add_domains_authed_with_denied_email_domain( | |
assert "domain denied" in res.json()["detail"] | ||
|
||
def test_check_domain_allowed(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock): | ||
domain_allowed_mock = mocker.patch("entities.repos.institutions_repo.is_email_domain_allowed") | ||
domain_allowed_mock = mocker.patch("entities.repos.institutions_repo.is_domain_allowed") | ||
domain_allowed_mock.return_value = True | ||
domain_to_check = "local.host" | ||
client = TestClient(app_fixture) | ||
res = client.get(f"/v1/institutions/domains/allowed?domain={domain_to_check}") | ||
domain_allowed_mock.assert_called_once_with(ANY, domain_to_check) | ||
assert res.json() is True | ||
|
||
def test_get_associated_institutions( | ||
self, mocker: MockerFixture, app_fixture: FastAPI, auth_mock: Mock, get_institutions_mock: Mock | ||
): | ||
get_institutions_mock.return_value = [ | ||
FinancialInstitutionDao( | ||
name="Test Bank 123", | ||
lei="TESTBANK123", | ||
domains=[FinancialInstitutionDomainDao(domain="test123.bank", lei="TESTBANK123")], | ||
), | ||
FinancialInstitutionDao( | ||
name="Test Bank 234", | ||
lei="TESTBANK234", | ||
domains=[FinancialInstitutionDomainDao(domain="test234.bank", lei="TESTBANK234")], | ||
), | ||
] | ||
claims = { | ||
"name": "test", | ||
"preferred_username": "test_user", | ||
"email": "[email protected]", | ||
"sub": "testuser123", | ||
"institutions": ["/TESTBANK123", "/TESTBANK234"], | ||
} | ||
auth_mock.return_value = ( | ||
AuthCredentials(["authenticated"]), | ||
AuthenticatedUser.from_claim(claims), | ||
) | ||
client = TestClient(app_fixture) | ||
res = client.get("/v1/institutions/associated") | ||
assert res.status_code == 200 | ||
get_institutions_mock.assert_called_once_with(ANY, ["TESTBANK123", "TESTBANK234"]) | ||
data = res.json() | ||
inst1 = next(filter(lambda inst: inst["lei"] == "TESTBANK123", data)) | ||
inst2 = next(filter(lambda inst: inst["lei"] == "TESTBANK234", data)) | ||
assert inst1["approved"] is False | ||
assert inst2["approved"] is True |
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,31 @@ | ||
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 | ||
|
||
allowed_domain = "allowed.domain" | ||
|
||
assert await email_domain_denied(mock_session, allowed_domain) is False | ||
domain_allowed_mock.assert_called_once_with(mock_session, allowed_domain) |
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