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

Persist submitting user metadata #563

Merged
merged 1 commit into from
May 8, 2024
Merged

Conversation

sc15zs
Copy link
Contributor

@sc15zs sc15zs commented May 2, 2024

Ticket:
https://dluhcdigital.atlassian.net/browse/FMD-251

Description:
Adds two new fields to Submission model in data-store.
Saves submitting user's account_id and email to these fields passed in from post-award-submit.
PR for this:
communitiesuk/funding-service-design-post-award-submit#160

Test:
Tested locally and in dev environment.

Copy link
Contributor

@Joel-Pearce Joel-Pearce left a comment

Choose a reason for hiding this comment

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

This functionality is going to require a unit test in which a mocked json containing this metadata from the frontend hits the /ingest endpoint.

At the very least, save_submission_file_name_and_user_metadata is going to require a unit test.

@sc15zs sc15zs force-pushed the persist_submitting_user_metadata branch from b9b0d10 to baba43a Compare May 3, 2024 15:23
@sc15zs
Copy link
Contributor Author

sc15zs commented May 7, 2024

This functionality is going to require a unit test in which a mocked json containing this metadata from the frontend hits the /ingest endpoint.

At the very least, save_submission_file_name_and_user_metadata is going to require a unit test.

Unit test has been added to make sure that new field values are saved to submission model from submission json.

@sc15zs sc15zs force-pushed the persist_submitting_user_metadata branch from 97576b6 to 92c416f Compare May 7, 2024 11:53
core/controllers/ingest.py Outdated Show resolved Hide resolved
Comment on lines +575 to +576
submitting_account_id = sqla.Column(sqla.String())
submitting_user_email = sqla.Column(sqla.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to think about whether we can backfill these columns and make them non-nullable in the future. Could you make a ticket for this and put it in the refinement bucket of one of the boards please (probably submit's board)? :)

@sc15zs sc15zs force-pushed the persist_submitting_user_metadata branch from 60bf6d7 to d924fc0 Compare May 7, 2024 15:17
@sc15zs sc15zs requested review from nsnape and Joel-Pearce May 7, 2024 16:50
@sc15zs sc15zs force-pushed the persist_submitting_user_metadata branch from 6c9a4d8 to 2d4f0c7 Compare May 8, 2024 12:09
)

# Check that submitting_account_id and submitting_user_email are saved on the Submission
sub = Submission.query.filter_by(submission_id="S-PF-R01-1").first()
Copy link
Contributor

Choose a reason for hiding this comment

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

consider changing first() to one() - it's better practice as:

  • If you are only expecting one row, one() explicitly gets this, or throws an error.
  • If something changes in the future and there ends up being more than one row returned by that query (due to test fixture leakage, or badly defined test setup, or some regressive code change) then first() may give arbitrary, difficult to debug error messages, whereas one() will explicitly say it only expects one result


assert response.status_code == 200, f"{response.json}"

sub = Submission.query.filter_by(submission_id="S-PF-R01-1").first()
Copy link
Contributor

Choose a reason for hiding this comment

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

as per other comment, switch to use one()

@sc15zs sc15zs force-pushed the persist_submitting_user_metadata branch 2 times, most recently from 099aac2 to bde4b12 Compare May 8, 2024 13:22
assert sub.submitting_user_email == "testuser@levellingup.gov.uk"


def test_save_submission_file_name_and_user_metadata():
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs to use a test fixture that resets the changes, made within the test, otherwise there's a big risk of the data leaking into another test (probably in a separate module, or if someone extends this one). I think in this case the changes are not committed to the DB (from what I can tell by quickly reading it) so the appropriate fixture is probably seeded_test_client_rollback

@sc15zs sc15zs force-pushed the persist_submitting_user_metadata branch from 9e6d9ee to 4238299 Compare May 8, 2024 14:16
@sc15zs sc15zs force-pushed the persist_submitting_user_metadata branch from 4238299 to 88f949a Compare May 8, 2024 14:42
@sc15zs sc15zs merged commit 701ff8d into main May 8, 2024
2 checks passed
@sc15zs sc15zs deleted the persist_submitting_user_metadata branch May 8, 2024 14:57
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.

4 participants