Skip to content

Commit

Permalink
Task 178 - fix bug for get_latest_submission when filing does not exi…
Browse files Browse the repository at this point in the history
…st (#205)

closes [#178 ](#178)
## Additions

-

## Removals

-

## Changes

-

## Testing

1.

## Screenshots


## Notes

-

## Todos

-

## Checklist

- [ ] PR has an informative and human-readable title
- [ ] Changes are limited to a single goal (no scope creep)
- [ ] Code can be automatically merged (no conflicts)
- [ ] Code follows the standards laid out in the [development
playbook](https://github.com/cfpb/development)
- [ ] Passes all existing automated tests
- [ ] Any _change_ in functionality is tested
- [ ] New functions are documented (with a description, list of inputs,
and expected output)
- [ ] Placeholder code is flagged / future todos are captured in
comments
- [ ] Visually tested in supported browsers and devices (see checklist
below 👇)
- [ ] Project documentation has been updated (including the "Unreleased"
section of the CHANGELOG)
- [ ] Reviewers requested with the [Reviewers
tool](https://help.github.com/articles/requesting-a-pull-request-review/)
:arrow_right:

## Testing checklist

### Browsers

- [ ] Chrome
- [ ] Firefox
- [ ] Safari
- [ ] Internet Explorer 8, 9, 10, and 11
- [ ] Edge
- [ ] iOS Safari
- [ ] Chrome for Android

### Accessibility

- [ ] Keyboard friendly
- [ ] Screen reader friendly

### Other

- [ ] Is useable without CSS
- [ ] Is useable without JS
- [ ] Flexible from small to large screens
- [ ] No linting errors or warnings
- [ ] JavaScript tests are passing

---------

Co-authored-by: Nargis Sultani <[email protected]>
Co-authored-by: jcadam14 <[email protected]>
  • Loading branch information
3 people authored May 9, 2024
1 parent 323635d commit 761d45e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/sbl_filing_api/routers/filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ async def get_submissions(request: Request, lei: str, period_code: str):
@router.get("/institutions/{lei}/filings/{period_code}/submissions/latest", response_model=SubmissionDTO)
@requires("authenticated")
async def get_submission_latest(request: Request, lei: str, period_code: str):
filing = await repo.get_filing(request.state.db_session, lei, period_code)
if not filing:
raise RegTechHttpException(
status_code=status.HTTP_404_NOT_FOUND,
name="Filing Not Found",
detail=f"There is no Filing for LEI {lei} in period {period_code}, unable to get latest submission for it.",
)
result = await repo.get_latest_submission(request.state.db_session, lei, period_code)
if result:
return result
Expand Down Expand Up @@ -317,6 +324,13 @@ async def put_contact_info(request: Request, lei: str, period_code: str, contact
)
@requires("authenticated")
async def get_latest_submission_report(request: Request, lei: str, period_code: str):
filing = await repo.get_filing(request.state.db_session, lei, period_code)
if not filing:
raise RegTechHttpException(
status_code=status.HTTP_404_NOT_FOUND,
name="Filing Not Found",
detail=f"There is no Filing for LEI {lei} in period {period_code}, unable to get latest submission for it.",
)
latest_sub = await repo.get_latest_submission(request.state.db_session, lei, period_code)
if latest_sub:
file_data = submission_processor.get_from_storage(
Expand Down
21 changes: 19 additions & 2 deletions tests/api/routers/test_filing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ def test_unauthed_get_latest_submissions(
res = client.get("/v1/filing/institutions/123456790/filings/2024/submissions/latest")
assert res.status_code == 403

async def test_get_latest_submission(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
async def test_get_latest_submission(
self, mocker: MockerFixture, app_fixture: FastAPI, get_filing_mock: Mock, authed_user_mock: Mock
):
user_action_submit = UserActionDAO(
id=2,
user_id="123456-7890-ABCDEF-GHIJ",
Expand All @@ -183,6 +185,7 @@ async def test_get_latest_submission(self, mocker: MockerFixture, app_fixture: F
action_type=UserActionType.SUBMIT,
timestamp=datetime.datetime.now(),
)

mock = mocker.patch("sbl_filing_api.entities.repos.submission_repo.get_latest_submission")
mock.return_value = SubmissionDAO(
filing=1,
Expand All @@ -208,6 +211,12 @@ async def test_get_latest_submission(self, mocker: MockerFixture, app_fixture: F
mock.assert_called_with(ANY, "1234567890ZXWVUTSR00", "2024")
assert res.status_code == 204

# verify Filing Not Found RegTechHttpException returned when filing does not exist
get_filing_mock.return_value = None
client = TestClient(app_fixture)
res = client.get("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/submissions/latest")
assert res.status_code == 404

def test_unauthed_get_submission_by_id(self, mocker: MockerFixture, app_fixture: FastAPI):
client = TestClient(app_fixture)
res = client.get("/v1/filing/institutions/123456790/filings/2024/submissions/1")
Expand Down Expand Up @@ -956,7 +965,9 @@ async def test_errors_sign_filing(
== "There is no Filing for LEI 1234567890ABCDEFGH00 in period 2024, unable to sign a non-existent Filing."
)

async def test_get_latest_sub_report(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
async def test_get_latest_sub_report(
self, mocker: MockerFixture, app_fixture: FastAPI, get_filing_mock: Mock, authed_user_mock: Mock
):
sub_mock = mocker.patch("sbl_filing_api.entities.repos.submission_repo.get_latest_submission")
sub_mock.return_value = SubmissionDAO(
id=1,
Expand Down Expand Up @@ -994,6 +1005,12 @@ async def test_get_latest_sub_report(self, mocker: MockerFixture, app_fixture: F
sub_mock.assert_called_with(ANY, "1234567890ZXWVUTSR00", "2024")
assert res.status_code == 204

# verify Filing Not Found RegTechHttpException returned when filing does not exist
get_filing_mock.return_value = None
client = TestClient(app_fixture)
res = client.get("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/submissions/latest/report")
assert res.status_code == 404

async def test_get_sub_report(self, mocker: MockerFixture, app_fixture: FastAPI, authed_user_mock: Mock):
sub_mock = mocker.patch("sbl_filing_api.entities.repos.submission_repo.get_submission")
sub_mock.return_value = SubmissionDAO(
Expand Down

0 comments on commit 761d45e

Please sign in to comment.