Commit Graph

3 Commits

Author SHA1 Message Date
Ahmad Amireh 20a3562779 Quiz Submission Questions API - Update
This patch provides support for answering Quiz Questions via the API.

closes CNVS-9844, CNVS-10225

TEST PLAN
---- ----

Testing this will be a bit rough because there are many variations and
validations to cover. I'll spare the validations that are covered by
specs from the test plan.

Create a quiz with a question of *each* type except "Text" and "File
Upload". There's a script that creates a quiz with its questions
automatically for you if you don't want to keep doing this manually. See
references.

> Answering Questions

Now you need to answer each question via the API. Most of them vary in
formats, but they are fully specified in the API documentation page
(along with examples). See DOCUMENTATION for more info.

> Flagging Questions

Flagging, and unflagging, a question is the same regardless of its type,
see the "EXAMPLE REQUESTS" section.

> Access Validations

Here are some generic, non-question based validations to verify. You
should NOT be able to answer a question if:

  - the quiz submission has been turned in
  - the quiz submission is overdue
  - the Access Code for the quiz is invalid
  - the IP filter of the Quiz prohibits you from taking the quiz
  - the quiz submission :validation_token is incorrectly specified (ie,
    other students shouldn't be able to answer your questions)
  - you don't specify the latest :attempt, so if the Quiz has multiple
    attempts, and this is your 2nd take, you specify an :attempt of 1,
    3, or anything but 2 should fail
  - NEW: turn quiz into an OQAAT quiz with the "Can't go back" flag on;
    the API should not reject all requests to modify any of the
    questions with a 501 error saying that type of quizzes is not
    supported yet (support will come in CNVS-10224)

> Grading

Also, when you're done answering the questions, take a look at the
grades and make sure everything gets graded just like it does when using
the UI directly.

> Verifying results in the browser

While taking a quiz in the canvas UI, the scripts perform backups in the
background that would overwrite any changes you do via the API. If you
want to verify the changes you make via the API from the UI, you must
append "?backup=false" to the take quiz page URL, something like this:

http://localhost:3000/courses/1/quizzes/1/take?backup=false

Setting that flag will (for now) disable the backup behaviour and should
make things tick.

EXAMPLE REQUESTS
------- --------

Don't forget to set the 'Content-Type' header to 'application/json'!

> Answering a Multiple-Choice question

[PUT] /api/v1/quiz_submissions/:quiz_submission_id/questions/:id

{
  "attempt": 1,
  "validation_token": "1babd0...",
  "answer": 10
}

> Flagging a question

[PUT] /api/v1/quiz_submissions/:quiz_submission_id/questions/:id/flag

{
  "attempt": 1,
  "validation_token": "1babd0..."
}

> Unflagging a question

[PUT] /api/v1/quiz_submissions/:quiz_submission_id/questions/:id/unflag

{
  "attempt": 1,
  "validation_token": "1babd0..."
}

DOCUMENTATION
-------------

Run `bundle exec rake doc:api` and check out the Quiz Submission
Questions page. There's an Appendix that contains example requests for
each question type, as well as the errors produced by each handler.

LINKS
-----

  - bootstrap script:
    https://gist.github.com/amireh/e7e8f835ffbf1d053e4c
  - direct link to the API documentation page:
    http://canvas.docs.kodoware.com/quiz_submission_questions.html

Change-Id: I9a958323ece8854bc21a24c2affd8dc3972e46d5
Reviewed-on: https://gerrit.instructure.com/27206
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Derek DeVries <ddevries@instructure.com>
QA-Review: Myller de Araujo <myller@instructure.com>
Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-01-23 17:49:36 +00:00
Ahmad Amireh 34e58a7354 Quiz Submissions API - Update
This patch ports the ability for teachers to manually grade questions
and add comments on student answers in a quiz submission.

fixes CNVS-8981

TEST PLAN
---- ----

Create a quiz with like two questions, take it as a student and turn it
in.

Endpoint: [PUT]
/api/v1/courses/:course_id/quizzes/:quiz_id/submissions/:id

  1. Modify fudge points (Appendix A) with values like -2.5, 2.5 and:
    a. verify that the score gets adjusted by the fudge amount
    b. verify that the returned "fudge_points" in the output is adjusted
  2. Modify a question score (Appendix B) and:
    a. verify that the total score is adjusted by the correct amount
    b. verify that no other question scores were affected
    c. verify that no comments were affected
  3. Modify a question comment (Appendix C) and:
    a. verify that the total score is not affected
    b. verify that no comments were affected

Tip: to verify stuff like single question scores and comments, just go
to the quiz history page in the web UI and keep refreshing after
sending API requests.

Tip: to get a list of all the question ids, perform a GET request to:
  /api/v1/courses/:course_id/quizzes/:quiz_id/questions

Validations that should hold:

  1. [403] if you're not a teacher
  2. [400] if you specify an invalid attempt
  3. [400] if you specify an attempt that is in progress (not turned in)
  4. [400] if you pass in a funny score, like an array ([ 'hehe' ]) or a
     Hash ({ hello: 'World' })

EXAMPLE REQUESTS
------- --------

Appendix A: Modifying fudge points

{
  "quiz_submissions": [{
    "attempt": 1,
    "fudge_points": VALUE
  }]
}

Appendix B: Modifying a question score

{
  "quiz_submissions": [{
    "attempt": 1,
    "questions": {
      "QUESTION_ID": {
        "score": VALUE
      }
    }
  }]
}

Appendix C: Modifying a question comment

{
  "quiz_submissions": [{
    "attempt": 1,
    "questions": {
      "QUESTION_ID": {
        "comment": "HEHEHEHH"
      }
    }
  }]
}

Change-Id: Id290d4e9f9cb9abcaa00eae857f4b0b7bd06e2ff
Reviewed-on: https://gerrit.instructure.com/28268
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Myller de Araujo <myller@instructure.com>
Reviewed-by: Jason Madsen <jmadsen@instructure.com>
Product-Review: Ahmad Amireh <ahmad@instructure.com>
2014-01-14 08:30:39 +00:00
Ahmad Amireh e3778b529c Quiz Submissions API - Create & Complete
Allows users to start a "quiz-taking session" via the API by creating
a QuizSubmission and later on completing it.

Note that this patch isn't concerned with actually using the QS to
answer questions. That task will be the concern of a new API controller,
QuizSubmissionQuestions.

closes CNVS-8980

TEST PLAN
---- ----

- Create a quiz
- Keep a tab open on the Moderate Quiz (MQ from now) page

Create the quiz submission (ie, start a quiz-taking session):

- Via the API, as a student:
  - POST to /courses/:course_id/quizzes/:quiz_id/submissions
    - Verify that you receive a 200 response with the newly created
      QuizSubmission in the JSON response.
    - Copy the "validation_token" field down, you will need this later
    - Go to the MQ tab and verify that it says the student has started a
      quiz attempt

Complete the quiz submission (ie, finish a quiz-taking session):

- Via the API, as a student, prepare a request with:
  - Method: POST
  - URI: /courses/:course_id/quizzes/:quiz_id/submissions/:id/complete
  - Parameter "validation_token" to what you copied earlier
  - Parameter "attempt" to the current attempt number (starts at 1)
  - Now perform the request, and:
    - Verify that you receive a 200 response
    - Go to the MQ tab and verify that it says the submission has been
      completed (ie, Time column reads "finished in X seconds/minutes")

Other stuff to test (failure scenarios):

The first endpoint (one for starting a quiz attempt) should reject your
request in any of the following cases:

  - The quiz has been locked
  - You are not enrolled in the quiz course
  - The Quiz has an Access Code that you either didn't pass, or passed
    incorrectly
  - The Quiz has an IP filter and you're not in the address range
  - You are already taking the quiz (you've created the submission and
    did not call /complete yet)
  - You are not currently taking the quiz, but you already took it
    earlier and the Quiz does not allow for multiple attempts

The second endpoint (one for completing the quiz attempt) should reject
your request in any of the following cases:

  - You pass in an invalid "validation_token"
  - You already completed that quiz submission (e.g, you called that
    endpoint earlier)

Change-Id: Iff8a47859d7477c210de46ea034544d5e2527fb2
Reviewed-on: https://gerrit.instructure.com/27015
Reviewed-by: Derek DeVries <ddevries@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Myller de Araujo <myller@instructure.com>
Product-Review: Ahmad Amireh <ahmad@instructure.com>
2013-12-19 06:44:28 +00:00