Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srh-sloan committed Jul 1, 2024
1 parent 1240019 commit b5a1f14
Show file tree
Hide file tree
Showing 3 changed files with 286 additions and 70 deletions.
28 changes: 14 additions & 14 deletions app/data/not_a_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,21 @@
"type": "YesNoField",
"title": "Is the lead contact the same person as the authorised signatory?",
"hint": '<p class=\\"govuk-hint\\">An authorised signatory:<ul class=\\"govuk-list govuk-list--bullet govuk-hint\\"> <li>is allowed to act on behalf of the organisation</li> <li>will sign the grant funding agreement if your application is successful</li></ul></p>',
"conditions": [
{
"name": "lead_contact_same_as_signatory_yes",
"value": "True",
"operator": "is",
"destination_page": "CONTINUE",
},
{
"name": "lead_contact_same_as_signatory_no",
"value": "False",
"operator": "is",
"destination_page": "authorised-signatory-details",
},
],
},
"conditions": [
{
"name": "lead_contact_same_as_signatory_yes",
"value": "True",
"operator": "is",
"destination_page": "CONTINUE",
},
{
"name": "lead_contact_same_as_signatory_no",
"value": "False",
"operator": "is",
"destination_page": "authorised-signatory-details",
},
],
"id": "reuse_is_lead_contact_same_as_auth_signatory",
"builder_display_name": "",
},
Expand Down
231 changes: 213 additions & 18 deletions tests/test_build_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@


