From 241de51922eb9f7cdddaee5d16116f4a90594d4b Mon Sep 17 00:00:00 2001 From: lchen-2101 <73617864+lchen-2101@users.noreply.github.com> Date: Wed, 6 Mar 2024 14:37:35 -0500 Subject: [PATCH] feat: use put instead of patch --- src/routers/institutions.py | 15 ++++++- tests/api/routers/test_institutions_api.py | 50 ++++++++++++++++++++-- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/routers/institutions.py b/src/routers/institutions.py index b897b46..9ebc2e2 100644 --- a/src/routers/institutions.py +++ b/src/routers/institutions.py @@ -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( diff --git a/tests/api/routers/test_institutions_api.py b/tests/api/routers/test_institutions_api.py index 9b2ab21..149afa5 100644 --- a/tests/api/routers/test_institutions_api.py +++ b/tests/api/routers/test_institutions_api.py @@ -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"}]}, ) @@ -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"}]}, ) @@ -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"}]}, )