Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix(summary-flows) targetSubjectId is required in query filters. (M2-6900) #1383

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions src/apps/answers/crud/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
UserAnswerItemData,
)
from apps.answers.errors import AnswerNotFoundError
from apps.answers.filters import AppletSubmitDateFilter, ReviewAppletItemFilter
from apps.answers.filters import AppletSubmitDateFilter
from apps.applets.db.schemas import AppletHistorySchema
from apps.applets.domain.applet_history import Version
from apps.shared.filtering import Comparisons, FilterField, Filtering
Expand Down Expand Up @@ -222,19 +222,6 @@ async def get_flow_submissions(

return parse_obj_as(list[FlowSubmission], data), count

async def get_respondents_answered_activities_by_applet_id(
self, applet_id: uuid.UUID, filters: ReviewAppletItemFilter
) -> list[AnswerSchema]:
query: Query = select(AnswerSchema)
query = query.where(AnswerSchema.applet_id == applet_id)
query = query.where(func.date(AnswerSchema.created_at) == filters.created_date)
if filters.target_subject_id:
query = query.where(AnswerSchema.target_subject_id == filters.target_subject_id)
query = query.order_by(AnswerSchema.created_at.asc())

db_result = await self._execute(query)
return db_result.scalars().all()

async def get_respondents_submit_dates(
self, applet_id: uuid.UUID, filters: AppletSubmitDateFilter
) -> list[datetime.date]:
Expand Down
2 changes: 1 addition & 1 deletion src/apps/answers/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SummaryActivityFilter(BaseQueryParams):


class ReviewAppletItemFilter(BaseQueryParams):
target_subject_id: uuid.UUID | None
target_subject_id: uuid.UUID
created_date: datetime.date


Expand Down
17 changes: 17 additions & 0 deletions src/apps/answers/tests/test_answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1888,3 +1888,20 @@ async def test_access_to_activity_list(
client.login(user)
response = await client.get(url)
assert response.status_code == expected

async def test_review_flows_one_answer_without_target_subject_id(
self, mock_kiq_report, client, tom: User, applet_with_flow: AppletFull, tom_answer_activity_flow, session
):
client.login(tom)
url = self.review_flows_url.format(applet_id=applet_with_flow.id)

response = await client.get(
url,
dict(
createdDate=datetime.datetime.utcnow().date(),
),
)
assert response.status_code == 422
data = response.json()
assert data["result"][0]["message"] == "field required"
assert data["result"][0]["path"] == ["query", "targetSubjectId"]
Loading