Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Institutions LEI Bug #49

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/routers/institutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ async def create_institution(
async def get_associated_institutions(request: Request):
user: AuthenticatedUser = request.user
email_domain = get_email_domain(user.email)
if not user.institutions:
return []
associated_institutions = await repo.get_institutions(request.state.db_session, user.institutions)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also add the safe guard in the repo, so empty list of leis doesn't return everything

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The search by list of leis was added functionality to this endpoint. It would send all institutions back if nothing was specified (domain, pg #, count). For clarification, we want to remove this feature to be lei specific search?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, this stays as is, but the repo should have a safe guard as well; right now the repo treats both None and empty list as the same, which shouldn't be the case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

second thought, just have the logic in the repo is good enough, so the router doesn't need to have this check.

return [
FinanicialInstitutionAssociationDto(
Expand Down
21 changes: 21 additions & 0 deletions tests/api/routers/test_institutions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,24 @@ def test_get_associated_institutions(
inst2 = next(filter(lambda inst: inst["lei"] == "TESTBANK234", data))
assert inst1["approved"] is False
assert inst2["approved"] is True

def test_get_associated_institutions_with_no_institutions(
self, app_fixture: FastAPI, auth_mock: Mock, get_institutions_mock: Mock
):
get_institutions_mock.return_value = None
claims = {
"name": "test",
"preferred_username": "test_user",
"email": "[email protected]",
"sub": "testuser123",
"institutions": [],
}
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_not_called()
assert res.json() == []
Loading