Skip to content

Commit

Permalink
Added modified test files
Browse files Browse the repository at this point in the history
  • Loading branch information
Nargis Sultani committed Nov 30, 2023
1 parent 540b3df commit 090ffdf
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/routers/institutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ async def get_associated_institutions(request: Request):
FinanicialInstitutionAssociationDto(
name=institution.name,
lei=institution.lei,
tax_id="123456789",
rssd_id=1234,
primary_federal_regulator_id="FRI1",
hmda_institution_type_id="HIT1",
sbl_institution_type_id="SIT1",
hq_address_street_1="Test Address Street 1",
hq_address_street_2="",
hq_address_city="Test City 1",
hq_address_state="TN",
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=12345,
top_holder_lei="TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=123456,
approved=email_domain in [inst_domain.domain for inst_domain in institution.domains],
)
for institution in associated_institutions
Expand Down
16 changes: 16 additions & 0 deletions tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ def get_institutions_mock(mocker: MockerFixture) -> Mock:
name="Test Bank 123",
lei="TESTBANK123",
domains=[FinancialInstitutionDomainDao(domain="test.bank", lei="TESTBANK123")],
tax_id="123456789",
rssd_id=1234,
primary_federal_regulator_id="FRI1",
hmda_institution_type_id="HIT1",
sbl_institution_type_id="SIT1",
hq_address_street_1="Test Address Street 1",
hq_address_street_2="",
hq_address_city="Test City 1",
hq_address_state="TN",
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=12345,
top_holder_lei="TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=123456,
)
]
return mock
49 changes: 47 additions & 2 deletions tests/api/routers/test_institutions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ def test_get_institutions_authed(
client = TestClient(app_fixture)
res = client.get("/v1/institutions/")
assert res.status_code == 200
print(res.status_code)
assert res.json()[0].get("name") == "Test Bank 123"

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": "testLei",
},
)
assert res.status_code == 403

