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

File parsing and validation #70

Merged
merged 24 commits into from
Mar 6, 2024
Merged

File parsing and validation #70

merged 24 commits into from
Mar 6, 2024

Conversation

guffee23
Copy link
Contributor

@guffee23 guffee23 commented Feb 26, 2024

Closes #5

  • Broke out validate_submission into separate functions for specific tasks.
  • Changed update_submission to utilize new sessions when making db calls.
  • Call validates file passed in and updates the table to the current step in the process or with completed result.
  • Added pytests and fixtures for api and submission_processor.

validator_version = imeta.version("regtech-data-validator")

# Set VALIDATION_IN_PROGRESS
await update_submission(SubmissionDAO(submitter=submission_id, state=SubmissionState.VALIDATION_IN_PROGRESS))
Copy link
Contributor

@jcadam14 jcadam14 Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

submitter is going to be the username or email (see #52). The SubmissionDAO id field should be set to the submission_id. As it stands, each state update is creating a new entry in the database instead of updating the submission with that id.

)
await update_submission(
SubmissionDAO(
submitter=submission_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment

else:
await update_submission(
SubmissionDAO(
submitter=submission_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@@ -46,7 +46,7 @@ async def upload_file(
):
content = await file.read()
await submission_processor.upload_to_storage(lei, submission_id, content)
background_tasks.add_task(submission_processor.validate_submission, lei, submission_id, content)
background_tasks.add_task(submission_processor.validate_submission, lei, submission_id, content, background_tasks)
Copy link
Collaborator

@lchen-2101 lchen-2101 Feb 27, 2024

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

repo.update_submission(the_dao, request.state.db_session)

then the bg task's one, call it without passing in a session.

Copy link
Collaborator

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.

Copy link

github-actions bot commented Mar 5, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/entities/repos
  submission_repo.py
  src/routers
  filing.py
  src/services
  submission_processor.py 30-41
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Contributor

@jcadam14 jcadam14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to go after removing the unnecessary mock lines in def test_unauthed_upload_file. There is still the issue of the submitter being set to the submitter_id, but this will all be rewritten with #51 and I don't think it's worth the extra effort here to correct all that (would take faking up a submitter email/username, and submission ids). Just make sure that is corrected there.

mock_upload = mocker.patch("services.submission_processor.upload_to_storage")
mock_upload.return_value = None
mock_validate_submission = mocker.patch("services.submission_processor.validate_submission")
mock_validate_submission.return_value = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically these mock return values aren't needed because the unauthed hits and returns from the endpoint prior to any actual processing in the function.

Copy link
Contributor

@jcadam14 jcadam14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@jcadam14 jcadam14 merged commit e0763f1 into main Mar 6, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File parsing and validation
3 participants