Skip to content

Commit

Permalink
feature: paragraph ItemResponseType for phrase builder response optio…
Browse files Browse the repository at this point in the history
…ns BE (M2-7762) (#1632)

* Allowing  paragraph item type as a response phrase field for the Action Plan.
* Added new repose_type case for the validate_phrasal_templates function.
* Unit test created that creates and applet with paragraph item and phrase builder with paragraph as an option to choose from the phrase builder.
  • Loading branch information
AlejandroCoronadoN authored Oct 29, 2024
1 parent cd8fb90 commit 69a4f67
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/apps/activities/domain/custom_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def validate_phrasal_templates(values: dict):
ResponseType.DATE,
ResponseType.SLIDERROWS,
ResponseType.SINGLESELECTROWS,
ResponseType.PARAGRAPHTEXT,
ResponseType.MULTISELECTROWS,
]:
raise IncorrectPhrasalTemplateItemTypeError()
Expand Down
18 changes: 18 additions & 0 deletions src/apps/activities/tests/fixtures/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,21 @@ def phrasal_template_with_slider_rows_create(
)

return [slider_rows_item_create, phrasal_item]


@pytest.fixture
def phrasal_template_with_paragraph_create(
phrasal_template_config: PhrasalTemplateConfig,
phrasal_template_with_paragraph_response_values: PhrasalTemplateValues,
base_item_data: BaseItemData,
paragraph_text_item_create,
):
phrasal_item = ActivityItemCreate(
**base_item_data.dict(exclude={"name"}),
name="phrasal_template_paragraph_test",
response_type=ResponseType.PHRASAL_TEMPLATE,
config=phrasal_template_config,
response_values=phrasal_template_with_paragraph_response_values,
)

return [paragraph_text_item_create, phrasal_item]
31 changes: 31 additions & 0 deletions src/apps/activities/tests/fixtures/response_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
MultiSelectionRowsValues,
MultiSelectionValues,
NumberSelectionValues,
ParagraphTextValues,
PhrasalTemplateDisplayMode,
PhrasalTemplateField,
PhrasalTemplatePhrase,
Expand Down Expand Up @@ -53,6 +54,13 @@ def single_select_response_values() -> SingleSelectionValues:
)


@pytest.fixture
def paragraph_response_values() -> ParagraphTextValues:
return ParagraphTextValues(
type=ResponseType.PARAGRAPHTEXT,
)


@pytest.fixture
def multi_select_response_values(
single_select_response_values: SingleSelectionValues,
Expand Down Expand Up @@ -202,6 +210,18 @@ def phrasal_template_with_slider_rows_response_fields(slider_rows_item_create) -
]


@pytest.fixture()
def phrasal_template_wiht_paragraph_response_fields(paragraph_text_item_create) -> List[PhrasalTemplateField]:
return [
_PhrasalTemplateSentenceField(text="test sentence"),
_PhrasalTemplateItemResponseField(
item_name=paragraph_text_item_create.name, display_mode=PhrasalTemplateDisplayMode.SENTENCE, item_index=0
),
_PhrasalTemplateLineBreakField(),
_PhrasalTemplateSentenceField(text="test sentence 2"),
]


@pytest.fixture
def phrasal_template_with_slider_rows_response_values(
phrasal_template_with_slider_rows_response_fields,
Expand All @@ -211,3 +231,14 @@ def phrasal_template_with_slider_rows_response_values(
card_title="test card title",
type=ResponseType.PHRASAL_TEMPLATE,
)


@pytest.fixture
def phrasal_template_with_paragraph_response_values(
phrasal_template_wiht_paragraph_response_fields,
) -> PhrasalTemplateValues:
return PhrasalTemplateValues(
phrases=[PhrasalTemplatePhrase(image=None, fields=phrasal_template_wiht_paragraph_response_fields)],
card_title="test paragraph card title",
type=ResponseType.PHRASAL_TEMPLATE,
)
7 changes: 6 additions & 1 deletion src/apps/applets/tests/test_applet_activity_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ async def test_create_applet_with_each_activity_item(
assert item["responseValues"] == item_create.response_values.dict(by_alias=True)

@pytest.mark.parametrize(
"item_fixture", ("phrasal_template_with_text_create", "phrasal_template_with_slider_rows_create")
"item_fixture",
(
"phrasal_template_with_text_create",
"phrasal_template_with_slider_rows_create",
"phrasal_template_with_paragraph_create",
),
)
async def test_create_applet_with_phrasal_template(
self,
Expand Down

0 comments on commit 69a4f67

Please sign in to comment.