Skip to content

Commit

Permalink
fs-4749 adding funding_type to exports
Browse files Browse the repository at this point in the history
  • Loading branch information
srh-sloan committed Oct 18, 2024
1 parent 9736048 commit 0ed52ad
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 125 deletions.
5 changes: 3 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"extensions": [
"ms-python.debugpy",
"ms-python.vscode-pylance",
"mikoz.black-py"
"mikoz.black-py",
"eamodio.gitlens"
]
}
},
}
}
1 change: 1 addition & 0 deletions app/export_config/generate_fund_round_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def generate_fund_config(round_id):
owner_organisation_name="None",
owner_organisation_shortname="None",
owner_organisation_logo_uri="None",
funding_type=fund.funding_type.value,
)
return fund_export.as_dict()

Expand Down
3 changes: 3 additions & 0 deletions app/shared/data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing import Dict
from typing import Optional

from app.db.models.fund import FundingType


@dataclass
class SubCondition:
Expand Down Expand Up @@ -103,6 +105,7 @@ class FundExport:
owner_organisation_name: str
owner_organisation_shortname: str
owner_organisation_logo_uri: str
funding_type: FundingType
name_json: NameJson = field(default_factory=NameJson)
title_json: TitleJson = field(default_factory=TitleJson)
description_json: DescriptionJson = field(default_factory=DescriptionJson)
Expand Down
6 changes: 6 additions & 0 deletions tasks/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from app.db.models import Section
from app.db.models import Subcriteria
from app.db.models import Theme
from app.db.models.fund import FundingType
from app.shared.data_classes import Condition
from app.shared.data_classes import ConditionValue

Expand All @@ -24,6 +25,7 @@
"description_json": {"en": "A £10m fund to improve testing across the devolved nations."},
"welsh_available": False,
"owner_organisation_id": None,
"funding_type": FundingType.COMPETITIVE,
}
BASIC_ROUND_INFO = {
"audit_info": {"user": "dummy_user", "timestamp": datetime.now().isoformat(), "action": "create"},
Expand Down Expand Up @@ -80,6 +82,7 @@ def init_salmon_fishing_fund():
short_name="DF",
logo_uri="http://www.google.com",
audit_info={"user": "dummy_user", "timestamp": datetime.now().isoformat(), "action": "create"},
funding_type=FundingType.COMPETITIVE,
)

f: Fund = Fund(
Expand All @@ -92,6 +95,7 @@ def init_salmon_fishing_fund():
welsh_available=False,
short_name=f"SFF{randint(0,999)}",
owner_organisation_id=o.organisation_id,
funding_type=FundingType.COMPETITIVE,
)

r: Round = Round(
Expand Down Expand Up @@ -322,6 +326,7 @@ def init_salmon_fishing_fund():
welsh_available=False,
short_name="CTF",
owner_organisation_id=o.organisation_id,
funding_type=FundingType.COMPETITIVE,
)

rd: Round = Round(
Expand Down Expand Up @@ -368,6 +373,7 @@ def init_unit_test_data() -> dict:
welsh_available=False,
short_name=f"UTF{randint(0,999)}",
owner_organisation_id=o.organisation_id,
funding_type=FundingType.COMPETITIVE,
)

