2014-06-28 04:33:16 +08:00
|
|
|
# coding: utf-8
|
2012-03-28 22:52:21 +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 ContentMigration do
|
2013-03-15 04:17:43 +08:00
|
|
|
context "#prepare_data" do
|
|
|
|
it "should strip invalid utf8" do
|
|
|
|
data = {
|
|
|
|
'assessment_questions' => [{
|
|
|
|
'question_name' => "hai\xfbabcd"
|
|
|
|
}]
|
|
|
|
}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(ContentMigration.new.prepare_data(data)[:assessment_questions][0][:question_name]).to eq "haiabcd"
|
2013-03-15 04:17:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-03 06:38:05 +08:00
|
|
|
context "import_object?" do
|
2014-06-30 19:34:00 +08:00
|
|
|
before :once do
|
2013-08-08 06:19:48 +08:00
|
|
|
course
|
|
|
|
@cm = ContentMigration.new(context: @course)
|
2012-04-03 06:38: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(@cm.import_object?("content_migrations", CC::CCHelper.create_key(@cm))).to eq true
|
2012-04-03 06:38:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true for everything if 'everything' is selected" do
|
|
|
|
@cm.migration_ids_to_import = {:copy => {:everything => "1"}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@cm.import_object?("content_migrations", CC::CCHelper.create_key(@cm))).to eq true
|
2012-04-03 06:38:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true if there are no copy options" do
|
|
|
|
@cm.migration_ids_to_import = {:copy => {}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@cm.import_object?("content_migrations", CC::CCHelper.create_key(@cm))).to eq true
|
2012-04-03 06:38:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false for nil objects" do
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@cm.import_object?("content_migrations", nil)).to eq false
|
2012-04-03 06:38:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true for all object types if the all_ option is true" do
|
|
|
|
@cm.migration_ids_to_import = {:copy => {:all_content_migrations => "1"}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@cm.import_object?("content_migrations", CC::CCHelper.create_key(@cm))).to eq true
|
2012-04-03 06:38:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false for objects not selected" do
|
|
|
|
@cm.save!
|
|
|
|
@cm.migration_ids_to_import = {:copy => {:all_content_migrations => "0"}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@cm.import_object?("content_migrations", CC::CCHelper.create_key(@cm))).to eq false
|
2012-04-03 06:38:05 +08:00
|
|
|
@cm.migration_ids_to_import = {:copy => {:content_migrations => {}}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@cm.import_object?("content_migrations", CC::CCHelper.create_key(@cm))).to eq false
|
2012-04-03 06:38:05 +08:00
|
|
|
@cm.migration_ids_to_import = {:copy => {:content_migrations => {CC::CCHelper.create_key(@cm) => "0"}}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@cm.import_object?("content_migrations", CC::CCHelper.create_key(@cm))).to eq false
|
2012-04-03 06:38:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true for selected objects" do
|
|
|
|
@cm.save!
|
|
|
|
@cm.migration_ids_to_import = {:copy => {:content_migrations => {CC::CCHelper.create_key(@cm) => "1"}}}
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@cm.import_object?("content_migrations", CC::CCHelper.create_key(@cm))).to eq true
|
2012-04-03 06:38:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2014-02-20 05:07:34 +08:00
|
|
|
|
2013-04-16 22:37:11 +08:00
|
|
|
it "should exclude user-hidden migration plugins" do
|
|
|
|
ab = Canvas::Plugin.find(:academic_benchmark_importer)
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(ContentMigration.migration_plugins(true).include?(ab)).to be_falsey
|
2013-04-16 22:37:11 +08:00
|
|
|
end
|
2012-04-03 06:38:05 +08:00
|
|
|
|
2013-04-10 04:30:41 +08:00
|
|
|
context "zip file import" do
|
2014-04-23 01:55:08 +08:00
|
|
|
def test_zip_import(context)
|
2013-04-10 04:30:41 +08:00
|
|
|
zip_path = File.join(File.dirname(__FILE__) + "/../fixtures/migration/file.zip")
|
2014-04-23 01:55:08 +08:00
|
|
|
cm = ContentMigration.new(:context => context, :user => @user,)
|
2013-04-10 04:30:41 +08:00
|
|
|
cm.migration_type = 'zip_file_importer'
|
2014-04-23 01:55:08 +08:00
|
|
|
cm.migration_settings[:folder_id] = Folder.root_folders(context).first.id
|
2013-04-10 04:30:41 +08:00
|
|
|
cm.save!
|
|
|
|
|
|
|
|
attachment = Attachment.new
|
|
|
|
attachment.context = cm
|
|
|
|
attachment.uploaded_data = File.open(zip_path, 'rb')
|
|
|
|
attachment.filename = 'file.zip'
|
|
|
|
attachment.save!
|
|
|
|
|
|
|
|
cm.attachment = attachment
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(context.reload.attachments.count).to eq 1
|
2014-04-23 01:55:08 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should import into a course" do
|
|
|
|
course_with_teacher
|
|
|
|
test_zip_import(@course)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should import into a user" do
|
|
|
|
user
|
|
|
|
test_zip_import(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should import into a group" do
|
|
|
|
group_with_user
|
|
|
|
test_zip_import(@group)
|
2013-04-10 04:30:41 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-14 04:33:43 +08:00
|
|
|
it "should use url for migration file" do
|
|
|
|
course_with_teacher
|
|
|
|
cm = ContentMigration.new(:context => @course, :user => @user,)
|
|
|
|
cm.migration_type = 'zip_file_importer'
|
|
|
|
cm.migration_settings[:folder_id] = Folder.root_folders(@course).first.id
|
|
|
|
# the mock below should prevent it from actually hitting the url
|
|
|
|
cm.migration_settings[:file_url] = "http://localhost:3000/file.zip"
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
Attachment.any_instance.expects(:clone_url).with(cm.migration_settings[:file_url], false, true, :quota_context => cm.context)
|
|
|
|
|
|
|
|
cm.queue_migration
|
|
|
|
worker = Canvas::Migration::Worker::CCWorker.new
|
|
|
|
worker.perform(cm)
|
|
|
|
end
|
|
|
|
|
2014-05-05 20:23:55 +08:00
|
|
|
context "account-level import" do
|
|
|
|
it "should import question banks from qti migrations" do
|
2014-10-14 10:08:00 +08:00
|
|
|
skip unless Qti.qti_enabled?
|
2014-05-05 20:23:55 +08:00
|
|
|
|
|
|
|
account = Account.create!(:name => 'account')
|
|
|
|
@user = user
|
2014-05-31 02:01:49 +08:00
|
|
|
account.account_users.create!(user: @user)
|
2014-05-05 20:23:55 +08:00
|
|
|
cm = ContentMigration.new(:context => account, :user => @user)
|
|
|
|
cm.migration_type = 'qti_converter'
|
|
|
|
cm.migration_settings['import_immediately'] = true
|
|
|
|
qb_name = 'Import Unfiled Questions Into Me'
|
|
|
|
cm.migration_settings['question_bank_name'] = qb_name
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
package_path = File.join(File.dirname(__FILE__) + "/../fixtures/migration/cc_default_qb_test.zip")
|
|
|
|
attachment = Attachment.new
|
|
|
|
attachment.context = cm
|
|
|
|
attachment.uploaded_data = File.open(package_path, 'rb')
|
|
|
|
attachment.filename = 'file.zip'
|
|
|
|
attachment.save!
|
|
|
|
|
|
|
|
cm.attachment = attachment
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(cm.migration_issues).to be_empty
|
2014-05-05 20:23:55 +08:00
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(account.assessment_question_banks.count).to eq 1
|
2014-05-05 20:23:55 +08:00
|
|
|
bank = account.assessment_question_banks.first
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(bank.title).to eq qb_name
|
2014-05-05 20:23:55 +08:00
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(bank.assessment_questions.count).to eq 1
|
2014-05-05 20:23:55 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should import questions from quizzes into question banks" do
|
2014-10-14 10:08:00 +08:00
|
|
|
skip unless Qti.qti_enabled?
|
2014-05-05 20:23:55 +08:00
|
|
|
|
|
|
|
account = Account.create!(:name => 'account')
|
|
|
|
@user = user
|
2014-05-31 02:01:49 +08:00
|
|
|
account.account_users.create!(user: @user)
|
2014-05-05 20:23:55 +08:00
|
|
|
cm = ContentMigration.new(:context => account, :user => @user)
|
|
|
|
cm.migration_type = 'qti_converter'
|
|
|
|
cm.migration_settings['import_immediately'] = true
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
package_path = File.join(File.dirname(__FILE__) + "/../fixtures/migration/quiz_qti.zip")
|
|
|
|
attachment = Attachment.new
|
|
|
|
attachment.context = cm
|
|
|
|
attachment.uploaded_data = File.open(package_path, 'rb')
|
|
|
|
attachment.filename = 'file.zip'
|
|
|
|
attachment.save!
|
|
|
|
|
|
|
|
cm.attachment = attachment
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(cm.migration_issues).to be_empty
|
2014-09-25 04:27:03 +08:00
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(account.assessment_question_banks.count).to eq 1
|
2014-09-25 04:27:03 +08:00
|
|
|
bank = account.assessment_question_banks.first
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(bank.title).to eq "Unnamed Quiz"
|
2014-09-25 04:27:03 +08:00
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(bank.assessment_questions.count).to eq 1
|
2014-09-25 04:27:03 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not re-use the question_bank without overwrite_quizzes" do
|
2014-10-14 10:08:00 +08:00
|
|
|
skip unless Qti.qti_enabled?
|
2014-09-25 04:27:03 +08:00
|
|
|
|
|
|
|
account = Account.create!(:name => 'account')
|
|
|
|
@user = user
|
|
|
|
account.account_users.create!(user: @user)
|
|
|
|
cm = ContentMigration.new(:context => account, :user => @user)
|
|
|
|
cm.migration_type = 'qti_converter'
|
|
|
|
cm.migration_settings['import_immediately'] = true
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
package_path = File.join(File.dirname(__FILE__) + "/../fixtures/migration/quiz_qti.zip")
|
|
|
|
attachment = Attachment.new
|
|
|
|
attachment.context = cm
|
|
|
|
attachment.uploaded_data = File.open(package_path, 'rb')
|
|
|
|
attachment.filename = 'file.zip'
|
|
|
|
attachment.save!
|
|
|
|
|
|
|
|
cm.attachment = attachment
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
|
|
|
# run again
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(cm.migration_issues).to be_empty
|
2014-09-25 04:27:03 +08:00
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(account.assessment_question_banks.count).to eq 2
|
2014-09-25 04:27:03 +08:00
|
|
|
account.assessment_question_banks.each do |bank|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(bank.title).to eq "Unnamed Quiz"
|
|
|
|
expect(bank.assessment_questions.count).to eq 1
|
2014-09-25 04:27:03 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should re-use the question_bank (and everything else) with overwrite_quizzes" do
|
2014-10-14 10:08:00 +08:00
|
|
|
skip unless Qti.qti_enabled?
|
2014-09-25 04:27:03 +08:00
|
|
|
|
|
|
|
account = Account.create!(:name => 'account')
|
|
|
|
@user = user
|
|
|
|
account.account_users.create!(user: @user)
|
|
|
|
cm = ContentMigration.new(:context => account, :user => @user)
|
|
|
|
cm.migration_type = 'qti_converter'
|
|
|
|
cm.migration_settings['import_immediately'] = true
|
2014-09-26 23:06:42 +08:00
|
|
|
|
|
|
|
# having this set used to always prepend the id, and it would get set it there were any other imported quizzes/questions
|
|
|
|
cm.migration_settings['id_prepender'] = 'thisusedtobreakstuff'
|
2014-09-25 04:27:03 +08:00
|
|
|
cm.save!
|
|
|
|
|
|
|
|
package_path = File.join(File.dirname(__FILE__) + "/../fixtures/migration/quiz_qti.zip")
|
|
|
|
attachment = Attachment.new
|
|
|
|
attachment.context = cm
|
|
|
|
attachment.uploaded_data = File.open(package_path, 'rb')
|
|
|
|
attachment.filename = 'file.zip'
|
|
|
|
attachment.save!
|
|
|
|
|
|
|
|
cm.attachment = attachment
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
2014-09-26 23:06:42 +08:00
|
|
|
cm.migration_settings['overwrite_quizzes'] = true
|
|
|
|
cm.migration_settings['id_prepender'] = 'somethingelse'
|
|
|
|
cm.save!
|
2014-09-25 04:27:03 +08:00
|
|
|
# run again
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(cm.migration_issues).to be_empty
|
2014-05-05 20:23:55 +08:00
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(account.assessment_question_banks.count).to eq 1
|
2014-05-05 20:23:55 +08:00
|
|
|
bank = account.assessment_question_banks.first
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(bank.title).to eq "Unnamed Quiz"
|
2014-05-05 20:23:55 +08:00
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(bank.assessment_questions.count).to eq 1
|
2014-05-05 20:23:55 +08:00
|
|
|
end
|
|
|
|
end
|
2014-07-31 21:14:01 +08:00
|
|
|
|
2015-04-09 00:28:41 +08:00
|
|
|
it "should not overwrite deleted quizzes unless overwrite_quizzes is true" do
|
|
|
|
skip unless Qti.qti_enabled?
|
|
|
|
|
|
|
|
course_with_teacher
|
|
|
|
cm = ContentMigration.new(:context => @course, :user => @teacher)
|
|
|
|
cm.migration_type = 'qti_converter'
|
|
|
|
cm.migration_settings['import_immediately'] = true
|
|
|
|
|
|
|
|
# having this set used to always prepend the id, and it would get set it there were any other imported quizzes/questions
|
|
|
|
cm.migration_settings['id_prepender'] = 'thisusedtobreakstuff'
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
package_path = File.join(File.dirname(__FILE__) + "/../fixtures/migration/quiz_qti.zip")
|
|
|
|
attachment = Attachment.new
|
|
|
|
attachment.context = cm
|
|
|
|
attachment.uploaded_data = File.open(package_path, 'rb')
|
|
|
|
attachment.filename = 'file.zip'
|
|
|
|
attachment.save!
|
|
|
|
|
|
|
|
cm.attachment = attachment
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
|
|
|
expect(@course.quizzes.count).to eq 1
|
|
|
|
orig_quiz = @course.quizzes.first
|
|
|
|
qq = orig_quiz.quiz_questions.first
|
|
|
|
qq.question_data[:question_text] = "boooring"
|
|
|
|
qq.save!
|
|
|
|
orig_quiz.destroy
|
|
|
|
|
|
|
|
cm.migration_settings['id_prepender'] = 'somethingelse'
|
|
|
|
cm.save!
|
|
|
|
# run again, should create a new quiz
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
|
|
|
@course.reload
|
|
|
|
expect(@course.quizzes.count).to eq 2
|
|
|
|
expect(@course.quizzes.active.count).to eq 1
|
|
|
|
|
|
|
|
new_quiz = @course.quizzes.active.first
|
|
|
|
|
|
|
|
cm.migration_settings['overwrite_quizzes'] = true
|
|
|
|
cm.migration_settings['id_prepender'] = 'somethingelse_again'
|
|
|
|
cm.save!
|
|
|
|
# run again, but this time restore the deleted quiz
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
|
|
|
@course.reload
|
|
|
|
expect(@course.quizzes.count).to eq 2
|
|
|
|
expect(@course.quizzes.active.count).to eq 2
|
|
|
|
|
|
|
|
orig_quiz.reload
|
|
|
|
# should overwrite the old quiz question data
|
|
|
|
expect(orig_quiz.quiz_questions.first.question_data[:question_text]).to eq(
|
|
|
|
new_quiz.quiz_questions.first.question_data[:question_text])
|
|
|
|
end
|
|
|
|
|
2014-07-31 21:14:01 +08:00
|
|
|
it "should identify and import compressed tarball archives" do
|
2014-10-14 10:08:00 +08:00
|
|
|
skip unless Qti.qti_enabled?
|
2014-07-31 21:14:01 +08:00
|
|
|
|
|
|
|
course_with_teacher
|
|
|
|
cm = ContentMigration.new(:context => @course, :user => @user)
|
|
|
|
cm.migration_type = 'qti_converter'
|
|
|
|
cm.migration_settings['import_immediately'] = true
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
package_path = File.join(File.dirname(__FILE__) + "/../fixtures/migration/cc_default_qb_test.tar.gz")
|
|
|
|
attachment = Attachment.new
|
|
|
|
attachment.context = cm
|
|
|
|
attachment.uploaded_data = File.open(package_path, 'rb')
|
|
|
|
attachment.filename = 'file.zip'
|
|
|
|
attachment.save!
|
|
|
|
|
|
|
|
cm.attachment = attachment
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(cm.migration_issues).to be_empty
|
2014-07-31 21:14:01 +08:00
|
|
|
|
2014-10-14 10:08:00 +08:00
|
|
|
expect(@course.assessment_question_banks.count).to eq 1
|
2014-07-31 21:14:01 +08:00
|
|
|
end
|
2015-02-09 21:57:24 +08:00
|
|
|
|
|
|
|
it "should try to handle utf-16 encoding errors" do
|
|
|
|
course_with_teacher
|
|
|
|
cm = ContentMigration.new(:context => @course, :user => @user)
|
|
|
|
cm.migration_type = 'canvas_cartridge_importer'
|
|
|
|
cm.migration_settings['import_immediately'] = true
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
package_path = File.join(File.dirname(__FILE__) + "/../fixtures/migration/canvas_cc_utf16_error.zip")
|
|
|
|
attachment = Attachment.new
|
|
|
|
attachment.context = cm
|
|
|
|
attachment.uploaded_data = File.open(package_path, 'rb')
|
|
|
|
attachment.filename = 'file.zip'
|
|
|
|
attachment.save!
|
|
|
|
|
|
|
|
cm.attachment = attachment
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
|
|
|
expect(cm.migration_issues).to be_empty
|
|
|
|
end
|
2015-09-23 01:29:42 +08:00
|
|
|
|
|
|
|
it "should correclty handle media comment resolution in quizzes" do
|
|
|
|
course_with_teacher
|
|
|
|
cm = ContentMigration.new(:context => @course, :user => @user)
|
|
|
|
cm.migration_type = 'canvas_cartridge_importer'
|
|
|
|
cm.migration_settings['import_immediately'] = true
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
package_path = File.join(File.dirname(__FILE__) + "/../fixtures/migration/canvas_quiz_media_comment.zip")
|
|
|
|
attachment = Attachment.new
|
|
|
|
attachment.context = cm
|
|
|
|
attachment.uploaded_data = File.open(package_path, 'rb')
|
|
|
|
attachment.filename = 'file.zip'
|
|
|
|
attachment.save!
|
|
|
|
|
|
|
|
cm.attachment = attachment
|
|
|
|
cm.save!
|
|
|
|
|
|
|
|
cm.queue_migration
|
|
|
|
run_jobs
|
|
|
|
|
|
|
|
expect(cm.migration_issues).to be_empty
|
|
|
|
quiz = @course.quizzes.available.first
|
|
|
|
expect(quiz.quiz_data).to be_present
|
|
|
|
expect(quiz.quiz_data.to_yaml).to include("/media_objects/m-5U5Jww6HL7zG35CgyaYGyA5bhzsremxY")
|
|
|
|
|
|
|
|
qq = quiz.quiz_questions.first
|
|
|
|
expect(qq.question_data).to be_present
|
|
|
|
expect(qq.question_data.to_yaml).to include("/media_objects/m-5U5Jww6HL7zG35CgyaYGyA5bhzsremxY")
|
|
|
|
|
|
|
|
end
|
2015-12-15 02:52:54 +08:00
|
|
|
|
|
|
|
it "expires migration jobs after 48 hours" do
|
|
|
|
course_with_teacher
|
|
|
|
cm = ContentMigration.new(:context => @course, :user => @teacher)
|
|
|
|
cm.migration_type = 'common_cartridge_importer'
|
|
|
|
cm.workflow_state = 'created'
|
|
|
|
cm.save!
|
|
|
|
cm.queue_migration
|
|
|
|
|
|
|
|
Canvas::Migration::Worker::CCWorker.any_instance.expects(:perform).never
|
|
|
|
Timecop.travel(50.hours.from_now) do
|
|
|
|
run_jobs
|
|
|
|
end
|
|
|
|
|
|
|
|
cm.reload
|
|
|
|
expect(cm).to be_failed
|
|
|
|
expect(cm.migration_issues).not_to be_empty
|
|
|
|
expect(cm.migration_issues.last.error_report.message).to include 'job expired'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "expires import jobs after 48 hours" do
|
|
|
|
course_with_teacher
|
|
|
|
cm = ContentMigration.new(:context => @course, :user => @teacher)
|
|
|
|
cm.migration_type = 'common_cartridge_importer'
|
|
|
|
cm.workflow_state = 'exported'
|
|
|
|
cm.save!
|
|
|
|
Canvas::Migration::Worker::CCWorker.expects(:new).never
|
|
|
|
cm.queue_migration
|
|
|
|
|
|
|
|
ContentMigration.any_instance.expects(:import_content).never
|
|
|
|
Timecop.travel(50.hours.from_now) do
|
|
|
|
run_jobs
|
|
|
|
end
|
|
|
|
|
|
|
|
cm.reload
|
|
|
|
expect(cm).to be_failed
|
|
|
|
expect(cm.migration_issues).not_to be_empty
|
|
|
|
expect(cm.migration_issues.last.error_report.message).to include 'job expired'
|
|
|
|
end
|
2012-04-16 22:27:33 +08:00
|
|
|
end
|