support falling back to a fallback account with course sis imports
Change-Id: I368e59b6abf65ed5adce5d75b0e9b066066ece1f Reviewed-on: https://gerrit.instructure.com/4974 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
7b748e51a4
commit
12d9fa334b
|
@ -52,10 +52,11 @@ module SIS
|
||||||
course ||= AbstractCourse.new
|
course ||= AbstractCourse.new
|
||||||
course.enrollment_term = term if term
|
course.enrollment_term = term if term
|
||||||
course.root_account = @root_account
|
course.root_account = @root_account
|
||||||
if row['account_id'].present?
|
|
||||||
account = Account.find_by_root_account_id_and_sis_source_id(@root_account.id, row['account_id'])
|
account = nil
|
||||||
course.account = account if account
|
account = Account.find_by_root_account_id_and_sis_source_id(@root_account.id, row['account_id']) if row['account_id'].present?
|
||||||
end
|
account ||= Account.find_by_root_account_id_and_sis_source_id(@root_account.id, row['fallback_account_id']) if row['fallback_account_id'].present?
|
||||||
|
course.account = account if account
|
||||||
course.account ||= @root_account
|
course.account ||= @root_account
|
||||||
|
|
||||||
# only update the name/short_name on new records, and ones that haven't been changed
|
# only update the name/short_name on new records, and ones that haven't been changed
|
||||||
|
|
|
@ -56,10 +56,11 @@ module SIS
|
||||||
course ||= Course.new
|
course ||= Course.new
|
||||||
course.enrollment_term = term if term
|
course.enrollment_term = term if term
|
||||||
course.root_account = @root_account
|
course.root_account = @root_account
|
||||||
if row['account_id'].present?
|
|
||||||
account = Account.find_by_root_account_id_and_sis_source_id(@root_account.id, row['account_id'])
|
account = nil
|
||||||
course.account = account if account
|
account = Account.find_by_root_account_id_and_sis_source_id(@root_account.id, row['account_id']) if row['account_id'].present?
|
||||||
end
|
account ||= Account.find_by_root_account_id_and_sis_source_id(@root_account.id, row['fallback_account_id']) if row['fallback_account_id'].present?
|
||||||
|
course.account = account if account
|
||||||
course.account ||= @root_account
|
course.account ||= @root_account
|
||||||
|
|
||||||
courses_to_update_associations.add course if course.account_id_changed? || course.root_account_id_changed?
|
courses_to_update_associations.add course if course.account_id_changed? || course.root_account_id_changed?
|
||||||
|
|
|
@ -259,6 +259,25 @@ describe SIS::SisCsv do
|
||||||
c.root_account.should == @account
|
c.root_account.should == @account
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should support falling back to a fallback account if the primary one doesn't exist" do
|
||||||
|
before_count = AbstractCourse.count
|
||||||
|
process_csv_data_cleanly(
|
||||||
|
"account_id,parent_account_id,name,status",
|
||||||
|
"A001,,TestAccount,active"
|
||||||
|
)
|
||||||
|
process_csv_data_cleanly(
|
||||||
|
"abstract_course_id,short_name,long_name,account_id,term_id,status,fallback_account_id",
|
||||||
|
"C001,Hum101,Humanities,NOEXIST,T001,active,A001"
|
||||||
|
)
|
||||||
|
AbstractCourse.count.should == before_count + 1
|
||||||
|
AbstractCourse.last.tap{|c|
|
||||||
|
c.account.should == Account.last
|
||||||
|
c.account.name.should == "TestAccount"
|
||||||
|
c.root_account.should == @account
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "course importing" do
|
context "course importing" do
|
||||||
|
@ -324,6 +343,20 @@ describe SIS::SisCsv do
|
||||||
course.associated_accounts.map(&:id).sort.should == [account.id, @account.id].sort
|
course.associated_accounts.map(&:id).sort.should == [account.id, @account.id].sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should support falling back to a fallback account if the primary one doesn't exist" do
|
||||||
|
process_csv_data_cleanly(
|
||||||
|
"account_id,parent_account_id,name,status",
|
||||||
|
"A001,,Humanities,active"
|
||||||
|
)
|
||||||
|
process_csv_data_cleanly(
|
||||||
|
"course_id,short_name,long_name,account_id,term_id,status,fallback_account_id",
|
||||||
|
"test_1,TC 101,Test Course 101,NOEXIST,,active,A001"
|
||||||
|
)
|
||||||
|
account = @account.sub_accounts.find_by_sis_source_id("A001")
|
||||||
|
course = account.courses.find_by_sis_source_id("test_1")
|
||||||
|
course.account.should == account
|
||||||
|
end
|
||||||
|
|
||||||
it "should rename courses that have not had their name manually changed" do
|
it "should rename courses that have not had their name manually changed" do
|
||||||
process_csv_data(
|
process_csv_data(
|
||||||
"course_id,short_name,long_name,account_id,term_id,status",
|
"course_id,short_name,long_name,account_id,term_id,status",
|
||||||
|
|
Loading…
Reference in New Issue