Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sc15zs committed May 8, 2024
1 parent d924fc0 commit 6c9a4d8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/controllers/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ def populate_db(
the workbook to the database.
:param excel_file: source spreadsheet containing the data.
:param load_mapping: dictionary of tables and functions to load the tables into the DB.
:param submitting_account_id: The account ID of the submitting user.
:param submitting_user_email: The email address of the submitting user.
:return: None
"""
reporting_round = int(transformed_data["Submission_Ref"]["Reporting Round"].iloc[0])
Expand Down Expand Up @@ -448,6 +450,8 @@ def save_submission_file_name_and_user_metadata(
:param excel_file: The Excel file to save.
:param submission_id: The ID of the submission to be updated.
:param submitting_account_id: The account ID of the submitting user.
:param submitting_user_email: The email address of the submitting user.
"""
submission = Submission.query.filter_by(submission_id=submission_id).first()
submission.submission_filename = excel_file.filename
Expand Down
33 changes: 33 additions & 0 deletions tests/integration_tests/test_ingest_component_pathfinders.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import json
from datetime import datetime
from pathlib import Path
from typing import BinaryIO

import pytest
from werkzeug.datastructures import FileStorage

from core.controllers.ingest import save_submission_file_name_and_user_metadata
from core.db import db
from core.db.entities import Programme, Submission


Expand Down Expand Up @@ -539,3 +543,32 @@ def test_ingest_pf_r1_file_success_2(test_client_reset, pathfinders_round_1_file
sub = Submission.query.filter_by(submission_id="S-PF-R01-1").first()
assert sub.submitting_account_id == "0000-1111-2222-3333-4444"
assert sub.submitting_user_email == "testuser@levellingup.gov.uk"


def test_save_submission_file_name_and_user_metadata(test_client_reset, pathfinders_round_1_file_success, test_buckets):
"""Tests save_submission_file_name_and_user_metadata() function in isolation, that submitting_account_id and
submitting_user_email values are saved to Submission model successfully."""

sub = Submission(
submission_id="S-PF-R01-1",
submission_date=datetime(2024, 5, 1),
reporting_period_start=datetime(2024, 4, 1),
reporting_period_end=datetime(2024, 4, 30),
reporting_round=1,
)
db.session.add(sub)

with open("tests/integration_tests/mock_pf_returns/PF_Round_1_Success.xlsx", "rb") as fp:
file = FileStorage(fp, "PF_Round_1_Success.xlsx")

save_submission_file_name_and_user_metadata(
excel_file=file,
submission_id="S-PF-R01-1",
submitting_account_id="0000-1111-2222-3333-4444",
submitting_user_email="testuser@levellingup.gov.uk",
)

# 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()
assert sub.submitting_account_id == "0000-1111-2222-3333-4444"
assert sub.submitting_user_email == "testuser@levellingup.gov.uk"

0 comments on commit 6c9a4d8

Please sign in to comment.