Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
https://dluhcdigital.atlassian.net/browse/FS-4666
Browse files Browse the repository at this point in the history
While user updating the application and round closed user responses will be saved & redirect them to the fund close page, but there will be trigger to that behavior.
  • Loading branch information
nuwan-samarasinghe committed Oct 8, 2024
1 parent 259eac7 commit beab522
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
5 changes: 4 additions & 1 deletion api/routes/application/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ def put(self):
"is_summary_page_submit": request_json["metadata"].get("isSummaryPageSubmit", False),
}
try:
updated_form = update_form(**form_dict)
updated_form, round_status = update_form(**form_dict)
if not round_status:
current_app.logger.info("Round is closed so user will be redirected")
return {}, 301
return updated_form, 201
except NoResultFound as e:
return {"code": 404, "message": str(e)}, 404
Expand Down
9 changes: 9 additions & 0 deletions db/queries/statuses/queries.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from db import db
from db.models import Applications
from db.models.forms.forms import Forms
Expand Down Expand Up @@ -243,3 +245,10 @@ def update_statuses(application_id: str, form_name: str, is_summary_page_submitt

update_application_status(application, round.feedback_survey_config)
db.session.commit()
if isinstance(round.deadline, datetime):
deadline = datetime.strptime(round.deadline.strftime("%Y-%m-%dT%H:%M:%S"), "%Y-%m-%dT%H:%M:%S")
else:
deadline = datetime.strptime(round.deadline, "%Y-%m-%dT%H:%M:%S")
if datetime.now() > deadline:
return False
return True
10 changes: 6 additions & 4 deletions db/queries/updating/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ def update_application_and_related_form(application_id, question_json, form_name
if (project_name := attempt_to_find_and_update_project_name(question_json, application)) is not None:
application.project_name = project_name
form_sql_row.json = question_json
update_statuses(application_id, form_name, is_summary_page_submit)
round_status = update_statuses(application_id, form_name, is_summary_page_submit)
db.session.commit()
current_app.logger.info(f"Application updated for application_id: '{application_id}.")
return round_status


def update_form(application_id, form_name, question_json, is_summary_page_submit):
try:
round_status = None
form_sql_row = get_form(application_id, form_name)
# Running update form for the first time
if question_json and not form_sql_row.json:
update_application_and_related_form(
round_status = update_application_and_related_form(
application_id,
question_json,
form_name,
Expand All @@ -47,7 +49,7 @@ def update_form(application_id, form_name, question_json, is_summary_page_submit
raise Exception("ABORTING UPDATE, INVALID DATA GIVEN")
# Updating form subsequent times
elif form_sql_row.json and form_sql_row.json != question_json:
update_application_and_related_form(
round_status = update_application_and_related_form(
application_id,
question_json,
form_name,
Expand All @@ -56,4 +58,4 @@ def update_form(application_id, form_name, question_json, is_summary_page_submit
except sqlalchemy.orm.exc.NoResultFound as e:
raise e
db.session.commit()
return form_sql_row.as_json()
return form_sql_row.as_json(), round_status
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime
from datetime import timedelta
from uuid import uuid4

import pytest
Expand Down Expand Up @@ -261,7 +262,9 @@ def generate_mock_round(fund_id: str, round_id: str) -> Round:
fund_id=fund_id,
short_name="TEST",
opens=datetime.strptime("2023-01-01 12:00:00", "%Y-%m-%d %H:%M:%S"),
deadline=datetime.strptime("2023-01-31 12:00:00", "%Y-%m-%d %H:%M:%S"),
deadline=datetime.strptime(
(datetime.now() + timedelta(days=10)).strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S"
),
assessment_deadline=datetime.strptime("2023-03-31 12:00:00", "%Y-%m-%d %H:%M:%S"),
project_name_field_id="TestFieldId",
contact_email="test@outlook.com",
Expand Down
47 changes: 47 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
from datetime import datetime
from datetime import timedelta
from unittest import mock
from unittest.mock import ANY
from unittest.mock import MagicMock
Expand All @@ -13,6 +15,7 @@
from db.queries.application import get_all_applications
from db.schemas import ApplicationSchema
from external_services.models.fund import Fund
from external_services.models.round import Round
from fsd_utils.services.aws_extended_client import SQSExtendedClient
from moto import mock_aws
from tests.helpers import application_expected_data
Expand Down Expand Up @@ -580,6 +583,33 @@ def test_complete_form(flask_test_client, seed_application_records):
assert section_status == "COMPLETED"


@pytest.mark.apps_to_insert([test_application_data[0]])
def test_form_data_save_with_closed_round(flask_test_client, seed_application_records, mocker):
"""
GIVEN We have a functioning Application Store API
WHEN A put is made with a completed section,
THEN The section JSON should be updated to
match the PUT'ed JSON and be marked as in-progress.
and if the round is closed then it will give a 301 to redirect the user to fund closure notification page
"""
mocker.patch("db.queries.application.queries.get_round", new=generate_mock_round_closed)
mocker.patch("db.queries.statuses.queries.get_round", new=generate_mock_round_closed)
section_put = {
"questions": test_question_data,
"metadata": {
"application_id": str(seed_application_records[0].id),
"form_name": "declarations",
"isSummaryPageSubmit": True,
},
}
response = flask_test_client.put(
"/applications/forms",
json=section_put,
follow_redirects=True,
)
assert response.status_code == 301


@pytest.mark.apps_to_insert([test_application_data[2]])
def test_put_returns_400_on_submitted_application(flask_test_client, _db, seed_application_records):
"""
Expand Down Expand Up @@ -726,6 +756,23 @@ def _mock_aws_client():
return sqs_extended_client


def generate_mock_round_closed(fund_id: str, round_id: str) -> Round:
return Round(
title="Generated test round",
id=round_id,
fund_id=fund_id,
short_name="TEST",
opens=datetime.strptime("2023-01-01 12:00:00", "%Y-%m-%d %H:%M:%S"),
deadline=datetime.strptime(
(datetime.now() - timedelta(days=10)).strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S"
),
assessment_deadline=datetime.strptime("2023-03-31 12:00:00", "%Y-%m-%d %H:%M:%S"),
project_name_field_id="TestFieldId",
contact_email="test@outlook.com",
title_json={"en": "English title", "cy": "Welsh title"},
)


def test_post_research_survey_data(flask_test_client, mocker):
request_data = {
"application_id": "123",
Expand Down

0 comments on commit beab522

Please sign in to comment.