Skip to content

Commit

Permalink
fix: ensure flow_history_id is checked before filtering versions in a…
Browse files Browse the repository at this point in the history
…nswers
  • Loading branch information
Ramir Mesquita committed Dec 27, 2024
1 parent c9e5a35 commit 58a3baa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/apps/answers/crud/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ async def get_versions_by_activity_id(self, activity_id: uuid.UUID) -> list[Vers

for _, version, created_at, flow_history_id, _ in db_result.all():
# Filters out the activities associated with flows to display only isolated activities
if flow_history_id.endswith(version):
if flow_history_id and flow_history_id.endswith(version):
results.append(Version(version=version, created_at=created_at))

return results
Expand Down
12 changes: 6 additions & 6 deletions src/apps/answers/tests/test_answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ async def test_answer_skippable_activity_items_create_for_respondent(
assert len(response.json()["result"]["dates"]) == 1

async def test_answer_skippable_activity_items_create_for_respondent_with_flow_id(
self, client: TestClient, tom: User, answer_create: AppletAnswerCreate, applet: AppletFull
self, client: TestClient, tom: User, answer_create: AppletAnswerCreate, applet_with_flow: AppletFull
):
client.login(tom)

Expand All @@ -1017,12 +1017,12 @@ async def test_answer_skippable_activity_items_create_for_respondent_with_flow_i
assert response.status_code == http.HTTPStatus.CREATED, response.json()

response = await client.get(
self.applet_submit_dates_url.format(applet_id=str(applet.id)),
self.applet_submit_dates_url.format(applet_id=str(applet_with_flow.id)),
dict(
respondentId=tom.id,
fromDate=datetime.date.today() - datetime.timedelta(days=10),
toDate=datetime.date.today() + datetime.timedelta(days=10),
activityOrFlowId=applet.activity_flows[0].id,
activityOrFlowId=applet_with_flow.activity_flows[0].id,
),
)
assert response.status_code == http.HTTPStatus.OK
Expand All @@ -1049,20 +1049,20 @@ async def test_list_submit_dates(
assert len(response.json()["result"]["dates"]) == 1

async def test_list_submit_dates_with_flow_id(
self, client: TestClient, tom: User, answer_create: AppletAnswerCreate, applet: AppletFull
self, client: TestClient, tom: User, answer_create: AppletAnswerCreate, applet_with_flow: AppletFull
):
client.login(tom)

response = await client.post(self.answer_url, data=answer_create)
assert response.status_code == http.HTTPStatus.CREATED

response = await client.get(
self.applet_submit_dates_url.format(applet_id=str(applet.id)),
self.applet_submit_dates_url.format(applet_id=str(applet_with_flow.id)),
dict(
respondentId=tom.id,
fromDate=datetime.date.today() - datetime.timedelta(days=10),
toDate=datetime.date.today() + datetime.timedelta(days=10),
activityOrFlowId=applet.activity_flows[0].id,
activityOrFlowId=applet_with_flow.activity_flows[0].id,
),
)
assert response.status_code == http.HTTPStatus.OK
Expand Down
16 changes: 8 additions & 8 deletions src/apps/answers/tests/test_answers_arbitrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async def test_answer_skippable_activity_items_create_for_respondent_with_flow_i
arbitrary_client: TestClient,
tom: User,
answer_create: AppletAnswerCreate,
applet: AppletFull,
applet_with_flow: AppletFull,
):
arbitrary_client.login(tom)

Expand All @@ -280,12 +280,12 @@ async def test_answer_skippable_activity_items_create_for_respondent_with_flow_i
assert response.status_code == http.HTTPStatus.CREATED, response.json()

response = await arbitrary_client.get(
self.applet_submit_dates_url.format(applet_id=str(applet.id)),
self.applet_submit_dates_url.format(applet_id=str(applet_with_flow.id)),
dict(
respondentId=tom.id,
fromDate=datetime.date.today() - datetime.timedelta(days=10),
toDate=datetime.date.today() + datetime.timedelta(days=10),
activityOrFlowId=applet.activity_flows[0].id,
activityOrFlowId=applet_with_flow.activity_flows[0].id,
),
)
assert response.status_code == http.HTTPStatus.OK
Expand All @@ -298,33 +298,33 @@ async def test_list_submit_dates_with_flow_id(
arbitrary_client: TestClient,
tom: User,
answer_create: AppletAnswerCreate,
applet: AppletFull,
applet_with_flow: AppletFull,
):
arbitrary_client.login(tom)

response = await arbitrary_client.post(self.answer_url, data=answer_create)
assert response.status_code == http.HTTPStatus.CREATED

response = await arbitrary_client.get(
self.applet_submit_dates_url.format(applet_id=str(applet.id)),
self.applet_submit_dates_url.format(applet_id=str(applet_with_flow.id)),
dict(
respondentId=tom.id,
fromDate=datetime.date.today() - datetime.timedelta(days=10),
toDate=datetime.date.today() + datetime.timedelta(days=10),
activityOrFlowId=applet.activity_flows[0].id,
activityOrFlowId=applet_with_flow.activity_flows[0].id,
),
)
assert response.status_code == http.HTTPStatus.OK
assert len(response.json()["result"]["dates"]) == 1
await assert_answer_exist_on_arbitrary(str(answer_create.submit_id), arbitrary_session)

response = await arbitrary_client.get(
self.applet_submit_dates_url.format(applet_id=str(applet.id)),
self.applet_submit_dates_url.format(applet_id=str(applet_with_flow.id)),
dict(
respondentId=tom.id,
fromDate=datetime.date.today() - datetime.timedelta(days=10),
toDate=datetime.date.today() + datetime.timedelta(days=10),
activityOrFlowId=applet.activity_flows[0].id,
activityOrFlowId=applet_with_flow.activity_flows[0].id,
),
)
assert response.status_code == 200
Expand Down

0 comments on commit 58a3baa

Please sign in to comment.