Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NarenderRajuB committed Oct 18, 2024
1 parent fe08b92 commit ca179b9
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 2 deletions.
124 changes: 124 additions & 0 deletions app/db/migrations/versions/~2024_10_18_0344-ca6ccf18956b_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""empty message
Revision ID: ca6ccf18956b
Revises: da30746cec39
Create Date: 2024-10-18 03:44:16.320217
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'ca6ccf18956b'
down_revision = 'da30746cec39'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('page', schema=None) as batch_op:
batch_op.add_column(sa.Column('section', postgresql.JSON(none_as_null=True, astext_type=sa.Text()), nullable=True))

with op.batch_alter_table('round', schema=None) as batch_op:
batch_op.alter_column('application_reminder_sent',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('reference_contact_page_over_email',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('support_times',
existing_type=sa.VARCHAR(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('support_days',
existing_type=sa.VARCHAR(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('project_name_field_id',
existing_type=sa.VARCHAR(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('all_uploaded_documents_section_available',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('application_fields_download_available',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('display_logo_on_pdf_exports',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('mark_as_complete_enabled',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('is_expression_of_interest',
existing_type=sa.BOOLEAN(),
server_default=None,
existing_nullable=False)
batch_op.alter_column('section_base_path',
existing_type=sa.INTEGER(),
server_default=sa.text("nextval('section_base_path_seq')"),
existing_nullable=True)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('round', schema=None) as batch_op:
batch_op.alter_column('section_base_path',
existing_type=sa.INTEGER(),
server_default=sa.text("nextval('section_base_path_seq'::regclass)"),
existing_nullable=True)
batch_op.alter_column('is_expression_of_interest',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('mark_as_complete_enabled',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('display_logo_on_pdf_exports',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('application_fields_download_available',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('all_uploaded_documents_section_available',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('project_name_field_id',
existing_type=sa.VARCHAR(),
server_default=sa.text("''::character varying"),
existing_nullable=False)
batch_op.alter_column('support_days',
existing_type=sa.VARCHAR(),
server_default=sa.text("''::character varying"),
existing_nullable=False)
batch_op.alter_column('support_times',
existing_type=sa.VARCHAR(),
server_default=sa.text("''::character varying"),
existing_nullable=False)
batch_op.alter_column('reference_contact_page_over_email',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)
batch_op.alter_column('application_reminder_sent',
existing_type=sa.BOOLEAN(),
server_default=sa.text('false'),
existing_nullable=False)

with op.batch_alter_table('page', schema=None) as batch_op:
batch_op.drop_column('section')

# ### end Alembic commands ###
1 change: 1 addition & 0 deletions app/db/models/application_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class Page(BaseModel):
source_template_id = Column(UUID(as_uuid=True), nullable=True)
controller = Column(String(), nullable=True)
options = Column(JSON(none_as_null=True))
section = Column(JSON(none_as_null=True))

def __repr__(self):
return f"Page(/{self.display_path} - {self.name_in_apply_json['en']}, Components: {self.components})"
Expand Down
5 changes: 4 additions & 1 deletion app/export_config/generate_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"title": None,
"components": [],
"next": [],
"section": None,
}


Expand Down Expand Up @@ -81,7 +82,7 @@ def build_component(component: Component) -> dict:
"type": component.type.value if component.type else None,
"content": component.content,
"options": component.options or {},
"schema": {},
"schema": component.schema or {},
"title": component.title,
"name": component.runner_component_name,
}
Expand Down Expand Up @@ -269,6 +270,8 @@ def build_form_json(form: Form) -> dict:
# Build the basic page structure
for page in form.pages:
results["pages"].append(build_page(page=page))
if page.section:
results["sections"].append(page.section)

# start page is the page with the controller ending start.js
start_page = _find_page_by_controller(form.pages, "start.js")
Expand Down
1 change: 1 addition & 0 deletions app/export_config/generate_fund_round_form_jsons.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"path": {"type": "string"},
"title": {"type": "string"},
"options": {"type": "object"},
"section": {"type": "object"},
"components": {
"type": "array",
"items": {
Expand Down
5 changes: 4 additions & 1 deletion app/import_config/load_form_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def _build_condition(condition_data, destination_page_path) -> Condition:

def _get_component_by_runner_name(db, runner_component_name, page_id):

return db.session.query(Component).filter(Component.runner_component_name == runner_component_name).first()
return db.session.query(Component).filter(Component.runner_component_name == runner_component_name).filter()
db.session.quer()


def add_conditions_to_components(db, page: dict, conditions: dict, page_id):
Expand Down Expand Up @@ -145,6 +146,8 @@ def insert_page_as_template(page, form_id):
is_template=True,
template_name=page.get("title", None),
options=page.get("options", None),
section=page.get("section", None),

)
try:
db.session.add(new_page)
Expand Down
10 changes: 10 additions & 0 deletions app/shared/data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,13 @@ class RoundExport:

def as_dict(self):
return asdict(self)


@dataclass
class FormSection:
name: str
title: str
hideTitle: Optional[bool] = None

def as_dict(self):
return asdict(self)
7 changes: 7 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ services:
- 'NODE_CONFIG={"safelist": ["fab"]}'
- PREVIEW_MODE=true
- NODE_ENV=development
- SINGLE_REDIS=true
- FORM_RUNNER_ADAPTER_REDIS_INSTANCE_URI=redis://redis-data:6379

redis-data:
image: redis
ports:
- 6379:6379
62 changes: 62 additions & 0 deletions tests/test_data/test-section.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"metadata": {},
"startPage": "/first-page",
"pages": [
{
"title": "First page",
"path": "/first-page",
"components": [],
"next": [
{
"path": "/second-page"
}
],
"section": "aucbfI"
},
{
"path": "/second-page",
"title": "Second page",
"components": [
{
"name": "sBMuNR",
"options": {},
"type": "TextField",
"title": "Your name"
}
],
"next": [
{
"path": "/summary"
}
],
"section": "vJLJeJ"
},
{
"title": "Summary",
"path": "/summary",
"controller": "./pages/summary.js",
"components": []
}
],
"lists": [],
"sections": [
{
"name": "aucbfI",
"title": "Section 1",
"hideTitle": false
},
{
"name": "vJLJeJ",
"title": "Section 2",
"hideTitle": false
}
],
"conditions": [],
"fees": [],
"outputs": [],
"version": 2,
"skipSummary": false,
"feeOptions": {},
"markAsComplete": false,
"name":"section"
}
2 changes: 2 additions & 0 deletions tests/test_generate_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def test_build_lists(mocker, pages, exp_result):
name_in_apply_json={"en": "Organisation Name"},
form_index=1,
components=[mock_c_1],
section={"name": "abc", "title": "Section", "hideTitle": False},
),
{
"path": "/organisation-single-name",
Expand All @@ -126,6 +127,7 @@ def test_build_lists(mocker, pages, exp_result):
}
],
"next": [],
"section": "abc",
},
)
],
Expand Down
1 change: 1 addition & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def test_list_relationship(seed_dynamic_data):
16,
24,
), # noqa: E501
("test-section.json", "section.json", 3, 1),
],
)
def test_generate_config_for_round_valid_input(
Expand Down

0 comments on commit ca179b9

Please sign in to comment.