Skip to content

Commit

Permalink
addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nuwan-samarasinghe committed Feb 7, 2025
1 parent f1c9ecb commit 15349ec
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 80 deletions.
8 changes: 2 additions & 6 deletions app/blueprints/fund/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -44,17 +44,13 @@ def view_all_funds():
return render_template("view_all_funds.html", **params)


@fund_bp.route("/<uuid:fund_id>", methods=["GET", "DELETE"])
@fund_bp.route("/<uuid:fund_id>", 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)


Expand Down
15 changes: 5 additions & 10 deletions app/blueprints/round/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -198,16 +197,12 @@ def clone_round(round_id):
return redirect(url_for(ROUND_DETAILS, round_id=round_id))


@round_bp.route("/<round_id>", methods=["GET", "DELETE"])
@round_bp.route("/<round_id>")
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
)
1 change: 0 additions & 1 deletion app/db/queries/fund.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
34 changes: 3 additions & 31 deletions tests/blueprints/fund/test_routes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -330,8 +329,8 @@ def test_view_fund_details(flask_test_client, seed_dynamic_data):
html = response.data.decode("utf-8")
assert f'<h1 class="govuk-heading-l">{test_fund.name_json["en"]}</h1>' in html
assert (
f'<a class="govuk-link govuk-link--no-visited-state" href="/grants/{test_fund.fund_id}/edit#name_en">Change'
f'<span class="govuk-visually-hidden"> Grant name</span></a>' in html # noqa: E501
f'<a class="govuk-link govuk-link--no-visited-state" href="/grants/{test_fund.fund_id}/edit#name_en">Change'
f'<span class="govuk-visually-hidden"> Grant name</span></a>' in html # noqa: E501
)
assert '<a href="/grants/" class="govuk-back-link">Back</a>' in html

Expand All @@ -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"
30 changes: 1 addition & 29 deletions tests/blueprints/round/test_routes.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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"
49 changes: 46 additions & 3 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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


Expand Down Expand Up @@ -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"

0 comments on commit 15349ec

Please sign in to comment.