Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-W1 committed Oct 2, 2024
1 parent 02421a7 commit 302a436
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 81 deletions.
7 changes: 6 additions & 1 deletion app/blueprints/fund_builder/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,12 @@ def create_new_round(form):
display_logo_on_pdf_exports=form.display_logo_on_pdf_exports.data == "true",
mark_as_complete_enabled=form.mark_as_complete_enabled.data == "true",
is_expression_of_interest=form.is_expression_of_interest.data == "true",
feedback_survey_config=form.feedback_survey_config.data,
feedback_survey_config={
"has_feedback_survey": form.feedback_survey_config.data,
"has_section_feedback": False,
"is_feedback_survey_optional": False,
"is_section_feedback_optional": False,
},
eligibility_config={"has_eligibility": form.eligibility_config.data},
eoi_decision_schema={"en": form.eoi_decision_schema.data, "cy": None},
)
Expand Down
6 changes: 3 additions & 3 deletions app/export_config/generate_fund_round_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def generate_fund_config(round_id):
short_name=fund.short_name,
description_json=fund.description_json,
welsh_available=fund.welsh_available,
owner_organisation_name=None,
owner_organisation_shortname=None,
owner_organisation_logo_uri=None,
owner_organisation_name="None",
owner_organisation_shortname="None",
owner_organisation_logo_uri="None",
)
return fund_export.as_dict()

Expand Down
12 changes: 4 additions & 8 deletions app/shared/data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,16 @@ class RoundExport:
mark_as_complete_enabled: Optional[bool] = None
is_expression_of_interest: Optional[bool] = None
eoi_decision_schema: Optional[Dict[str, str]] = None
# check to use FeedbackSurveyConfig
feedback_survey_config: Optional[Dict[str, str]] = (
{
feedback_survey_config: Optional[Dict[str, bool]] = field(
default_factory=lambda: {
"has_feedback_survey": False,
"has_section_feedback": False,
"is_feedback_survey_optional": False,
"is_section_feedback_optional": False,
},
}
)
# check to use EligibilityConfig
# TODO running DB migrations doesn't like next line
# eligibility_config: Optional[Dict[str, str]] = {"has_eligibility": False}
eligibility_config: Optional[Dict[str, bool]] = field(default_factory=lambda: {"has_eligibility": False})
title_json: TitleJson = field(default_factory=TitleJson)
# check to use EligibilityConfig
contact_us_banner_json: Optional[Dict[str, str]] = None

def as_dict(self):
Expand Down
143 changes: 76 additions & 67 deletions tests/test_config_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

def test_generate_config_for_round_valid_input(seed_dynamic_data, monkeypatch):
# Setup: Prepare valid input parameters
fund_id = seed_dynamic_data["funds"][0].fund_id
fund_short_name = seed_dynamic_data["funds"][0].short_name
round_id = seed_dynamic_data["rounds"][0].round_id
org_id = seed_dynamic_data["organisations"][0].organisation_id
round_short_name = seed_dynamic_data["rounds"][0].short_name
mock_round_base_paths = {round_short_name: 99}

Expand All @@ -35,75 +33,60 @@ def test_generate_config_for_round_valid_input(seed_dynamic_data, monkeypatch):
assert result is None
# Assert: Check if the directory structure and files are created as expected
expected_files = [
{
"path": output_base_path
/ round_short_name
/ "fund_store"
/ f"fund_config_{date.today().strftime('%d-%m-%Y')}.py",
"expected_output": {
"id": str(fund_id),
"short_name": fund_short_name,
"welsh_available": False,
"owner_organisation_name": f"Ministry of Testing - {str(org_id)[:5]}",
"owner_organisation_shortname": f"MoT-{str(org_id)[:5]}",
"owner_organisation_logo_uri": "http://www.google.com",
"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."},
},
},
{
"path": output_base_path
/ round_short_name
/ "fund_store"
/ f"round_config_{date.today().strftime('%d-%m-%Y')}.py",
"expected_output": {
"id": str(round_id),
"fund_id": str(fund_id),
"short_name": round_short_name,
"application_reminder_sent": False,
"prospectus": "http://www.google.com",
"privacy_notice": "http://www.google.com",
"reference_contact_page_over_email": False,
"contact_email": None,
"contact_phone": None,
"contact_textphone": None,
"support_times": "",
"support_days": "",
"instructions_json": None,
"feedback_link": None,
"project_name_field_id": "",
"application_guidance_json": None,
"guidance_url": None,
"all_uploaded_documents_section_available": False,
"application_fields_download_available": False,
"display_logo_on_pdf_exports": False,
"mark_as_complete_enabled": False,
"is_expression_of_interest": False,
"eoi_decision_schema": None,
"feedback_survey_config": None,
"eligibility_config": None,
"title_json": {"en": "round the first"},
"contact_us_banner_json": None,
},
},
{
"path": output_base_path
/ round_short_name
/ "fund_store"
/ f"sections_config_{date.today().strftime('%d-%m-%Y')}.py",
"expected_output": [
{
"section_name": {"en": "1. Organisation Information", "cy": ""},
"tree_path": "99.1",
"requires_feedback": None,
"sections_config": [
{
"section_name": {"en": "1. Organisation Information", "cy": ""},
"requires_feedback": None,
},
{
"section_name": {"en": "1.1 About your organisation", "cy": ""},
"form_name_json": {"en": "about-your-org", "cy": ""},
},
],
"fund_config": {
"short_name": fund_short_name,
"welsh_available": False,
"owner_organisation_name": "None",
"owner_organisation_shortname": "None",
"owner_organisation_logo_uri": "None",
"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."},
},
{
"section_name": {"en": "1.1 About your organisation", "cy": ""},
"tree_path": "99.1.1",
"form_name_json": {"en": "about-your-org", "cy": ""},
"round_config": {
"short_name": round_short_name,
"application_reminder_sent": False,
"prospectus": "http://www.google.com",
"privacy_notice": "http://www.google.com",
"reference_contact_page_over_email": False,
"contact_email": None,
"contact_phone": None,
"contact_textphone": None,
"support_times": "",
"support_days": "",
"instructions_json": None,
"feedback_link": None,
"project_name_field_id": "",
"application_guidance_json": None,
"guidance_url": None,
"all_uploaded_documents_section_available": False,
"application_fields_download_available": False,
"display_logo_on_pdf_exports": False,
"mark_as_complete_enabled": False,
"is_expression_of_interest": False,
"eoi_decision_schema": None,
"feedback_survey_config": None,
"eligibility_config": {"has_eligibility": False},
"title_json": {"en": "round the first"},
"contact_us_banner_json": None,
},
],
},
},
]
try:
Expand All @@ -116,11 +99,37 @@ def test_generate_config_for_round_valid_input(seed_dynamic_data, monkeypatch):
# Safely evaluate the Python literal structure
# only evaluates literals and not arbitrary code
data = ast.literal_eval(content)
# remove keys that can't be accurately compared
if isinstance(data, dict):
keys_to_remove = ["reminder_date", "assessment_start", "assessment_deadline", "deadline", "opens"]

