2012-03-26 04:23:05 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2011 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 ContentExport do
|
|
|
|
|
|
|
|
context "export_object?" do
|
2014-06-30 19:34:00 +08:00
|
|
|
before :once do
|
2014-06-02 23:24:19 +08:00
|
|
|
course = Account.default.courses.create!
|
|
|
|
@ce = course.content_exports.create!
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true for everything if there are no copy options" do
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq true
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true for everything if 'everything' is selected" do
|
|
|
|
@ce.selected_content = {:everything => "1"}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq true
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false for nil objects" do
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(nil)).to eq false
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true for all object types if the all_ option is true" do
|
|
|
|
@ce.selected_content = {:all_content_exports => "1"}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq true
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false for objects not selected" do
|
|
|
|
@ce.save!
|
|
|
|
@ce.selected_content = {:all_content_exports => "0"}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq false
|
2012-03-26 04:23:05 +08:00
|
|
|
@ce.selected_content = {:content_exports => {}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq false
|
2012-03-26 04:23:05 +08:00
|
|
|
@ce.selected_content = {:content_exports => {CC::CCHelper.create_key(@ce) => "0"}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq false
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true for selected objects" do
|
|
|
|
@ce.save!
|
|
|
|
@ce.selected_content = {:content_exports => {CC::CCHelper.create_key(@ce) => "1"}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.export_object?(@ce)).to eq true
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
2012-05-24 11:37:28 +08:00
|
|
|
end
|
|
|
|
|
2017-02-15 01:58:57 +08:00
|
|
|
context "Quizzes2 Export" do
|
|
|
|
before :once do
|
2017-03-09 04:04:36 +08:00
|
|
|
course_with_teacher(:active_all => true)
|
|
|
|
quiz = @course.quizzes.create!(:title => 'quiz1')
|
2017-03-03 00:38:59 +08:00
|
|
|
Account.default.context_external_tools.create!(
|
|
|
|
name: 'Quizzes.Next',
|
|
|
|
consumer_key: 'test_key',
|
|
|
|
shared_secret: 'test_secret',
|
|
|
|
tool_id: 'Quizzes 2',
|
|
|
|
url: 'http://example.com/launch'
|
|
|
|
)
|
2017-03-09 04:04:36 +08:00
|
|
|
@ce = @course.content_exports.create!(
|
2017-02-22 05:23:13 +08:00
|
|
|
:export_type => ContentExport::QUIZZES2,
|
2017-03-09 04:04:36 +08:00
|
|
|
:selected_content => quiz.id,
|
|
|
|
:user => @user
|
2017-02-22 05:23:13 +08:00
|
|
|
)
|
2017-02-15 01:58:57 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "changes the workflow_state when :quizzes2_exporter is enabled" do
|
|
|
|
Account.default.enable_feature!(:quizzes2_exporter)
|
|
|
|
expect { @ce.export_without_send_later }.to change { @ce.workflow_state }
|
|
|
|
expect(@ce.workflow_state).to eq "exported"
|
|
|
|
end
|
|
|
|
|
2017-02-22 05:23:13 +08:00
|
|
|
it "fails the content export when :quizzes2_exporter is disabled" do
|
2017-02-15 01:58:57 +08:00
|
|
|
Account.default.disable_feature!(:quizzes2_exporter)
|
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.workflow_state).to eq "created"
|
|
|
|
end
|
2017-03-09 04:04:36 +08:00
|
|
|
|
|
|
|
it "composes the payload with assignment details" do
|
|
|
|
Account.default.enable_feature!(:quizzes2_exporter)
|
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.settings[:quizzes2][:assignment]).not_to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it "composes the payload with qti details" do
|
|
|
|
Account.default.enable_feature!(:quizzes2_exporter)
|
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.settings[:quizzes2][:qti_export][:url]).to eq(@ce.attachment.download_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "completes with export_type of 'quizzes2'" do
|
|
|
|
Account.default.enable_feature!(:quizzes2_exporter)
|
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.export_type).to eq('quizzes2')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'failure cases' do
|
|
|
|
it "fails if the quiz exporter fails" do
|
|
|
|
Account.default.enable_feature!(:quizzes2_exporter)
|
|
|
|
allow_any_instance_of(Exporters::Quizzes2Exporter).to receive(:export).and_raise('fake error')
|
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.workflow_state).to eq "failed"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if the qti exporter fails" do
|
|
|
|
Account.default.enable_feature!(:quizzes2_exporter)
|
|
|
|
allow_any_instance_of(CC::CCExporter).to receive(:export).and_raise('fake error')
|
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.workflow_state).to eq "failed"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not set the status to exported if either exporter is unsuccessful" do
|
|
|
|
Account.default.enable_feature!(:quizzes2_exporter)
|
|
|
|
allow_any_instance_of(CC::CCExporter).to receive(:export).and_return(false)
|
|
|
|
@ce.export_without_send_later
|
|
|
|
expect(@ce.workflow_state).to eq "exporting"
|
|
|
|
end
|
|
|
|
end
|
2017-02-15 01:58:57 +08:00
|
|
|
end
|
|
|
|
|
2012-05-24 11:37:28 +08:00
|
|
|
context "add_item_to_export" do
|
2014-06-30 19:34:00 +08:00
|
|
|
before :once do
|
2014-06-02 23:24:19 +08:00
|
|
|
course = Account.default.courses.create!
|
|
|
|
@ce = course.content_exports.create!
|
2012-05-24 11:37:28 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not add nil" do
|
|
|
|
@ce.add_item_to_export(nil)
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.selected_content).to be_empty
|
2012-05-24 11:37:28 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should only add data model objects" do
|
|
|
|
@ce.add_item_to_export("hi")
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.selected_content).to be_empty
|
2012-03-26 04:23:05 +08:00
|
|
|
|
2012-05-24 11:37:28 +08:00
|
|
|
@ce.selected_content = { :assignments => nil }
|
|
|
|
@ce.save!
|
|
|
|
|
|
|
|
assignment_model
|
|
|
|
@ce.add_item_to_export(@assignment)
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.selected_content[:assignments]).not_to be_empty
|
2012-05-24 11:37:28 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not add objects if everything is already set" do
|
|
|
|
assignment_model
|
|
|
|
@ce.add_item_to_export(@assignment)
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.selected_content).to be_empty
|
2012-05-24 11:37:28 +08:00
|
|
|
|
|
|
|
@ce.selected_content = { :everything => 1 }
|
|
|
|
@ce.save!
|
|
|
|
|
|
|
|
@ce.add_item_to_export(@assignment)
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.selected_content.keys.map(&:to_s)).to eq ["everything"]
|
2012-05-24 11:37:28 +08:00
|
|
|
end
|
2012-03-26 04:23:05 +08:00
|
|
|
end
|
|
|
|
|
2012-05-09 07:08:24 +08:00
|
|
|
context "notifications" do
|
2014-06-30 19:34:00 +08:00
|
|
|
before :once do
|
2012-05-09 07:08:24 +08:00
|
|
|
course_with_teacher(:active_all => true)
|
2014-06-02 23:24:19 +08:00
|
|
|
@ce = @course.content_exports.create! { |ce| ce.user = @user }
|
2012-05-09 07:08:24 +08:00
|
|
|
|
|
|
|
Notification.create!(:name => 'Content Export Finished', :category => 'Migration')
|
|
|
|
Notification.create!(:name => 'Content Export Failed', :category => 'Migration')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should send notifications immediately" do
|
2013-03-20 03:10:46 +08:00
|
|
|
communication_channel_model.confirm!
|
2012-05-09 07:08:24 +08:00
|
|
|
|
|
|
|
['created', 'exporting', 'exported_for_course_copy', 'deleted'].each do |workflow|
|
|
|
|
@ce.workflow_state = workflow
|
|
|
|
expect { @ce.save! }.to change(DelayedMessage, :count).by 0
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.messages_sent['Content Export Finished']).to be_blank
|
|
|
|
expect(@ce.messages_sent['Content Export Failed']).to be_blank
|
2012-05-09 07:08:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
@ce.workflow_state = 'exported'
|
|
|
|
expect { @ce.save! }.to change(DelayedMessage, :count).by 0
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.messages_sent['Content Export Finished']).not_to be_blank
|
2012-05-09 07:08:24 +08:00
|
|
|
|
|
|
|
@ce.workflow_state = 'failed'
|
|
|
|
expect { @ce.save! }.to change(DelayedMessage, :count).by 0
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.messages_sent['Content Export Failed']).not_to be_blank
|
2012-05-09 07:08:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not send emails as part of a content migration (course copy)" do
|
2013-08-08 06:19:48 +08:00
|
|
|
@cm = ContentMigration.new(:user => @user, :copy_options => {:everything => "1"}, :context => @course)
|
2012-05-09 07:08:24 +08:00
|
|
|
@ce.content_migration = @cm
|
|
|
|
@ce.save!
|
|
|
|
|
|
|
|
@ce.workflow_state = 'exported'
|
|
|
|
expect { @ce.save! }.to change(DelayedMessage, :count).by 0
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.messages_sent['Content Export Finished']).to be_blank
|
2012-05-09 07:08:24 +08:00
|
|
|
|
|
|
|
@ce.workflow_state = 'failed'
|
|
|
|
expect { @ce.save! }.to change(DelayedMessage, :count).by 0
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@ce.messages_sent['Content Export Failed']).to be_blank
|
2012-05-09 07:08:24 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|