r: Round = Round(
Expand Down
30 changes: 3 additions & 27 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import shutil

import pytest
from flask_migrate import upgrade
from sqlalchemy import text

from app.create_app import create_app
from config import Config
from tasks.test_data import init_unit_test_data
from tasks.test_data import insert_test_data
from tests.helpers import create_test_fund
from tests.helpers import create_test_organisation
from tests.helpers import create_test_round
from config import Config
import shutil

pytest_plugins = ["fsd_test_utils.fixtures.db_fixtures"]

Expand All @@ -21,28 +19,6 @@ def temp_output_dir():
if temp_dir.exists():
shutil.rmtree(temp_dir)

@pytest.fixture
def test_fund(flask_test_client, _db, clear_test_data):
"""
Create a test fund using the test client and add it to the db.
Yields:
Fund: The created fund.
"""
org = create_test_organisation(flask_test_client)
return create_test_fund(flask_test_client, org)


@pytest.fixture
def test_round(flask_test_client, test_fund):
"""
Create a test round using the test client and add it to the db.
Yields:
Round: The created round.
"""
return create_test_round(flask_test_client, test_fund)


@pytest.fixture(scope="function")
def seed_dynamic_data(request, app, clear_test_data, _db, enable_preserve_test_data):
Expand Down
91 changes: 0 additions & 91 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
from datetime import datetime
from uuid import uuid4

from sqlalchemy import select

from app.db import db
from app.db.models import Fund
from app.db.models import Organisation
from app.db.models import Round
from app.db.queries.fund import add_fund
from app.db.queries.fund import add_organisation
from app.db.queries.round import add_round


def get_round_by_title(title: str) -> Round:
Expand All @@ -32,89 +24,6 @@ def get_round_by_title(title: str) -> Round:
return round


def create_test_organisation(flask_test_client):
"""
Creates a test Organisation and persists it to the database.
Args:
flask_test_client: The test client to use for the request
Returns:
The Organisation object created
"""
return add_organisation(
Organisation(
name=f"test_org_{uuid4().hex[:8]}",
short_name=f"X{uuid4().hex[:8]}",
logo_uri="http://www.example.com",
funds=[],
)
)


def create_test_fund(flask_test_client, organisation):
"""
Creates a test Fund and persists it to the database.
Args:
flask_test_client: The test client to use for the request
organisation: The Organisation object to use as the owner of the fund
Returns:
The Fund object created
"""
return add_fund(
Fund(
name_json={"en": "Test Fund"},
title_json={"en": "Test Fund Title"},
description_json={"en": "Test Fund Description"},
welsh_available=False,
short_name=f"F{uuid4().hex[:8]}",
owner_organisation_id=organisation.organisation_id,
)
)


def create_test_round(flask_test_client, fund):
"""
Creates a test Round and persists it to the database.
Args:
flask_test_client: The test client to use for the request
fund: The Fund object to use as the owner of the round
Returns:
The Round object created
"""
return add_round(
Round(
fund_id=fund.fund_id,
title_json={"en": "Test Round"},
short_name=f"R{uuid4().hex[:8]}",
opens=datetime.now().strftime("%m-%d-%Y %H:%M"),
deadline=datetime.now().strftime("%m-%d-%Y %H:%M"),
assessment_start=datetime.now().strftime("%m-%d-%Y %H:%M"),
reminder_date=datetime.now().strftime("%m-%d-%Y %H:%M"),
assessment_deadline=datetime.now().strftime("%m-%d-%Y %H:%M"),
prospectus_link="http://www.example.com",
privacy_notice_link="http://www.example.com",
contact_email="[email protected]",
contact_phone="1234567890",
contact_textphone="0987654321",
support_times="9am - 5pm",
support_days="Monday to Friday",
feedback_link="http://example.com/feedback",
project_name_field_id=1,
guidance_url="http://example.com/guidance",
eligibility_config={"has_eligibility": "false"},
eoi_decision_schema={"en": "eoi_decision_schema", "cy": ""},
contact_us_banner_json={"en": "contact_us_banner", "cy": ""},
instructions_json={"en": "instructions", "cy": ""},
application_guidance_json={"en": "application_guidance", "cy": ""},
)
)


def get_csrf_token(response):
"""
Extracts the CSRF token from the given response.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config_export.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ast
import json
import shutil
from pathlib import Path

import pytest
Expand Down Expand Up @@ -64,6 +63,7 @@ def test_generate_config_for_round_valid_input(seed_dynamic_data, monkeypatch, t
"name_json": {"en": "Unit Test Fund 1"},
"title_json": {"en": "funding to improve testing"},
"description_json": {"en": "A £10m fund to improve testing across the devolved nations."},
"funding_type": "COMPETITIVE",
},
"round_config": {
"short_name": round_short_name,
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_generate_config_for_round_invalid_input(seed_dynamic_data):
generate_config_for_round(round_id)


def test_generate_form_jsons_for_round_valid_input(seed_dynamic_data,temp_output_dir):
def test_generate_form_jsons_for_round_valid_input(seed_dynamic_data, temp_output_dir):
# Setup: Prepare valid input parameters
round_id = seed_dynamic_data["rounds"][0].round_id
round_short_name = seed_dynamic_data["rounds"][0].short_name
Expand Down
5 changes: 5 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from app.db.models import Organisation
from app.db.models import Round
from app.db.models import Section
from app.db.models.fund import FundingType
from app.db.queries.application import delete_form_from_section
from app.db.queries.application import delete_section_from_round
from app.db.queries.application import get_section_by_id
Expand Down Expand Up @@ -55,6 +56,7 @@ def test_add_fund(flask_test_client, _db, clear_test_data):
welsh_available=False,
short_name=f"X{randint(0,99999)}",
owner_organisation_id=o.organisation_id,
funding_type=FundingType.COMPETITIVE,
)
result = add_fund(f)
assert result
Expand All @@ -71,6 +73,7 @@ def test_add_fund(flask_test_client, _db, clear_test_data):
description_json={"en": "A £10m fund to improve stuff across the devolved nations."},
welsh_available=False,
short_name="TFCR1",
funding_type=FundingType.COMPETITIVE,
)
]
}
Expand Down Expand Up @@ -132,6 +135,7 @@ def test_get_all_funds(flask_test_client, _db, seed_dynamic_data):
description_json={"en": "A £10m fund to improve stuff across the devolved nations."},
welsh_available=False,
short_name="TF1",
funding_type=FundingType.COMPETITIVE,
)
]
}
Expand Down Expand Up @@ -167,6 +171,7 @@ def test_get_round_by_id_none(flask_test_client, _db):
description_json={"en": "A £10m fund to improve stuff across the devolved nations."},
welsh_available=False,
short_name="TFR1",
funding_type=FundingType.COMPETITIVE,
)
],
"rounds": [
Expand Down
16 changes: 13 additions & 3 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from app.db.models import Fund
from app.db.models import Round
from app.db.models.fund import FundingType
from app.db.queries.fund import get_fund_by_id
from app.db.queries.round import get_round_by_id
from tests.helpers import submit_form
Expand All @@ -16,6 +17,7 @@ def test_create_fund(flask_test_client, _db, clear_test_data):
"description_en": "New Fund Description",
"welsh_available": "false",
"short_name": "NF5432",
"funding_type": FundingType.COMPETITIVE.value,
}

response = submit_form(flask_test_client, "/fund", create_data)
Expand All @@ -30,11 +32,13 @@ def test_create_fund(flask_test_client, _db, clear_test_data):
assert created_fund.__getattribute__(key[:-3] + "_json")["en"] == value
elif key == "welsh_available":
assert created_fund.welsh_available is False
elif key == "funding_type":
assert created_fund.funding_type.value == value
else:
assert created_fund.__getattribute__(key) == value


def test_update_fund(flask_test_client, test_fund):
def test_update_fund(flask_test_client, seed_dynamic_data):
"""
Tests that a fund can be successfully updated using the /fund/<fund_id> route
Verifies that the updated fund has the correct attributes
Expand All @@ -46,8 +50,10 @@ def test_update_fund(flask_test_client, test_fund):
"welsh_available": "true",
"short_name": "UF1234",
"submit": "Submit",
"funding_type": "EOI",
}

