generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
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
File parsing and validation #70
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c66000e
Added update_submission function and associated pytest
jcadam14 4480894
Pass file through validator
guffee23 f702751
Merge branch '5_file_parse_and_val_v2' into 5_21_update_submission_pa…
guffee23 fc42dd7
Update table to correct state as validation progresses
guffee23 ab41fdd
Black formatting
guffee23 5ce69bc
Merge branch 'main' into 5_file_parse_and_val_v2
guffee23 8fd168a
Merge branch 'main' into 5_file_parse_and_val_v2
guffee23 b9fd240
Split validation and state table update into own function
guffee23 02a1039
Merge branch 'main' into 5_file_parse_and_val_v2
guffee23 82a9d00
Set to new session instance for separate transactions
guffee23 a681c68
Added upload file api test
guffee23 5e52cae
Renamed test function
guffee23 14503b5
WIP - validate and update tests
guffee23 942d062
Merge branch 'main' into 5_file_parse_and_val_v2
guffee23 853ba29
Finished valdiation api tests
guffee23 d1585eb
Added validation version to in progress table write
guffee23 73e6ca8
Merge branch 'main' into 5_file_parse_and_val_v2
guffee23 db84ade
Moved tests under TestSubmissionProcessor class
guffee23 2988429
Fixed mock in test submission repo
guffee23 fbd43c5
Merge branch 'main' into 5_file_parse_and_val_v2
guffee23 ca9e3dd
Added unauthed test for file upload
guffee23 65cb7b0
Removed unnecessary lines
guffee23 0cc3563
Merge branch 'main' into 5_file_parse_and_val_v2
guffee23 40dc399
Merge branch 'main' into 5_file_parse_and_val_v2
guffee23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
from io import BytesIO | ||
from fastapi import BackgroundTasks | ||
from regtech_data_validator.create_schemas import validate_phases | ||
import pandas as pd | ||
import importlib.metadata as imeta | ||
from entities.models import SubmissionDAO, SubmissionState | ||
from entities.repos.submission_repo import update_submission | ||
from http import HTTPStatus | ||
from fastapi import HTTPException | ||
import logging | ||
|
@@ -19,6 +26,46 @@ async def upload_to_storage(lei: str, submission_id: str, content: bytes, extens | |
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail="Failed to upload file") | ||
|
||
|
||
async def validate_submission(lei: str, submission_id: str, content: bytes): | ||
# implement validation process here | ||
pass | ||
async def validate_submission(lei: str, submission_id: str, content: bytes, background_tasks: BackgroundTasks): | ||
df = pd.read_csv(BytesIO(content), dtype=str, na_filter=False) | ||
validator_version = imeta.version("regtech-data-validator") | ||
|
||
# Set VALIDATION_IN_PROGRESS | ||
await update_submission( | ||
SubmissionDAO( | ||
submitter=submission_id, | ||
state=SubmissionState.VALIDATION_IN_PROGRESS, | ||
validation_ruleset_version=validator_version, | ||
) | ||
) | ||
background_tasks.add_task(validate_and_update_submission, df, lei, submission_id, validator_version) | ||
|
||
|
||
async def validate_and_update_submission(df: pd.DataFrame, lei: str, submission_id: str, validator_version: str): | ||
# Validate Phases | ||
result = validate_phases(df, {"lei": lei}) | ||
|
||
# Update tables with response | ||
if not result[0]: | ||
sub_state = ( | ||
SubmissionState.VALIDATION_WITH_ERRORS | ||
if "error" in result[1]["validation_severity"].values | ||
else SubmissionState.VALIDATION_WITH_WARNINGS | ||
) | ||
await update_submission( | ||
SubmissionDAO( | ||
submitter=submission_id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above comment |
||
state=sub_state, | ||
validation_ruleset_version=validator_version, | ||
validation_json=result[1].to_json(), | ||
) | ||
) | ||
else: | ||
await update_submission( | ||
SubmissionDAO( | ||
submitter=submission_id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
state=SubmissionState.VALIDATION_SUCCESSFUL, | ||
validation_ruleset_version=validator_version, | ||
validation_json=result[1].to_json(), | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's go with getting submission updated before the background_task kicks in; we don't need 2 nested bg tasks. so have the submission dao updated here to say validation in progress; then just 1 bg task that does the validation and update the submission dao when validation completes.
when we do the first submission update with the validation in progress, pass in the session already attached to the request. so
then the bg task's one, call it without passing in a session.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, we'll deal with this in the refactor that will happen in #51; just address the submission_id comment.