Skip to content

Commit

Permalink
separate out unit test and ui test data
Browse files Browse the repository at this point in the history
  • Loading branch information
srh-sloan committed Jul 18, 2024
1 parent 57fe637 commit da05f76
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 81 deletions.
3 changes: 2 additions & 1 deletion tasks/db_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from app.app import app # noqa:E402

from .test_data import init_salmon_fishing_fund # noqa:E402
from .test_data import insert_test_data # noqa:E402


Expand Down Expand Up @@ -62,7 +63,7 @@ def create_test_data(c):
)
)
db.session.commit()
insert_test_data(db=db)
insert_test_data(db=db, test_data=init_salmon_fishing_fund())


@task
Expand Down
222 changes: 159 additions & 63 deletions tasks/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from app.db.models import Theme


def init_data() -> dict:
def init_salmon_fishing_fund():

f: Fund = Fund(
fund_id=uuid4(),
name_json={"en": "Salmon Fishing Fund"},
Expand Down Expand Up @@ -101,30 +102,14 @@ def init_data() -> dict:
name_in_apply_json={"en": "Organisation Classification"},
form_index=4,
)
# p_org_alt_names: Page = Page(
# page_id=uuid4(),
# form_id=None,
# display_path="organisation-alternative-names",
# name_in_apply_json={"en": "Alternative names of your organisation"},
# form_index=2,
# is_template=True,
# )
# template_page: Page = Page(
# page_id=uuid4(),
# form_id=None,
# display_path="testing_templates_path",
# is_template=True,
# name_in_apply_json={"en": "Template Path"},
# form_index=0,
# )
# non_template_page: Page = Page(
# page_id=uuid4(),
# form_id=None,
# display_path="testing_templates_path",
# is_template=False,
# name_in_apply_json={"en": "Not Template Path"},
# form_index=0,
# )
p_org_alt_names: Page = Page(
page_id=uuid4(),
form_id=None,
display_path="organisation-alternative-names",
name_in_apply_json={"en": "Alternative names of your organisation"},
form_index=2,
is_template=True,
)
cri1: Criteria = Criteria(criteria_id=uuid4(), index=1, round_id=r.round_id, name="Unscored", weighting=0.0)
sc1: Subcriteria = Subcriteria(
subcriteria_id=uuid4(), criteria_index=1, criteria_id=cri1.criteria_id, name="Organisation Information"
Expand Down Expand Up @@ -178,31 +163,31 @@ def init_data() -> dict:
options={"hideTitle": False, "classes": ""},
runner_component_name="organisation_name",
)
# c3: Component = Component(
# component_id=uuid4(),
# page_id=p1.page_id,
# title="Does your organisation use any other names?",
# type=ComponentType.YES_NO_FIELD,
# page_index=2,
# theme_id=t1.theme_id,
# theme_index=2,
# options={"hideTitle": False, "classes": ""},
# runner_component_name="does_your_organisation_use_other_names",
# conditions=[
# {
# "name": "organisation_other_names_no",
# "value": "false", # this must be lowercaes or the navigation doesn't work
# "operator": "is",
# "destination_page_path": "CONTINUE",
# },
# {
# "name": "organisation_other_names_yes",
# "value": "true", # this must be lowercaes or the navigation doesn't work
# "operator": "is",
# "destination_page_path": "organisation-alternative-names",
# },
# ],
# )
c3: Component = Component(
component_id=uuid4(),
page_id=p1.page_id,
title="Does your organisation use any other names?",
type=ComponentType.YES_NO_FIELD,
page_index=2,
theme_id=t1.theme_id,
theme_index=2,
options={"hideTitle": False, "classes": ""},
runner_component_name="does_your_organisation_use_other_names",
conditions=[
{
"name": "organisation_other_names_no",
"value": "false", # this must be lowercaes or the navigation doesn't work
"operator": "is",
"destination_page_path": "CONTINUE",
},
{
"name": "organisation_other_names_yes",
"value": "true", # this must be lowercaes or the navigation doesn't work
"operator": "is",
"destination_page_path": "organisation-alternative-names",
},
],
)
c2: Component = Component(
component_id=uuid4(),
page_id=p2.page_id,
Expand All @@ -215,17 +200,17 @@ def init_data() -> dict:
options={"hideTitle": False, "classes": ""},
runner_component_name="organisation_address",
)
# c7: Component = Component(
# component_id=uuid4(),
# page_id=p_org_alt_names.page_id,
# title="Alternative Name 1",
# type=ComponentType.TEXT_FIELD,
# page_index=1,
# theme_id=None,
# theme_index=None,
# options={"hideTitle": False, "classes": ""},
# runner_component_name="alt_name_1",
# )
c7: Component = Component(
component_id=uuid4(),
page_id=p_org_alt_names.page_id,
title="Alternative Name 1",
type=ComponentType.TEXT_FIELD,
page_index=1,
theme_id=None,
theme_index=None,
options={"hideTitle": False, "classes": ""},
runner_component_name="alt_name_1",
)
l1: Lizt = Lizt(
list_id=uuid4(),
name="classifications_list",
Expand All @@ -251,14 +236,125 @@ def init_data() -> dict:
"rounds": [r, r2],
"sections": [s1],
"forms": [f1, f2],
"pages": [p1, p2, p3, p5], # template_page, non_template_page, p_org_alt_names
"components": [c1, c2, c4, c5, c6, c8], # c3,c7
"pages": [p1, p2, p3, p5, p_org_alt_names],
"components": [c1, c2, c4, c5, c6, c8, c3, c7],
"criteria": [cri1],
"subcriteria": [sc1],
"themes": [t1, t2],
}


