forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0001-unit-tests-for-lit-outcomes-replace-result.patch
159 lines (155 loc) · 5.96 KB
/
0001-unit-tests-for-lit-outcomes-replace-result.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
From 297abf2c313c9553b89bca1c067af000e89f2914 Mon Sep 17 00:00:00 2001
From: Brad Humphrey <[email protected]>
Date: Tue, 17 Sep 2013 12:33:12 -0600
Subject: [PATCH] unit tests for lit outcomes replace result
now we only automatically grade assignments when a grade is passed back,
otherwise we leave them ungraded so that the teacher will be notified.
Change-Id: Ic941c54062685ef1bba0aa860682db40cff952e3
---
lib/basic_lti/basic_outcomes.rb | 13 +++-
spec/lib/basic_lti/basic_outcomes_spec.rb | 111 ++++++++++++++++++++++++++++++
2 files changed, 122 insertions(+), 2 deletions(-)
create mode 100644 spec/lib/basic_lti/basic_outcomes_spec.rb
diff --git a/lib/basic_lti/basic_outcomes.rb b/lib/basic_lti/basic_outcomes.rb
index f16651a..6d66638 100644
--- a/lib/basic_lti/basic_outcomes.rb
+++ b/lib/basic_lti/basic_outcomes.rb
@@ -197,9 +197,18 @@ to because the assignment has no points possible.
self.description = I18n.t('lib.basic_lti.no_points_possible', 'Assignment has no points possible.')
else
if submission_hash[:submission_type] != 'external_tool'
- assignment.submit_homework(user, submission_hash.clone)
+ @submission = assignment.submit_homework(user, submission_hash.clone)
end
- @submission = assignment.grade_student(user, submission_hash).first
+
+ if new_score
+ @submission = assignment.grade_student(user, submission_hash).first
+ end
+
+ unless @submission
+ self.code_major = 'failure'
+ self.description = I18n.t('lib.basic_lti.no_submission_created', 'This outcome request failed to create a new homework submission.')
+ end
+
self.body = "<replaceResultResponse />"
end
diff --git a/spec/lib/basic_lti/basic_outcomes_spec.rb b/spec/lib/basic_lti/basic_outcomes_spec.rb
new file mode 100644
index 0000000..3e9beaf
--- /dev/null
+++ b/spec/lib/basic_lti/basic_outcomes_spec.rb
@@ -0,0 +1,111 @@
+#
+# Copyright (C) 2013 Instructure, Inc.
+#
+# This file is part of Canvas.
+#
+# Canvas is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, version 3 of the License.
+#
+# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Affero General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+
+describe BasicLTI::BasicOutcomes do
+ before(:each) do
+ course_model
+ @root_account = @course.root_account
+ @account = account_model(:root_account => @root_account, :parent_account => @root_account)
+ @course.update_attribute(:account, @account)
+ @user = factory_with_protected_attributes(User, :name => "some user", :workflow_state => "registered")
+ @course.enroll_student(@user)
+ end
+
+ let(:tool) do
+ @course.context_external_tools.create(:name => "a", :url => "http://google.com", :consumer_key => '12345', :shared_secret => 'secret')
+ end
+
+ let(:assignment) do
+ @course.assignments.create!(
+ {
+ title: "value for title",
+ description: "value for description",
+ due_at: Time.now,
+ points_possible: "1.5",
+ submission_types: 'external_tool',
+ external_tool_tag_attributes: {url: tool.url}
+ }
+ )
+ end
+
+ let(:source_id) { BasicLTI::BasicOutcomes.encode_source_id(tool, @course, assignment, @user) }
+
+ let(:xml) do
+ Nokogiri::XML.parse %Q{
+ <?xml version = "1.0" encoding = "UTF-8"?>
+ <imsx_POXEnvelopeRequest xmlns = "http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
+ <imsx_POXHeader>
+ <imsx_POXRequestHeaderInfo>
+ <imsx_version>V1.0</imsx_version>
+ <imsx_messageIdentifier>999999123</imsx_messageIdentifier>
+ </imsx_POXRequestHeaderInfo>
+ </imsx_POXHeader>
+ <imsx_POXBody>
+ <replaceResultRequest>
+ <resultRecord>
+ <sourcedGUID>
+ <sourcedId>#{source_id}</sourcedId>
+ </sourcedGUID>
+ <result>
+ <resultScore>
+ <language>en</language>
+ <textString>0.92</textString>
+ </resultScore>
+ <resultData>
+ <text>text data for canvas submission</text>
+ </resultData>
+ </result>
+ </resultRecord>
+ </replaceResultRequest>
+ </imsx_POXBody>
+ </imsx_POXEnvelopeRequest>
+ }
+ end
+
+ describe "#handle_replaceResult" do
+ it "accepts a grade" do
+ xml.css('resultData').remove
+ request = BasicLTI::BasicOutcomes.process_request(tool, xml)
+
+ request.code_major.should == 'success'
+ request.handle_request(tool).should be_true
+ submission = assignment.submissions.where(user_id: @user.id).first
+ submission.grade.should == (assignment.points_possible * 0.92).round(2).to_s
+ end
+
+ it "accepts a result data without grade" do
+ xml.css('resultScore').remove
+ request = BasicLTI::BasicOutcomes.process_request(tool, xml)
+ request.code_major.should == 'success'
+ request.handle_request(tool).should be_true
+ submission = assignment.submissions.where(user_id: @user.id).first
+ submission.body.should == 'text data for canvas submission'
+ submission.grade.should be_nil
+ submission.workflow_state.should == 'submitted'
+ end
+
+ it "fails if neither result data or a grade is sent" do
+ xml.css('resultData').remove
+ xml.css('resultScore').remove
+ request = BasicLTI::BasicOutcomes.process_request(tool, xml)
+ request.code_major.should == 'failure'
+ end
+ end
+end
--
1.8.4