add error for courses import with invalid account

test plan
 - import a course with an invalid account
 - it should have an error for that line
 - the rest of the import should work

fixes VICE-704

Change-Id: I307488aaad26459e508c2d0a3ac63707ee2b3ea3
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/244305
Reviewed-by: Drake Harper <drake.harper@instructure.com>
QA-Review: Drake Harper <drake.harper@instructure.com>
Product-Review: Drake Harper <drake.harper@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
Rob Orton 2020-08-05 00:33:55 -06:00
parent 2a2227e1b4
commit f66372aab2
2 changed files with 19 additions and 7 deletions

View File

@ -89,6 +89,9 @@ module SIS
account = nil
account = @root_account.all_accounts.where(sis_source_id: account_id).take if account_id.present?
account ||= @root_account.all_accounts.where(sis_source_id: fallback_account_id).take if fallback_account_id.present?
if account_id.present? && !account
raise ImportError, "Account not found \"#{account_id}\" for course #{course_id}"
end
course_account_stuck = course.stuck_sis_fields.include?(:account_id)
unless course_account_stuck
course.account = account if account

View File

@ -25,12 +25,12 @@ describe SIS::CSV::CourseImporter do
it 'should skip bad content' do
before_count = Course.count
importer = process_csv_data(
"course_id,short_name,long_name,account_id,term_id,status",
"C001,Hum101,Humanities,A001,T001,active",
",Hum102,Humanities 2,A001,T001,active",
"C003,Hum102,Humanities 2,A001,T001,inactive",
"C004,,Humanities 2,A001,T001,active",
"C005,Hum102,,A001,T001,active"
"course_id,short_name,long_name,term_id,status",
"C001,Hum101,Humanities,T001,active",
",Hum102,Humanities 2,T001,active",
"C003,Hum102,Humanities 2,T001,inactive",
"C004,,Humanities 2,T001,active",
"C005,Hum102,,T001,active"
)
expect(Course.count).to eq before_count + 1
@ -52,6 +52,15 @@ describe SIS::CSV::CourseImporter do
expect(course.associated_accounts.map(&:id).sort).to eq [@account.id]
end
it "should throw an error when account is not found" do
importer = process_csv_data(
"course_id,short_name,long_name,account_id,term_id,status",
"test_1,TC 101,Test Course 101,VERY_INVALID_ACCOUNT,,active"
)
errors = importer.errors.map { |r| r.last }
expect(errors).to eq ["Account not found \"VERY_INVALID_ACCOUNT\" for course test_1"]
end
it "should support term stickiness" do
process_csv_data_cleanly(
"term_id,name,status,start_date,end_date",
@ -642,7 +651,7 @@ describe SIS::CSV::CourseImporter do
it 'should allow unpublished to be passed for active' do
process_csv_data_cleanly(
"course_id,short_name,long_name,account_id,term_id,status",
"c1,TC 101,Test Course 1,A001,T001,unpublished"
"c1,TC 101,Test Course 1,,T001,unpublished"
)
expect(Course.active.where(sis_source_id: 'c1').take).to be_present
end