def init_unit_test_data() -> dict:
f: Fund = Fund(
fund_id=uuid4(),
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."},
welsh_available=False,
short_name=f"UTF{randint(0,999)}",
)

r: Round = Round(
round_id=uuid4(),
fund_id=f.fund_id,
audit_info={"user": "dummy_user", "timestamp": datetime.now().isoformat(), "action": "create"},
title_json={"en": "round the first"},
short_name=f"UTR{randint(0,999)}",
opens=datetime.now(),
deadline=datetime.now(),
assessment_start=datetime.now(),
reminder_date=datetime.now(),
assessment_deadline=datetime.now(),
prospectus_link="http://www.google.com",
privacy_notice_link="http://www.google.com",
)
# r2: Round = Round(
# round_id=uuid4(),
# fund_id=f.fund_id,
# audit_info={"user": "dummy_user", "timestamp": datetime.now().isoformat(), "action": "create"},
# title_json={"en": "round the second"},
# short_name=f"UTR{randint(0,999)}",
# opens=datetime.now(),
# deadline=datetime.now(),
# assessment_start=datetime.now(),
# reminder_date=datetime.now(),
# assessment_deadline=datetime.now(),
# prospectus_link="http://www.google.com",
# privacy_notice_link="http://www.google.com",
# )

s1: Section = Section(
section_id=uuid4(), index=1, round_id=r.round_id, name_in_apply_json={"en": "Organisation Information"}
)
f1: Form = Form(
form_id=uuid4(),
section_id=s1.section_id,
name_in_apply_json={"en": "About your organisation"},
section_index=1,
runner_publish_name="about-your-org",
)
p1: Page = Page(
page_id=uuid4(),
form_id=f1.form_id,
display_path="organisation-name",
name_in_apply_json={"en": "Organisation Name"},
form_index=1,
)

cri1: Criteria = Criteria(criteria_id=uuid4(), index=1, round_id=r.round_id, name="Unscored", weighting=0.0)
sc1: Subcriteria = Subcriteria(
subcriteria_id=uuid4(), criteria_index=1, criteria_id=cri1.criteria_id, name="Organisation Information"
)
t1: Theme = Theme(
theme_id=uuid4(), subcriteria_id=sc1.subcriteria_id, name="General Information", subcriteria_index=1
)

c1: Component = Component(
component_id=uuid4(),
page_id=p1.page_id,
title="What is your organisation's name?",
hint_text="This must match the regsitered legal organisation name",
type=ComponentType.TEXT_FIELD,
page_index=1,
theme_id=t1.theme_id,
theme_index=1,
options={"hideTitle": False, "classes": ""},
runner_component_name="organisation_name",
)