test_fund = seed_dynamic_data["funds"][0]
response = submit_form(flask_test_client, f"/fund/{test_fund.fund_id}", update_data)
assert response.status_code == 200

Expand All @@ -59,15 +65,18 @@ def test_update_fund(flask_test_client, test_fund):
assert updated_fund.__getattribute__(key[:-3] + "_json")["en"] == value
elif key == "welsh_available":
assert updated_fund.welsh_available is True
elif key == "funding_type":
assert updated_fund.funding_type.value == value
elif key != "submit":
assert updated_fund.__getattribute__(key) == value


def test_create_new_round(flask_test_client, test_fund):
def test_create_new_round(flask_test_client, seed_dynamic_data):
"""
Tests that a round can be successfully created using the /round route
Verifies that the created round has the correct attributes
"""
test_fund = seed_dynamic_data["funds"][0]
new_round_data = {
"fund_id": test_fund.fund_id,
"title_en": "New Round",
Expand Down Expand Up @@ -119,7 +128,7 @@ def test_create_new_round(flask_test_client, test_fund):
assert new_round.short_name == "NR123"


def test_update_existing_round(flask_test_client, test_round):
def test_update_existing_round(flask_test_client, seed_dynamic_data):
"""
Tests that a round can be successfully updated using the /round/<round_id> route
Verifies that the updated round has the correct attributes
Expand Down Expand Up @@ -165,6 +174,7 @@ def test_update_existing_round(flask_test_client, test_round):
"guidance_url": "http://example.com/guidance",
}

test_round = seed_dynamic_data["rounds"][0]
response = submit_form(flask_test_client, f"/round/{test_round.round_id}", update_round_data)
assert response.status_code == 200

Expand Down

0 comments on commit 0ed52ad

Please sign in to comment.