def test_create_institution_authed(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
Expand All @@ -37,7 +44,29 @@ def test_create_institution_authed(self, mocker: MockerFixture, app_fixture: Fas
upsert_group_mock = mocker.patch("oauth2.oauth2_admin.OAuth2Admin.upsert_group")
upsert_group_mock.return_value = "leiGroup"
client = TestClient(app_fixture)
res = client.post("/v1/institutions/", json={"name": "testName", "lei": "testLei"})
res = client.post(
"/v1/institutions/",
json={
"name": "testName",
"lei": "testLei",
"tax_id": "123456789",
"ssd_id": 1234,
"primary_federal_regulator_id": "FRI1",
"hmda_institution_type_id": "HIT1",
"sbl_institution_type_id": "SIT1",
"hq_address_street_1": "Test Address Street 1",
"hq_address_street_2": "",
"hq_address_city": "Test City 1",
"hq_address_state": "TN",
"hq_address_zip": "00000",
"parent_lei": "PARENTTESTBANK123",
"parent_legal_name": "PARENT TEST BANK 123",
"parent_rssd_id": 12345,
"top_holder_lei": "TOPHOLDERLEI123",
"top_holder_legal_name": "TOP HOLDER LEI 123",
"top_holder_rssd_id": 123456,
},
)
assert res.status_code == 200
assert res.json()[1].get("name") == "testName"

Expand Down Expand Up @@ -68,6 +97,22 @@ def test_get_institution_authed(self, mocker: MockerFixture, app_fixture: FastAP
name="Test Bank 123",
lei="TESTBANK123",
domains=[FinancialInstitutionDomainDao(domain="test.bank", lei="TESTBANK123")],
tax_id="123456789",
rssd_id=1234,
primary_federal_regulator_id="FRI1",
hmda_institution_type_id="HIT1",
sbl_institution_type_id="SIT1",
hq_address_street_1="Test Address Street 1",
hq_address_street_2="",
hq_address_city="Test City 1",
hq_address_state="TN",
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=12345,
top_holder_lei="TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=123456,
)
client = TestClient(app_fixture)
lei_path = "testLeiPath"
Expand Down
57 changes: 56 additions & 1 deletion tests/entities/repos/test_institutions_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
)
from entities.models import DeniedDomainDao
from entities.repos import institutions_repo as repo
from entities.models import FederalRegulatorDao
from entities.models import HMDAInstitutionTypeDao
from entities.models import SBLInstitutionTypeDao
from entities.models import AddressStateDao


class TestInstitutionsRepo:
Expand All @@ -20,10 +24,42 @@ async def setup(
name="Test Bank 123",
lei="TESTBANK123",
domains=[FinancialInstitutionDomainDao(domain="test.bank.1", lei="TESTBANK123")],
tax_id="123456789",
rssd_id=1234,
primary_federal_regulator_id=FederalRegulatorDao(id="FRI1", name="Test Federal Regulator ID 1").id,
hmda_institution_type_id=HMDAInstitutionTypeDao(id="HIT1", name="Test HMDA Instituion ID 1").id,
sbl_institution_type_id=SBLInstitutionTypeDao(id="SIT1", name="Test SBL Instituion ID 1").id,
hq_address_street_1="Test Address Street 1",
hq_address_street_2="",
hq_address_city="Test City 1",
hq_address_state=AddressStateDao(code="TN", name="Tennessee").code,
hq_address_zip="00000",
parent_lei="PARENTTESTBANK123",
parent_legal_name="PARENT TEST BANK 123",
parent_rssd_id=12345,
top_holder_lei="TOPHOLDERLEI123",
top_holder_legal_name="TOP HOLDER LEI 123",
top_holder_rssd_id=123456,
), FinancialInstitutionDao(
name="Test Bank 456",
lei="TESTBANK456",
domains=[FinancialInstitutionDomainDao(domain="test.bank.2", lei="TESTBANK456")],
tax_id="987654321",
rssd_id=4321,
primary_federal_regulator_id=FederalRegulatorDao(id="FRI2", name="Test Federal Regulator ID 2").id,
hmda_institution_type_id=HMDAInstitutionTypeDao(id="HIT2", name="Test HMDA Instituion ID 2").id,
sbl_institution_type_id=SBLInstitutionTypeDao(id="SIT2", name="Test SBL Instituion ID 2").id,
hq_address_street_1="Test Address Street 2",
hq_address_street_2="",
hq_address_city="Test City 2",
hq_address_state=AddressStateDao(code="TX", name="Texas").code,
hq_address_zip="11111",
parent_lei="PARENTTESTBANK456",
parent_legal_name="PARENT TEST BANK 456",
parent_rssd_id=54321,
top_holder_lei="TOPHOLDERLEI456",
top_holder_legal_name="TOP HOLDER LEI 456",
top_holder_rssd_id=654321,
)
transaction_session.add(fi_dao_123)
transaction_session.add(fi_dao_456)
Expand Down Expand Up @@ -52,7 +88,26 @@ async def test_get_institutions_by_lei_list_item_not_existing(self, query_sessio
async def test_add_institution(self, transaction_session: AsyncSession):
await repo.upsert_institution(
transaction_session,
FinancialInstitutionDao(name="New Bank 123", lei="NEWBANK123"),
FinancialInstitutionDao(
name="New Bank 123",
lei="NEWBANK123",
tax_id="654321987",
rssd_id=6543,
primary_federal_regulator_id=FederalRegulatorDao(id="FRI3", name="Test Federal Regulator ID 3").id,
hmda_institution_type_id=HMDAInstitutionTypeDao(id="HIT3", name="Test HMDA Instituion ID 3").id,
sbl_institution_type_id=SBLInstitutionTypeDao(id="SIT3", name="Test SBL Instituion ID 3").id,
hq_address_street_1="Test Address Street 3",
hq_address_street_2="",
hq_address_city="Test City 3",
hq_address_state=AddressStateDao(code="CA", name="California").code,
hq_address_zip="22222",
parent_lei="PARENTNEWBANK123",
parent_legal_name="PARENT NEW BANK 123",
parent_rssd_id=76543,
top_holder_lei="TOPHOLDERNEWBANKLEI123",
top_holder_legal_name="TOP HOLDER NEW BANK LEI 123",
top_holder_rssd_id=876543,
),
)
res = await repo.get_institutions(transaction_session)
assert len(res) == 3
Expand Down

0 comments on commit 090ffdf

Please sign in to comment.