l1: Lizt = Lizt(
list_id=uuid4(),
name="classifications_list",
type="string",
items=[{"text": "Charity", "value": "charity"}, {"text": "Public Limited Company", "value": "plc"}],
is_template=True,
)
c_with_list: Component = Component(
component_id=uuid4(),
page_id=p1.page_id,
title="How is your organisation classified?",
type=ComponentType.RADIOS_FIELD,
page_index=2,
theme_id=t1.theme_id,
theme_index=6,
options={"hideTitle": False, "classes": ""},
runner_component_name="organisation_classification",
list_id=l1.list_id,
)
return {
"lists": [l1],
"funds": [f],
"rounds": [r],
"sections": [s1],
"forms": [f1],
"pages": [p1],
"components": [c1, c_with_list],
"criteria": [cri1],
"subcriteria": [sc1],
"themes": [t1],
}


def insert_test_data(db, test_data={}):
db.session.bulk_save_objects(test_data.get("funds", []))
db.session.commit()
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask_migrate import upgrade

from app.app import create_app
from tasks.test_data import init_data
from tasks.test_data import init_unit_test_data
from tasks.test_data import insert_test_data

pytest_plugins = ["fsd_test_utils.fixtures.db_fixtures"]
Expand All @@ -13,7 +13,7 @@ def seed_dynamic_data(request, app, clear_test_data, _db, enable_preserve_test_d
marker = request.node.get_closest_marker("seed_config")

if marker is None:
fab_seed_data = init_data()
fab_seed_data = init_unit_test_data()
else:
fab_seed_data = marker.args[0]
insert_test_data(db=_db, test_data=fab_seed_data)
Expand Down
33 changes: 18 additions & 15 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
from app.db.models import Fund
from app.db.models import Lizt
from app.db.queries.application import get_component_by_id
from app.db.queries.fund import get_all_funds
from app.db.queries.fund import get_fund_by_id
from app.question_reuse.generate_assessment_config import build_assessment_config
from app.question_reuse.generate_form import build_form_json


def test_build_form_json(seed_dynamic_data):
def test_build_form_json_no_conditions(seed_dynamic_data):

f: Fund = get_all_funds()[0]
f: Fund = get_fund_by_id(seed_dynamic_data["funds"][0].fund_id)
form: Form = f.rounds[0].sections[0].forms[0]

result = build_form_json(form=form)
assert result
assert len(result["pages"]) == 5
assert len(result["pages"]) == 3
exp_start_path = "/intro-about-your-organisation"
exp_second_path = "/organisation-name"
assert result["startPage"] == exp_start_path
Expand All @@ -36,32 +36,35 @@ def test_build_form_json(seed_dynamic_data):
# assert alt_names_page
# assert alt_names_page["next"][0]["path"] == "/organisation-address"

address_page = next((p for p in result["pages"] if p["path"] == "/organisation-address"), None)
assert address_page
assert address_page["next"][0]["path"] == "/organisation-classification"
# address_page = next((p for p in result["pages"] if p["path"] == "/organisation-address"), None)
# assert address_page
# assert address_page["next"][0]["path"] == "/organisation-classification"

assert (
next((p for p in result["pages"] if p["path"] == "/organisation-classification"), None)["next"][0]["path"]
== "/summary"
)
# assert (
# next((p for p in result["pages"] if p["path"] == "/organisation-classification"), None)["next"][0]["path"]
# == "/summary"
# )
assert len(org_name_page["next"]) == 1
assert org_name_page["next"][0]["path"] == "/summary"
assert len(org_name_page["components"]) == 2

summary = next((p for p in result["pages"] if p["path"] == "/summary"), None)
assert summary


# TODO this fails with components from a template (branching logic)
def test_build_assessment_config(seed_dynamic_data):
f: Fund = get_all_funds()[0]

f: Fund = get_fund_by_id(seed_dynamic_data["funds"][0].fund_id)
criteria = f.rounds[0].criteria[0]
result = build_assessment_config(criteria_list=[criteria])
assert result
first_unscored = result["unscored_sections"][0]
assert first_unscored
assert first_unscored["name"] == "Unscored"
assert len(first_unscored["subcriteria"]) == 1
assert len(first_unscored["subcriteria"][0]["themes"]) == 2
assert len(first_unscored["subcriteria"][0]["themes"][0]["answers"]) == 3
assert len(first_unscored["subcriteria"][0]["themes"][1]["answers"]) == 3
assert len(first_unscored["subcriteria"][0]["themes"]) == 1
assert len(first_unscored["subcriteria"][0]["themes"][0]["answers"]) == 2


list_id = uuid4()
Expand Down

0 comments on commit da05f76

Please sign in to comment.