diff --git a/app/blueprints/fund/routes.py b/app/blueprints/fund/routes.py index 3630bdc5..d1b30f16 100644 --- a/app/blueprints/fund/routes.py +++ b/app/blueprints/fund/routes.py @@ -11,7 +11,7 @@ from app.blueprints.fund.forms import FundForm from app.blueprints.fund.services import build_fund_rows from app.db.models.fund import Fund, FundingType -from app.db.queries.fund import add_fund, get_all_funds, get_fund_by_id, update_fund, delete_selected_fund +from app.db.queries.fund import add_fund, get_all_funds, get_fund_by_id, update_fund from app.shared.helpers import flash_message from app.shared.table_pagination import GovUKTableAndPagination @@ -44,17 +44,13 @@ def view_all_funds(): return render_template("view_all_funds.html", **params) -@fund_bp.route("/", methods=["GET", "DELETE"]) +@fund_bp.route("/", methods=["GET"]) def view_fund_details(fund_id): """ Renders grant details page """ form = FundForm() - if request.method == "DELETE": - delete_selected_fund(fund_id) - return redirect(url_for("fund_bp.view_all_funds")) fund = get_fund_by_id(fund_id) - #TODO at this time we are not implementing the delete grant but later we have to implement return render_template("fund_details.html", form=form, fund=fund) diff --git a/app/blueprints/round/routes.py b/app/blueprints/round/routes.py index 454c7392..382b4f97 100644 --- a/app/blueprints/round/routes.py +++ b/app/blueprints/round/routes.py @@ -19,11 +19,10 @@ ) from app.db.queries.clone import clone_single_round from app.db.queries.fund import get_all_funds, get_fund_by_id -from app.db.queries.round import get_all_rounds, get_round_by_id, delete_selected_round +from app.db.queries.round import get_all_rounds, get_round_by_id from app.shared.forms import SelectFundForm from app.shared.helpers import flash_message from app.shared.table_pagination import GovUKTableAndPagination -from config import Config INDEX_BP_DASHBOARD = "index_bp.dashboard" ROUND_DETAILS = "round_bp.round_details" @@ -198,16 +197,12 @@ def clone_round(round_id): return redirect(url_for(ROUND_DETAILS, round_id=round_id)) -@round_bp.route("/", methods=["GET", "DELETE"]) +@round_bp.route("/") def round_details(round_id): fund_round = get_round_by_id(round_id) form = RoundForm(data={"fund_id": fund_round.fund_id}) - fund_form = FundForm() - if request.method == "DELETE": - delete_selected_round(round_id) - return redirect(url_for("round_bp.view_all_rounds")) cloned_form = CloneRoundForm(data={"fund_id": fund_round.fund_id}) - # TODO at this time we are not implementing the delete applications but later we have to implement + fund_form = FundForm() return render_template( - "round_details.html", form=form, fund_form=fund_form, round=fund_round, - cloned_form=cloned_form) + "round_details.html", form=form, fund_form=fund_form, round=fund_round, cloned_form=cloned_form + ) diff --git a/app/db/queries/fund.py b/app/db/queries/fund.py index 686a5647..ce121608 100644 --- a/app/db/queries/fund.py +++ b/app/db/queries/fund.py @@ -1,4 +1,3 @@ -from f86018f3ab453f90c0c3__mypyc import init_djlint___src from flask import current_app from sqlalchemy import String, cast, select from sqlalchemy.orm import joinedload diff --git a/tests/blueprints/fund/test_routes.py b/tests/blueprints/fund/test_routes.py index 6c64d247..b68af8f8 100644 --- a/tests/blueprints/fund/test_routes.py +++ b/tests/blueprints/fund/test_routes.py @@ -1,9 +1,8 @@ import pytest from bs4 import BeautifulSoup from flask import g -from sqlalchemy.orm import joinedload -from app.db.models import Fund, Round, Section, Component, Lizt +from app.db.models import Fund from app.db.models.fund import FundingType from app.db.queries.fund import get_fund_by_id from tests.helpers import submit_form @@ -330,8 +329,8 @@ def test_view_fund_details(flask_test_client, seed_dynamic_data): html = response.data.decode("utf-8") assert f'

{test_fund.name_json["en"]}

