Skip to content

Commit

Permalink
Ticket 171: Update LEIs in tests (#172)
Browse files Browse the repository at this point in the history
Closes #171
  • Loading branch information
guffee23 authored Jun 3, 2024
1 parent fbea18b commit b3c377c
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 295 deletions.
486 changes: 244 additions & 242 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ def get_institutions_mock(mocker: MockerFixture, authed_user_mock: Mock) -> Mock
hq_address_state_code="GA",
hq_address_state=AddressStateDao(code="GA", name="Georgia"),
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_lei="012PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=12345,
top_holder_lei="TOPHOLDERLEI123",
top_holder_lei="01234TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=123456,
modified_by="test_user_id",
Expand Down
32 changes: 20 additions & 12 deletions tests/api/routers/test_admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_get_me_authed_with_institutions(self, mocker: MockerFixture, app_fixtur
"preferred_username": "test_user",
"email": "[email protected]",
"sub": "testuser123",
"institutions": ["/TEST1LEI", "/TEST2LEI/TEST2CHILDLEI"],
"institutions": ["/TEST1LEI100000000000", "/TEST2LEI200000000000/TEST2CHILDLEI1000000"],
}
auth_mock.return_value = (
AuthCredentials(["authenticated"]),
Expand All @@ -41,11 +41,13 @@ def test_get_me_authed_with_institutions(self, mocker: MockerFixture, app_fixtur
client = TestClient(app_fixture)
res = client.get("/v1/admin/me")
assert res.status_code == 200
assert res.json().get("institutions") == ["TEST1LEI", "TEST2CHILDLEI"]
assert res.json().get("institutions") == ["TEST1LEI100000000000", "TEST2CHILDLEI1000000"]

def test_update_me_unauthed(self, app_fixture: FastAPI, unauthed_user_mock: Mock):
client = TestClient(app_fixture)
res = client.put("/v1/admin/me", json={"first_name": "testFirst", "last_name": "testLast", "leis": ["testLei"]})
res = client.put(
"/v1/admin/me", json={"first_name": "testFirst", "last_name": "testLast", "leis": ["TEST1LEI100000000000"]}
)
assert res.status_code == 403

def test_update_me_no_permission(self, app_fixture: FastAPI, auth_mock: Mock):
Expand All @@ -60,7 +62,9 @@ def test_update_me_no_permission(self, app_fixture: FastAPI, auth_mock: Mock):
AuthenticatedUser.from_claim(claims),
)
client = TestClient(app_fixture)
res = client.put("/v1/admin/me", json={"first_name": "testFirst", "last_name": "testLast", "leis": ["testLei"]})
res = client.put(
"/v1/admin/me", json={"first_name": "testFirst", "last_name": "testLast", "leis": ["TEST1LEI100000000000"]}
)
assert res.status_code == 403

def test_update_me(self, mocker: MockerFixture, app_fixture: FastAPI, auth_mock: Mock):
Expand All @@ -72,7 +76,7 @@ def test_update_me(self, mocker: MockerFixture, app_fixture: FastAPI, auth_mock:
"preferred_username": "test_user",
"email": "[email protected]",
"sub": "testuser123",
"institutions": ["testlei1", "testlei2"],
"institutions": ["TEST1LEI100000000000", "TEST2LEI200000000000"],
}
auth_mock.return_value = (
AuthCredentials(["manage-account"]),
Expand All @@ -82,13 +86,17 @@ def test_update_me(self, mocker: MockerFixture, app_fixture: FastAPI, auth_mock:
associate_lei_mock.return_value = None
get_user_mock.return_value = auth_mock.return_value[1]
client = TestClient(app_fixture)
data = {"first_name": "testFirst", "last_name": "testLast", "leis": ["testLei1", "testLei2"]}
data = {
"first_name": "testFirst",
"last_name": "testLast",
"leis": ["TEST1LEI100000000000", "TEST2LEI200000000000"],
}
res = client.put("/v1/admin/me", json=data)
update_user_mock.assert_called_once_with("testuser123", {"firstName": "testFirst", "lastName": "testLast"})
associate_lei_mock.assert_called_once_with("testuser123", {"testLei1", "testLei2"})
associate_lei_mock.assert_called_once_with("testuser123", {"TEST1LEI100000000000", "TEST2LEI200000000000"})
assert res.status_code == 200
assert res.json().get("name") == "testFirst testLast"
assert res.json().get("institutions") == ["testlei1", "testlei2"]
assert res.json().get("institutions") == ["TEST1LEI100000000000", "TEST2LEI200000000000"]

def test_update_me_no_lei(self, mocker: MockerFixture, app_fixture: FastAPI, auth_mock: Mock):
update_user_mock = mocker.patch("regtech_api_commons.oauth2.oauth2_admin.OAuth2Admin.update_user")
Expand Down Expand Up @@ -122,7 +130,7 @@ def test_associate_institutions(self, mocker: MockerFixture, app_fixture: FastAP
"preferred_username": "test_user",
"email": "[email protected]",
"sub": "testuser123",
"institutions": ["testlei1", "testlei2"],
"institutions": ["TEST1LEI100000000000", "TEST2LEI200000000000"],
}
auth_mock.return_value = (
AuthCredentials(["manage-account"]),
Expand All @@ -131,8 +139,8 @@ def test_associate_institutions(self, mocker: MockerFixture, app_fixture: FastAP
associate_lei_mock.return_value = None
get_user_mock.return_value = auth_mock.return_value[1]
client = TestClient(app_fixture)
res = client.put("/v1/admin/me/institutions", json=["testlei1", "testlei2"])
associate_lei_mock.assert_called_once_with("testuser123", {"testlei1", "testlei2"})
res = client.put("/v1/admin/me/institutions", json=["TEST1LEI100000000000", "TEST2LEI200000000000"])
associate_lei_mock.assert_called_once_with("testuser123", {"TEST1LEI100000000000", "TEST2LEI200000000000"})
assert res.status_code == 200
assert res.json().get("name") == "test"
assert res.json().get("institutions") == ["testlei1", "testlei2"]
assert res.json().get("institutions") == ["TEST1LEI100000000000", "TEST2LEI200000000000"]
54 changes: 27 additions & 27 deletions tests/api/routers/test_institutions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_get_institutions_authed_not_admin(

def test_create_institution_unauthed(self, app_fixture: FastAPI, unauthed_user_mock: Mock):
client = TestClient(app_fixture)
res = client.post("/v1/institutions/", json={"name": "testName", "lei": "testLei"})
res = client.post("/v1/institutions/", json={"name": "testName", "lei": "TESTBANK123000000000"})
assert res.status_code == 403

def test_invalid_tax_id(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
Expand All @@ -78,10 +78,10 @@ def test_invalid_tax_id(self, mocker: MockerFixture, app_fixture: FastAPI, authe
"hq_address_city": "Test City 1",
"hq_address_state_code": "VA",
"hq_address_zip": "00000",
"parent_lei": "PARENTTESTBANK123",
"parent_lei": "012PARENTTESTBANK123",
"parent_legal_name": "PARENT TEST BANK 123",
"parent_rssd_id": 12345,
"top_holder_lei": "TOPHOLDERLEI123",
"top_holder_lei": "01234TOPHOLDERLEI123",
"top_holder_legal_name": "TOP HOLDER LEI 123",
"top_holder_rssd_id": 123456,
},
Expand Down Expand Up @@ -109,10 +109,10 @@ def test_invalid_lei(self, mocker: MockerFixture, app_fixture: FastAPI, authed_u
"hq_address_city": "Test City 1",
"hq_address_state_code": "VA",
"hq_address_zip": "00000",
"parent_lei": "PARENTTESTBANK123",
"parent_lei": "012PARENTTESTBANK123",
"parent_legal_name": "PARENT TEST BANK 123",
"parent_rssd_id": 12345,
"top_holder_lei": "TOPHOLDERLEI123",
"top_holder_lei": "01234TOPHOLDERLEI123",
"top_holder_legal_name": "TOP HOLDER LEI 123",
"top_holder_rssd_id": 123456,
},
Expand Down Expand Up @@ -144,10 +144,10 @@ def test_create_institution_authed(self, mocker: MockerFixture, app_fixture: Fas
hq_address_state_code="VA",
hq_address_state=AddressStateDao(code="VA", name="Virginia"),
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_lei="012PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=12345,
top_holder_lei="TOPHOLDERLEI123",
top_holder_lei="01234TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=123456,
)
Expand All @@ -172,10 +172,10 @@ def test_create_institution_authed(self, mocker: MockerFixture, app_fixture: Fas
"hq_address_city": "Test City 1",
"hq_address_state_code": "VA",
"hq_address_zip": "00000",
"parent_lei": "PARENTTESTBANK123",
"parent_lei": "012PARENTTESTBANK123",
"parent_legal_name": "PARENT TEST BANK 123",
"parent_rssd_id": 12345,
"top_holder_lei": "TOPHOLDERLEI123",
"top_holder_lei": "01234TOPHOLDERLEI123",
"top_holder_legal_name": "TOP HOLDER LEI 123",
"top_holder_rssd_id": 123456,
},
Expand Down Expand Up @@ -284,10 +284,10 @@ def test_create_institution_authed_no_permission(self, app_fixture: FastAPI, aut
"hq_address_city": "Test City 1",
"hq_address_state_code": "VA",
"hq_address_zip": "00000",
"parent_lei": "PARENTTESTBANK123",
"parent_lei": "012PARENTTESTBANK123",
"parent_legal_name": "PARENT TEST BANK 123",
"parent_rssd_id": 12345,
"top_holder_lei": "TOPHOLDERLEI123",
"top_holder_lei": "01234TOPHOLDERLEI123",
"top_holder_legal_name": "TOP HOLDER LEI 123",
"top_holder_rssd_id": 123456,
},
Expand Down Expand Up @@ -324,10 +324,10 @@ def test_get_institution_authed(self, mocker: MockerFixture, app_fixture: FastAP
hq_address_state_code="GA",
hq_address_state=AddressStateDao(code="GA", name="Georgia"),
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_lei="012PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=12345,
top_holder_lei="TOPHOLDERLEI123",
top_holder_lei="01234TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=123456,
)
Expand Down Expand Up @@ -357,7 +357,7 @@ def test_add_domains_unauthed(self, app_fixture: FastAPI, unauthed_user_mock: Mo

def test_add_domains_authed(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
add_domains_mock = mocker.patch("regtech_user_fi_management.entities.repos.institutions_repo.add_domains")
add_domains_mock.return_value = [FinancialInstitutionDomainDao(domain="test.bank", lei="TESTBANK123")]
add_domains_mock.return_value = [FinancialInstitutionDomainDao(domain="test.bank", lei="TESTBANK123000000000")]
client = TestClient(app_fixture)

lei_path = "testLeiPath"
Expand Down Expand Up @@ -427,10 +427,10 @@ def test_get_associated_institutions(
hq_address_state_code="GA",
hq_address_state=AddressStateDao(code="GA", name="Georgia"),
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_lei="012PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=12345,
top_holder_lei="TOPHOLDERLEI123",
top_holder_lei="01234TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=123456,
),
Expand All @@ -454,10 +454,10 @@ def test_get_associated_institutions(
hq_address_state_code="GA",
hq_address_state=AddressStateDao(code="GA", name="Georgia"),
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_lei="012PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=14523,
top_holder_lei="TOPHOLDERLEI123",
top_holder_lei="01234TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=341256,
),
Expand Down Expand Up @@ -559,15 +559,15 @@ def test_get_sbl_types(self, mocker: MockerFixture, app_fixture: FastAPI, authed
hq_address_state_code="GA",
hq_address_state=AddressStateDao(code="GA", name="Georgia"),
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_lei="012PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=12345,
top_holder_lei="TOPHOLDERLEI123",
top_holder_lei="01234TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=123456,
)
client = TestClient(app_fixture)
test_lei = "TESTBANK123"
test_lei = "TESTBANK123000000000"
res = client.get(f"/v1/institutions/{test_lei}/types/sbl")
assert res.status_code == HTTPStatus.OK
result = res.json()
Expand All @@ -581,20 +581,20 @@ def test_get_sbl_types_no_institution(self, mocker: MockerFixture, app_fixture:
)
get_institution_mock.return_value = None
client = TestClient(app_fixture)
test_lei = "TESTBANK123"
test_lei = "TESTBANK123000000000"
res = client.get(f"/v1/institutions/{test_lei}/types/sbl")
assert res.status_code == HTTPStatus.NO_CONTENT

def test_get_hmda_types(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
client = TestClient(app_fixture)
test_lei = "TESTBANK123"
test_lei = "TESTBANK123000000000"
res = client.get(f"/v1/institutions/{test_lei}/types/hmda")
assert res.status_code == HTTPStatus.NOT_IMPLEMENTED

def test_update_institution_types(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
mock = mocker.patch("regtech_user_fi_management.entities.repos.institutions_repo.update_sbl_types")
client = TestClient(app_fixture)
test_lei = "TESTBANK123"
test_lei = "TESTBANK123000000000"
res = client.put(
f"/v1/institutions/{test_lei}/types/sbl",
json={"sbl_institution_types": ["1", {"id": "2"}, {"id": "13", "details": "test"}]},
Expand All @@ -612,7 +612,7 @@ def test_update_non_existing_institution_types(
)
get_institution_mock.return_value = None
client = TestClient(app_fixture)
test_lei = "TESTBANK123"
test_lei = "TESTBANK123000000000"
res = client.put(
f"/v1/institutions/{test_lei}/types/sbl",
json={"sbl_institution_types": ["1", {"id": "2"}, {"id": "13", "details": "test"}]},
Expand All @@ -624,7 +624,7 @@ def test_update_unsupported_institution_types(
):
mock = mocker.patch("regtech_user_fi_management.entities.repos.institutions_repo.update_sbl_types")
client = TestClient(app_fixture)
test_lei = "TESTBANK123"
test_lei = "TESTBANK123000000000"
res = client.put(
f"/v1/institutions/{test_lei}/types/hmda",
json={"sbl_institution_types": ["1", {"id": "2"}, {"id": "13", "details": "test"}]},
Expand All @@ -635,7 +635,7 @@ def test_update_unsupported_institution_types(
def test_update_wrong_institution_types(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
mock = mocker.patch("regtech_user_fi_management.entities.repos.institutions_repo.update_sbl_types")
client = TestClient(app_fixture)
test_lei = "TESTBANK123"
test_lei = "TESTBANK123000000000"
res = client.put(
f"/v1/institutions/{test_lei}/types/test",
json={"sbl_institution_types": ["1", {"id": "2"}, {"id": "13", "details": "test"}]},
Expand Down
18 changes: 9 additions & 9 deletions tests/entities/repos/test_institutions_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ async def setup(
hq_address_city="Test City 1",
hq_address_state_code="GA",
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_lei="012PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=12345,
top_holder_lei="TOPHOLDERLEI123",
top_holder_lei="01234TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=123456,
modified_by="test_user_id",
Expand All @@ -92,10 +92,10 @@ async def setup(
hq_address_city="Test City 2",
hq_address_state_code="CA",
hq_address_zip="11111",
parent_lei="PARENTTESTBANK456",
parent_lei="012PARENTTESTBANK456",
parent_legal_name="PARENT TEST BANK 456",
parent_rssd_id=54321,
top_holder_lei="TOPHOLDERLEI456",
top_holder_lei="01234TOPHOLDERLEI456",
top_holder_legal_name="TOP HOLDER LEI 456",
top_holder_rssd_id=654321,
modified_by="test_user_id",
Expand All @@ -119,10 +119,10 @@ async def setup(
hq_address_city="Test City 3",
hq_address_state_code="FL",
hq_address_zip="11111",
parent_lei="PARENTTESTBANK456",
parent_lei="012PARENTTESTBANK456",
parent_legal_name="PARENT TEST SUB BANK 456",
parent_rssd_id=21435,
top_holder_lei="TOPHOLDERLEI456",
top_holder_lei="01234TOPHOLDERLEI456",
top_holder_legal_name="TOP HOLDER LEI SUB BANK 456",
top_holder_rssd_id=321654,
modified_by="test_user_id",
Expand Down Expand Up @@ -202,7 +202,7 @@ async def test_get_institutions_by_lei_list(self, query_session: AsyncSession):
assert len(res) == 2

async def test_get_institutions_by_lei_list_item_not_existing(self, query_session: AsyncSession):
res = await repo.get_institutions(query_session, leis=["NOTTESTBANK"])
res = await repo.get_institutions(query_session, leis=["0123NOTTESTBANK01234"])
assert len(res) == 0

async def test_add_institution(self, transaction_session: AsyncSession):
Expand All @@ -224,10 +224,10 @@ async def test_add_institution(self, transaction_session: AsyncSession):
hq_address_city="Test City 3",
hq_address_state_code="FL",
hq_address_zip="22222",
parent_lei="PARENTNEWBANK123",
parent_lei="0123PARENTNEWBANK123",
parent_legal_name="PARENT NEW BANK 123",
parent_rssd_id=76543,
top_holder_lei="TOPHOLDERNEWBANKLEI123",
top_holder_lei="TOPHOLDNEWBANKLEI123",
top_holder_legal_name="TOP HOLDER NEW BANK LEI 123",
top_holder_rssd_id=876543,
modified_by="test_user_id",
Expand Down
6 changes: 3 additions & 3 deletions tests/entities/test_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TestListeners:
connection: Connection = Mock(Connection)
target: FinancialInstitutionDao = FinancialInstitutionDao(
name="Test Bank 123",
lei="TESTBANK123",
lei="TESTBANK123000000000",
is_active=True,
tax_id="12-3456789",
rssd_id=1234,
Expand All @@ -37,10 +37,10 @@ class TestListeners:
hq_address_city="Test City 1",
hq_address_state_code="GA",
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_lei="012PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=12345,
top_holder_lei="TOPHOLDERLEI123",
top_holder_lei="01234TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=123456,
modified_by="test_user_id",
Expand Down

0 comments on commit b3c377c

Please sign in to comment.