Fix Submission#retrieve_lti_tii_score to be more robust

Also adds backtrace to TII helper error emails

Fixes CNVS-31702

Test plan:
* Setup TII as an LTI tool
* As a teacher, create a new assignment
* As a student, submit the assignment
* Start rails console
*   a = Assignment.find(<assignment_id>)
*   s = a.submissions.first
*   s.turnitin_data = {
      last_processed_attempt: 1,
      "attachment_42" => {
        status: "error",
        outcome_response: {
          outcomes_tool_placement_url: "https://api.turnitin.com/api/lti/1p0/invalid?lang=en_us",
          paperid: "607954245",
          lis_result_sourcedid: "10-5-42-8-invalid"
        },
        public_error_message: "Turnitin has not returned a score after 11 attempts to retrieve one."
      }
    }
*   s.save
*   s.retrieve_lti_tii_score

It should return nil (and definitely not crash with "undefined method `key?' for 1:Fixnum")

Change-Id: I12929a002b746bdce65373ba23439fa5757e54d2
Reviewed-on: https://gerrit.instructure.com/89865
Reviewed-by: Keith T. Garner <kgarner@instructure.com>
Tested-by: Jenkins
QA-Review: KC Naegle <knaegle@instructure.com>
Product-Review: Keith T. Garner <kgarner@instructure.com>
Product-Review: Neil Gupta <ngupta@instructure.com>
This commit is contained in:
Neil Gupta 2016-09-07 18:10:43 -05:00
parent 96d4ee9af5
commit 94c5ae0267
4 changed files with 16 additions and 9 deletions

View File

@ -469,7 +469,7 @@ class Submission < ActiveRecord::Base
def retrieve_lti_tii_score
if (tool = ContextExternalTool.tool_for_assignment(self.assignment))
turnitin_data.select {|_,v| v.key?(:outcome_response) }.each do |k, v|
turnitin_data.select {|_,v| v.try(:key?, :outcome_response) }.each do |k, v|
Turnitin::OutcomeResponseProcessor.new(tool, self.assignment, self.user, v[:outcome_response].as_json).resubmit(self, k)
end
end

View File

@ -17,7 +17,7 @@ module SupportHelpers
notify "Success", "#{fixer_name} fixed #{prettify_broken_count} in #{Time.now.to_i - @start_time} seconds!"
rescue => error
notify "Error", "#{fixer_name} failed because #{error.try(:message)}"
notify "Error", "#{fixer_name} failed because #{error.try(:message)}<br/><br/>#{error.try(:backtrace).try(:join, "<br/>")}"
raise error
end

View File

@ -33,13 +33,7 @@ describe SupportHelpers::Tii do
it 'emails the caller upon error' do
fixer = SupportHelpers::Tii::Fixer.new('email')
Message.expects(:new).with(
to: 'email',
from: 'tii_script@instructure.com',
subject: 'TurnItIn Fixer Error',
body: "#{fixer.fixer_name} failed because SupportHelpers::Tii::Fixer must implement #fix",
delay_for: 0
)
Message.expects(:new)
Mailer.expects(:create_message)
begin
fixer.monitor_and_fix

View File

@ -553,6 +553,19 @@ describe Submission do
Turnitin::OutcomeResponseProcessor.stubs(:new).returns(outcome_response_processor_mock)
submission.retrieve_lti_tii_score
end
it 'resubmits errored tii attachments even if turnitin_data has non-hash values' do
a = @course.assignments.create!(title: "test",
submission_types: 'external_tool',
external_tool_tag_attributes: {url: tool.url})
submission.assignment = a
submission.turnitin_data = lti_tii_data.merge(last_processed_attempt: 1)
submission.user = @user
outcome_response_processor_mock = mock('outcome_response_processor')
outcome_response_processor_mock.expects(:resubmit).with(submission, "attachment_42")
Turnitin::OutcomeResponseProcessor.stubs(:new).returns(outcome_response_processor_mock)
submission.retrieve_lti_tii_score
end
end
end