' in html assert ( - f'Change' - f' Grant name' in html # noqa: E501 + f'Change' + f' Grant name' in html # noqa: E501 ) assert 'Back' in html @@ -357,30 +356,3 @@ def test_create_fund_welsh_error_messages(flask_test_client, seed_dynamic_data): assert b"Enter the Welsh grant name" in response.data # Validation error message assert b"Enter the Welsh application name" in response.data # Validation error message assert b"Enter the Welsh grant description" in response.data # Validation error message - - -@pytest.mark.usefixtures("set_auth_cookie", "patch_validate_token_rs256_internal_user") -def test_delete_fund_feature_enabled(_db, flask_test_client, seed_fund_without_assessment): - """Test that the delete endpoint redirects to grant table page""" - test_fund: Fund = seed_fund_without_assessment["funds"][0] - flask_test_client.get(f"/grants/{test_fund.fund_id}") - with flask_test_client.session_transaction(): - output: Fund = _db.session.get(Fund, test_fund.fund_id, - options=[joinedload(Fund.rounds).joinedload(Round.sections)]) - assert output is not None, "No values present in the db" - response = flask_test_client.delete(f"/grants/{test_fund.fund_id}", data={ - "csrf_token": g.csrf_token, - }, follow_redirects=True) - assert response.status_code == 200 # Assuming redirection to a valid page - _db.session.commit() - output_f = _db.session.get(Fund, test_fund.fund_id, - options=[joinedload(Fund.rounds).joinedload(Round.sections)]) - assert output_f is None, "Grant delete did not happened" - output_r = _db.session.query(Round).all() - assert not output_r, "Round delete did not happened" - output_s = _db.session.query(Section).all() - assert not output_s, "Section delete did not happened" - output_c = _db.session.query(Component).all() - assert not output_c, "Component delete did not happened" - output_l = _db.session.query(Lizt).all() - assert not output_l, "Lizt delete did not happened" diff --git a/tests/blueprints/round/test_routes.py b/tests/blueprints/round/test_routes.py index 6449632f..6d8413d2 100644 --- a/tests/blueprints/round/test_routes.py +++ b/tests/blueprints/round/test_routes.py @@ -1,9 +1,8 @@ import pytest from bs4 import BeautifulSoup from flask import g, url_for -from sqlalchemy.orm import joinedload -from app.db.models import Round, Fund, Section, Component, Lizt +from app.db.models import Round from app.db.queries.round import get_round_by_id from tests.helpers import submit_form @@ -331,30 +330,3 @@ def test_clone_round(flask_test_client, seed_dynamic_data): soup = BeautifulSoup(response.data, "html.parser") notification = soup.find("div", {"class": "govuk-notification-banner__content"}) assert notification.text.strip() == "Error copying application" - - -@pytest.mark.usefixtures("set_auth_cookie", "patch_validate_token_rs256_internal_user") -def test_delete_fund_feature_enabled(_db, flask_test_client, seed_fund_without_assessment): - """Test that the delete endpoint redirects application table page""" - test_round: Round = seed_fund_without_assessment["rounds"][0] - flask_test_client.get(f"/rounds/{test_round.round_id}") - with flask_test_client.session_transaction(): - output: Fund = _db.session.get(Fund, test_round.fund_id, - options=[joinedload(Fund.rounds).joinedload(Round.sections)]) - assert output is not None, "No values present in the db" - response = flask_test_client.delete(f"/rounds/{test_round.round_id}", data={ - "csrf_token": g.csrf_token, - }, follow_redirects=True) - assert response.status_code == 200 # Assuming redirection to a valid page - _db.session.commit() - output_f = _db.session.get(Fund, test_round.fund_id, - options=[joinedload(Fund.rounds).joinedload(Round.sections)]) - assert output_f is not None, "Grant deleted" - output_r = _db.session.query(Round).all() - assert not output_r, "Round delete did not happened" - output_s = _db.session.query(Section).all() - assert not output_s, "Section delete did not happened" - output_c = _db.session.query(Component).all() - assert not output_c, "Component delete did not happened" - output_l = _db.session.query(Lizt).all() - assert not output_l, "Lizt delete did not happened" diff --git a/tests/test_db.py b/tests/test_db.py index 079f8f8d..d6887ebb 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -4,8 +4,9 @@ import pytest -from app.db.models import Form, Fund, Organisation, Round, Section +from app.db.models import Form, Fund, Organisation, Round, Section, Component, Lizt from app.db.models.fund import FundingType +from sqlalchemy.orm import joinedload from app.db.queries.application import ( delete_form_from_section, delete_section_from_round, @@ -16,8 +17,8 @@ move_section_up, swap_elements_in_list, ) -from app.db.queries.fund import add_fund, add_organisation, get_all_funds, get_fund_by_id -from app.db.queries.round import add_round, get_round_by_id +from app.db.queries.fund import add_fund, add_organisation, get_all_funds, get_fund_by_id, delete_selected_fund +from app.db.queries.round import add_round, get_round_by_id, delete_selected_round from tests.seed_test_data import BASIC_FUND_INFO, BASIC_ROUND_INFO @@ -568,3 +569,45 @@ def test_base_path_sequence_insert(seed_dynamic_data, _db): added_round_2 = add_round(new_round_2) assert added_round_2.section_base_path assert added_round_2.section_base_path > added_round_1.section_base_path + + +def test_delete_grant(_db, seed_fund_without_assessment): + """Test that the delete endpoint redirects to grant table page""" + test_fund: Fund = seed_fund_without_assessment["funds"][0] + output: Fund = _db.session.get(Fund, test_fund.fund_id, + options=[joinedload(Fund.rounds).joinedload(Round.sections)]) + assert output is not None, "No values present in the db" + delete_selected_fund(test_fund.fund_id) + _db.session.commit() + output_f = _db.session.get(Fund, test_fund.fund_id, + options=[joinedload(Fund.rounds).joinedload(Round.sections)]) + assert output_f is None, "Grant delete did not happened" + output_r = _db.session.query(Round).all() + assert not output_r, "Round delete did not happened" + output_s = _db.session.query(Section).all() + assert not output_s, "Section delete did not happened" + output_c = _db.session.query(Component).all() + assert not output_c, "Component delete did not happened" + output_l = _db.session.query(Lizt).all() + assert not output_l, "Lizt delete did not happened" + + +def test_delete_application(_db, seed_fund_without_assessment): + """Test that the delete endpoint redirects application table page""" + test_round: Round = seed_fund_without_assessment["rounds"][0] + output: Fund = _db.session.get(Fund, test_round.fund_id, + options=[joinedload(Fund.rounds).joinedload(Round.sections)]) + assert output is not None, "No values present in the db" + delete_selected_round(test_round.round_id) + _db.session.commit() + output_f = _db.session.get(Fund, test_round.fund_id, + options=[joinedload(Fund.rounds).joinedload(Round.sections)]) + assert output_f is not None, "Grant deleted" + output_r = _db.session.query(Round).all() + assert not output_r, "Round delete did not happened" + output_s = _db.session.query(Section).all() + assert not output_s, "Section delete did not happened" + output_c = _db.session.query(Component).all() + assert not output_c, "Component delete did not happened" + output_l = _db.session.query(Lizt).all() + assert not output_l, "Lizt delete did not happened"