diff --git a/app/models.py b/app/models.py index 059a290d..ea055a17 100644 --- a/app/models.py +++ b/app/models.py @@ -82,6 +82,7 @@ class QuestionSetMetric(BaseModel): num_correct: int num_wrong: int num_partially_correct: int + num_marked_for_review: Optional[int] # not there for non-assessment attempt_rate: float accuracy_rate: float @@ -93,6 +94,7 @@ class SessionMetrics(BaseModel): total_correct: int total_wrong: int total_partially_correct: int + total_marked_for_review: Optional[int] # not there for non-assessment total_marks: int @@ -400,6 +402,7 @@ class SessionAnswer(BaseModel): answer: answerType = None visited: bool = False time_spent: int = None # in seconds + marked_for_review: bool = False created_at: datetime = Field(default_factory=datetime.utcnow) updated_at: datetime = Field(default_factory=datetime.utcnow) @@ -418,6 +421,7 @@ class UpdateSessionAnswer(BaseModel): answer: Optional[answerType] visited: Optional[bool] time_spent: Optional[int] + marked_for_review: Optional[bool] updated_at: datetime = Field(default_factory=datetime.utcnow) class Config: diff --git a/app/routers/session_answers.py b/app/routers/session_answers.py index 4017139a..c11c89f0 100644 --- a/app/routers/session_answers.py +++ b/app/routers/session_answers.py @@ -91,7 +91,7 @@ async def update_session_answer_in_a_session( session_id - the id of the session position_index - the position index of the session answer in the session answers array. This corresponds to the position of the question in the quiz """ - log_message = f"Updating session answer for session: {session_id} at position: {position_index}. The answer is {session_answer.answer}. Visited is {session_answer.visited}. Time spent is {session_answer.time_spent} seconds." + log_message = f"Updating session answer for session: {session_id} at position: {position_index}. The answer is {session_answer.answer}. Visited is {session_answer.visited}. Time spent is {session_answer.time_spent} seconds. Marked for review status is {session_answer.marked_for_review}." session_answer = remove_optional_unset_args(session_answer) session_answer = jsonable_encoder(session_answer) diff --git a/app/tests/dummy_data/multiple_question_set_quiz.json b/app/tests/dummy_data/multiple_question_set_quiz.json index 372246ff..cfbe778d 100644 --- a/app/tests/dummy_data/multiple_question_set_quiz.json +++ b/app/tests/dummy_data/multiple_question_set_quiz.json @@ -39,7 +39,7 @@ "instructions": null, "image": { "url": "https://plio-prod-assets.s3.ap-south-1.amazonaws.com/images/afbxudrmbl.png", - "alt_text": "Image" + "alt_text": "Image 1" }, "options": [ { diff --git a/app/tests/test_session_answers.py b/app/tests/test_session_answers.py index 93ba98ef..ad05ddc9 100644 --- a/app/tests/test_session_answers.py +++ b/app/tests/test_session_answers.py @@ -56,6 +56,24 @@ def test_update_session_answer_with_only_visited(self): # ensure that `answer` is not affected assert session_answer["answer"] == self.session_answer["answer"] + def test_update_session_answer_with_only_marked_for_review(self): + new_marked_for_review = True + response = self.client.patch( + f"{session_answers.router.prefix}/{self.session_id}/{self.session_answer_position_index}", + json={"marked_for_review": new_marked_for_review}, + ) + assert response.status_code == 200 + response = self.client.get( + f"{session_answers.router.prefix}/{self.session_id}/{self.session_answer_position_index}" + ) + session_answer = json.loads(response.content) + + # ensure that `marked_for_review` has been updated + assert session_answer["marked_for_review"] == new_marked_for_review + + # ensure that `answer` is not affected + assert session_answer["answer"] == self.session_answer["answer"] + def test_update_session_answers_at_specific_positions(self): # updating all session answers