@pytest.mark.parametrize(
"input_json, exp_results",
"input_json,form_id, form_title, exp_results",
[
(
{
"title": "about-your-organisation",
"pages": ["organisation-name", "organisation-address"],
},
"form_id_1",
"Form Title",
{
"startPage": "/intro-about-your-organisation",
"pages": [
{
"path": "/intro-about-your-organisation",
"title": "Generated Form",
"path": "/intro-form_id_1",
"title": "Form Title",
"next": [{"path": "/organisation-name"}],
},
{
Expand Down Expand Up @@ -64,14 +66,16 @@
"lead-contact-details-and-auth-signatory",
],
},
"abc-123",
"This is the name of the form",
{
"metadata": {},
"startPage": "/intro-about-your-organisation",
"backLinkText": "Go back to application overview",
"pages": [
{
"path": "/intro-about-your-organisation",
"title": "Generated Form",
"path": "/intro-abc-123",
"title": "This is the name of the form",
"components": [],
"next": [{"path": "/organisation-name"}],
"options": {},
Expand Down Expand Up @@ -366,27 +370,218 @@
"name": "Generated by question bank 2024-06-18 13:54:24.954418",
},
),
(
{
"title": "about-your-organisation",
"pages": [
"lead-contact-details-and-auth-signatory",
],
},
"abc-123",
"This is the name of the form",
{
"metadata": {},
"startPage": "/intro-about-your-organisation",
"backLinkText": "Go back to application overview",
"pages": [
{
"path": "/intro-abc-123",
"title": "This is the name of the form",
"components": [],
"next": [{"path": "/lead-contact-details-and-auth-signatory"}],
"options": {},
"controller": "./pages/start.js",
},
{
"path": "/lead-contact-details-and-auth-signatory",
"title": "Lead contact details",
"components": [
{
"options": {"classes": "govuk-!-width-full"},
"type": "TextField",
"title": "Name of lead contact",
"hint": "They will receive all the information about this application.",
"name": "reuse-lead-contact-name",
},
{
"options": {"classes": "govuk-!-width-full"},
"type": "TextField",
"title": "Lead contact job title",
"name": "reuse-lead-contact-job-title",
},
{
"options": {"classes": "govuk-!-width-full"},
"type": "EmailAddressField",
"title": "Lead contact email address",
"name": "reuse-lead-contact-email",
},
{
"options": {"classes": "govuk-!-width-full"},
"type": "TelephoneNumberField",
"title": "Lead contact telephone number",
"name": "reuse-lead-contact-phone",
},
{
"options": {},
"type": "YesNoField",
"title": "Is the lead contact the same person as the authorised signatory?",
"hint": "<p class='govuk-hint'>An authorised signatory:<ul class='govuk-list govuk-list--bullet govuk-hint'> <li>is allowed to act on behalf of the organisation</li> <li>will sign the grant funding agreement if your application is successful</li></ul></p>",
"name": "reuse_is_lead_contact_same_as_auth_signatory",
},
],
"next": [
{
"path": "/summary",
"condition": "lead_contact_same_as_signatory_yes",
},
{
"path": "/authorised-signatory-details",
"condition": "lead_contact_same_as_signatory_no",
},
],
"options": {},
},
{
"path": "/authorised-signatory-details",
"title": "Authorised signatory details",
"components": [
{
"name": "xKWJWW",
"options": {},
"type": "Html",
"content": "<p class='govuk-hint'>An authorised signatory:</p>\\n<ul class='govuk-list govuk-list--bullet govuk-hint'>\\n <li>is allowed to act on behalf of the organisation</li>\\n <li>will sign the grant funding agreement if your application is successful</li>\\n </ul>",
"schema": {},
},
{
"name": "pDrPDz",
"options": {"classes": "govuk-!-width-full"},
"type": "TextField",
"title": "Authorised signatory full name",
"schema": {},
},
{
"name": "teowxM",
"options": {
"required": False,
"classes": "govuk-!-width-full",
},
"type": "TextField",
"title": "Alternative name",
"schema": {},
},
{
"name": "tikwxM",
"options": {
"required": True,
"classes": "govuk-!-width-full",
},
"type": "TextField",
"title": "Authorised signatory job title",
"schema": {},
},
{
"name": "ljfzCy",
"options": {"classes": "govuk-!-width-full"},
"type": "EmailAddressField",
"title": "Authorised signatory email address",
"schema": {},
},
{
"name": "gNgJme",
"options": {"classes": "govuk-!-width-full"},
"type": "TelephoneNumberField",
"title": "Authorised signatory telephone number",
"schema": {},
},
],
"next": [{"path": "/summary"}],
},
{
"path": "/summary",
"title": "Check your answers",
"components": [],
"next": [],
"section": "uLwBuz",
"controller": "./pages/summary.js",
},
],
"lists": [],
"conditions": [
{
"displayName": "lead_contact_same_as_signatory_yes",
"name": "lead_contact_same_as_signatory_yes",
"value": {
"name": "lead_contact_same_as_signatory_yes",
"conditions": [
{
"field": {
"name": "reuse_is_lead_contact_same_as_auth_signatory",
"type": "YesNoField",
"display": "Is the lead contact the same person as the authorised signatory?",
},
"operator": "is",
"value": {
"type": "Value",
"value": "True",
"display": "True",
},
}
],
},
},
{
"displayName": "lead_contact_same_as_signatory_no",
"name": "lead_contact_same_as_signatory_no",
"value": {
"name": "lead_contact_same_as_signatory_no",
"conditions": [
{
"field": {
"name": "reuse_is_lead_contact_same_as_auth_signatory",
"type": "YesNoField",
"display": "Is the lead contact the same person as the authorised signatory?",
},
"operator": "is",
"value": {
"type": "Value",
"value": "False",
"display": "False",
},
}
],
},
},
],
"fees": [],
"sections": [],
"outputs": [
{
"name": "update-form",
"title": "Update form in application store",
"type": "savePerPage",
"outputConfiguration": {
"savePerPageUrl": "https://webhook.site/a8d808ca-bf5e-4aea-aebc-f3d9bc93a435"
},
}
],
"skipSummary": False,
"name": "Generated by question bank 2024-06-18 13:54:24.954418",
},
),
],
)
def test_build_form(input_json, exp_results):
results = build_form_json(input_json)
def test_build_form(input_json, form_id, form_title, exp_results):
results = build_form_json(input_json=input_json, form_id=form_id, form_title=form_title)
assert results
assert len(results["pages"]) == len(exp_results["pages"])
assert results["name"] == form_title
for exp_page in exp_results["pages"]:
result_page = next(
res_page
for res_page in results["pages"]
if res_page["path"] == exp_page["path"]
)
result_page = next(res_page for res_page in results["pages"] if res_page["path"] == exp_page["path"])
assert result_page["title"] == exp_page["title"]
if "exp_component_count" in exp_page:
assert len(result_page["components"]) == exp_page["exp_component_count"]
if "next" in exp_page:
for exp_next in exp_page["next"]:
assert exp_next["path"] in [
next["path"] for next in result_page["next"]
]
assert exp_next["path"] in [next["path"] for next in result_page["next"]]
if "condition" in exp_next:
assert exp_next["condition"] in [
next["condition"] for next in result_page["next"]
]
assert exp_next["condition"] in [next["condition"] for next in result_page["next"]]
Loading

0 comments on commit b5a1f14

Please sign in to comment.