if expected_file["expected_output"].get("fund_config", None):
# remove keys that can't be accurately compared
keys_to_remove = ["base_path"]
keys_to_remove_fund_config = ["id"]
keys_to_remove_round_config = [
"id",
"fund_id",
"reminder_date",
"assessment_start",
"assessment_deadline",
"deadline",
"opens",
]
keys_to_remove_section_config = ["tree_path"]
data = {k: v for k, v in data.items() if k not in keys_to_remove}
assert data == expected_file["expected_output"]
data["fund_config"] = {
k: v for k, v in data["fund_config"].items() if k not in keys_to_remove_fund_config
}
data["round_config"] = {
k: v for k, v in data["round_config"].items() if k not in keys_to_remove_round_config
}
data["sections_config"] = [
{k: v for k, v in section.items() if k not in keys_to_remove_section_config}
for section in data["sections_config"]
]
assert expected_file["expected_output"]["fund_config"] == data["fund_config"]
assert expected_file["expected_output"]["round_config"] == data["round_config"]
assert expected_file["expected_output"]["sections_config"] == data["sections_config"]
else:
assert data == expected_file["expected_output"]
finally:
# Cleanup step to remove the directory
directory_path = output_base_path / round_short_name
Expand Down
4 changes: 2 additions & 2 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def test_get_round_by_id_none(flask_test_client, _db):
display_logo_on_pdf_exports=False,
mark_as_complete_enabled=False,
is_expression_of_interest=False,
feedback_survey_config={},
eligibility_config={},
feedback_survey_config=None,
eligibility_config=None,
eoi_decision_schema={},
)
],
Expand Down

0 comments on commit 302a436

Please sign in to comment.