Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report non-processing state check #309

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 25 additions & 5 deletions src/sbl_filing_api/routers/filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from concurrent.futures import ProcessPoolExecutor
from fastapi import Depends, Request, UploadFile, status
from fastapi.responses import Response, JSONResponse, StreamingResponse
from fastapi.responses import Response, StreamingResponse
from multiprocessing import Manager
from regtech_api_commons.api.router_wrapper import Router
from regtech_api_commons.api.exceptions import RegTechHttpException
Expand Down Expand Up @@ -330,7 +330,12 @@ async def get_latest_submission_report(request: Request, lei: str, period_code:
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:
if latest_sub and latest_sub.state in [
SubmissionState.VALIDATION_SUCCESSFUL,
SubmissionState.VALIDATION_WITH_ERRORS,
SubmissionState.VALIDATION_WITH_WARNINGS,
SubmissionState.SUBMISSION_ACCEPTED,
]:
file_data = submission_processor.get_from_storage(
period_code, lei, str(latest_sub.id) + submission_processor.REPORT_QUALIFIER
)
Expand All @@ -342,7 +347,12 @@ async def get_latest_submission_report(request: Request, lei: str, period_code:
"Cache-Control": "no-store",
},
)
return JSONResponse(status_code=status.HTTP_204_NO_CONTENT, content=None)
else:
raise RegTechHttpException(
status_code=status.HTTP_404_NOT_FOUND,
name="Report Not Found",
detail=f"Report for ({filing.id}) does not exist.",
)


@router.get(
Expand All @@ -352,7 +362,12 @@ async def get_latest_submission_report(request: Request, lei: str, period_code:
@requires("authenticated")
async def get_submission_report(request: Request, response: Response, lei: str, period_code: str, id: int):
sub = await repo.get_submission(request.state.db_session, id)
if sub:
if sub and sub.state in [
SubmissionState.VALIDATION_SUCCESSFUL,
SubmissionState.VALIDATION_WITH_ERRORS,
SubmissionState.VALIDATION_WITH_WARNINGS,
SubmissionState.SUBMISSION_ACCEPTED,
]:
file_data = submission_processor.get_from_storage(
period_code, lei, str(sub.id) + submission_processor.REPORT_QUALIFIER
)
Expand All @@ -364,4 +379,9 @@ async def get_submission_report(request: Request, response: Response, lei: str,
"Cache-Control": "no-store",
},
)
response.status_code = status.HTTP_404_NOT_FOUND
else:
raise RegTechHttpException(
status_code=status.HTTP_404_NOT_FOUND,
name="Report Not Found",
detail=f"Report for ({id}) does not exist.",
)
48 changes: 45 additions & 3 deletions tests/api/routers/test_filing_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ async def test_get_latest_sub_report(
timestamp=datetime.datetime.now(),
),
filing=1,
state=SubmissionState.VALIDATION_IN_PROGRESS,
state=SubmissionState.VALIDATION_SUCCESSFUL,
validation_ruleset_version="v1",
submission_time=datetime.datetime.now(),
filename="file1.csv",
Expand All @@ -987,11 +987,32 @@ async def test_get_latest_sub_report(
assert res.headers["content-disposition"] == 'attachment; filename="1_validation_report.csv"'
assert res.headers["Cache-Control"] == "no-store"

sub_mock.return_value = SubmissionDAO(
id=1,
submitter=UserActionDAO(
id=1,
user_id="1234-5678-ABCD-EFGH",
user_name="Test Submitter User",
user_email="[email protected]",
action_type=UserActionType.SUBMIT,
timestamp=datetime.datetime.now(),
),
filing=1,
state=SubmissionState.VALIDATION_IN_PROGRESS,
validation_ruleset_version="v1",
submission_time=datetime.datetime.now(),
filename="file1.csv",
)

client = TestClient(app_fixture)
res = client.get("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/submissions/latest/report")
assert res.status_code == 404

sub_mock.return_value = []
client = TestClient(app_fixture)
res = client.get("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/submissions/latest/report")
sub_mock.assert_called_with(ANY, "1234567890ZXWVUTSR00", "2024")
assert res.status_code == 204
assert res.status_code == 404

# verify Filing Not Found RegTechHttpException returned when filing does not exist
get_filing_mock.return_value = None
Expand All @@ -1012,7 +1033,7 @@ async def test_get_sub_report(self, mocker: MockerFixture, app_fixture: FastAPI,
timestamp=datetime.datetime.now(),
),
filing=1,
state=SubmissionState.VALIDATION_IN_PROGRESS,
state=SubmissionState.VALIDATION_SUCCESSFUL,
validation_ruleset_version="v1",
submission_time=datetime.datetime.now(),
filename="file1.csv",
Expand All @@ -1032,6 +1053,27 @@ async def test_get_sub_report(self, mocker: MockerFixture, app_fixture: FastAPI,
assert res.headers["content-disposition"] == 'attachment; filename="2_validation_report.csv"'
assert res.headers["Cache-Control"] == "no-store"

sub_mock.return_value = SubmissionDAO(
id=2,
submitter=UserActionDAO(
id=1,
user_id="1234-5678-ABCD-EFGH",
user_name="Test Submitter User",
user_email="[email protected]",
action_type=UserActionType.SUBMIT,
timestamp=datetime.datetime.now(),
),
filing=1,
state=SubmissionState.VALIDATION_IN_PROGRESS,
validation_ruleset_version="v1",
submission_time=datetime.datetime.now(),
filename="file1.csv",
)

client = TestClient(app_fixture)
res = client.get("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/submissions/1/report")
assert res.status_code == 404

sub_mock.return_value = []
client = TestClient(app_fixture)
res = client.get("/v1/filing/institutions/1234567890ZXWVUTSR00/filings/2024/submissions/1/report")
Expand Down
Loading