Skip to content

Commit

Permalink
feat: use put instead of patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lchen-2101 committed Mar 6, 2024
1 parent 8c30d9b commit 241de51
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/routers/institutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,20 @@ async def get_institution(
return res


@router.patch("/{lei}/types/{type}", response_model=VersionedData[List[SblTypeAssociationDetailsDto]] | None)
@router.get("/{lei}/types/{type}", response_model=VersionedData[List[SblTypeAssociationDetailsDto]] | None)
@requires("authenticated")
async def update_sbl_types(request: Request, lei: str, type: InstitutionType, types_patch: SblTypeAssociationPatchDto):
async def get_types(request: Request, lei: str, type: InstitutionType):
match type:
case "sbl":
fi = await repo.get_institution(request.state.db_session, lei)
return VersionedData(version=fi.version, data=fi.sbl_institution_types) if fi else None
case "hmda":
raise HTTPException(status_code=HTTPStatus.NOT_IMPLEMENTED, detail="HMDA type not yet supported")


@router.put("/{lei}/types/{type}", response_model=VersionedData[List[SblTypeAssociationDetailsDto]] | None)
@requires("authenticated")
async def update_types(request: Request, lei: str, type: InstitutionType, types_patch: SblTypeAssociationPatchDto):
match type:
case "sbl":
fi = await repo.update_sbl_types(
Expand Down
50 changes: 47 additions & 3 deletions tests/api/routers/test_institutions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,55 @@ def test_get_federal_regulators(self, mocker: MockerFixture, app_fixture: FastAP
res = client.get("/v1/institutions/regulators")
assert res.status_code == 200

def test_get_sbl_types(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
inst_version = 2
get_institution_mock = mocker.patch("entities.repos.institutions_repo.get_institution")
get_institution_mock.return_value = FinancialInstitutionDao(
version=inst_version,
name="Test Bank 123",
lei="TESTBANK123",
is_active=True,
domains=[FinancialInstitutionDomainDao(domain="test.bank", lei="TESTBANK123")],
tax_id="123456789",
rssd_id=1234,
primary_federal_regulator_id="FRI1",
primary_federal_regulator=FederalRegulatorDao(id="FRI1", name="FRI1"),
hmda_institution_type_id="HIT1",
hmda_institution_type=HMDAInstitutionTypeDao(id="HIT1", name="HIT1"),
sbl_institution_types=[SblTypeMappingDao(sbl_type=SBLInstitutionTypeDao(id="SIT1", name="SIT1"))],
hq_address_street_1="Test Address Street 1",
hq_address_street_2="",
hq_address_city="Test City 1",
hq_address_state_code="GA",
hq_address_state=AddressStateDao(code="GA", name="Georgia"),
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)
test_lei = "TESTBANK123"
res = client.get(f"/v1/institutions/{test_lei}/types/sbl")
assert res.status_code == HTTPStatus.OK
result = res.json()
assert len(result["data"]) == 1
assert result["version"] == inst_version
assert result["data"][0] == {"sbl_type": {"id": "SIT1", "name": "SIT1"}, "details": None}

def test_get_hmda_types(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
client = TestClient(app_fixture)
test_lei = "TESTBANK123"
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("entities.repos.institutions_repo.update_sbl_types")
client = TestClient(app_fixture)
test_lei = "TESTBANK123"
res = client.patch(
res = client.put(
f"/v1/institutions/{test_lei}/types/sbl",
json={"sbl_institution_types": ["1", {"id": "2"}, {"id": "13", "details": "test"}]},
)
Expand All @@ -447,7 +491,7 @@ def test_update_unsupported_institution_types(
mock = mocker.patch("entities.repos.institutions_repo.update_sbl_types")
client = TestClient(app_fixture)
test_lei = "TESTBANK123"
res = client.patch(
res = client.put(
f"/v1/institutions/{test_lei}/types/hmda",
json={"sbl_institution_types": ["1", {"id": "2"}, {"id": "13", "details": "test"}]},
)
Expand All @@ -458,7 +502,7 @@ def test_update_wrong_institution_types(self, mocker: MockerFixture, app_fixture
mock = mocker.patch("entities.repos.institutions_repo.update_sbl_types")
client = TestClient(app_fixture)
test_lei = "TESTBANK123"
res = client.patch(
res = client.put(
f"/v1/institutions/{test_lei}/types/test",
json={"sbl_institution_types": ["1", {"id": "2"}, {"id": "13", "details": "test"}]},
)
Expand Down

0 comments on commit 241de51

Please sign in to comment.