spec implement new spec helper
also remove unused spec helpers test plan * specs should pass Change-Id: If95b4da8b6d0f4237d92e489d8c6f0f731560f46 Reviewed-on: https://gerrit.instructure.com/26198 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Rob Orton <rob@instructure.com> Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
parent
b6d1adf13c
commit
9281bb21d8
|
@ -19,6 +19,8 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/report_spec_helper')
|
||||
|
||||
describe "Course Account Reports" do
|
||||
include ReportSpecHelper
|
||||
|
||||
before(:each) do
|
||||
|
||||
Notification.find_or_create_by_name("Report Generated")
|
||||
|
@ -78,7 +80,7 @@ describe "Course Account Reports" do
|
|||
it "should run unpublished courses report on a term" do
|
||||
parameters = {}
|
||||
parameters["enrollment_term_id"] = @default_term.id
|
||||
parsed = ReportSpecHelper.run_report(@account, @report, parameters, 1)
|
||||
parsed = read_report(@report, {params: parameters})
|
||||
|
||||
parsed.should == [[@course3.id.to_s, "SIS_COURSE_ID_3", "SCI101",
|
||||
"Science 101", nil, nil]]
|
||||
|
@ -87,7 +89,7 @@ describe "Course Account Reports" do
|
|||
end
|
||||
|
||||
it "should run unpublished courses report on sub account" do
|
||||
parsed = ReportSpecHelper.run_report(@sub_account, @report, {}, 1)
|
||||
parsed = read_report(@report, {account: @sub_account})
|
||||
|
||||
parsed.should == [[@course1.id.to_s, "SIS_COURSE_ID_1", "ENG101",
|
||||
"English 101", @course1.start_at.iso8601,
|
||||
|
@ -96,7 +98,7 @@ describe "Course Account Reports" do
|
|||
end
|
||||
|
||||
it "should run unpublished courses report" do
|
||||
parsed = ReportSpecHelper.run_report(@account, @report, {}, 1)
|
||||
parsed = read_report(@report, {order: 1})
|
||||
parsed.should == [[@course1.id.to_s, "SIS_COURSE_ID_1", "ENG101",
|
||||
"English 101", @course1.start_at.iso8601,
|
||||
@course1.conclude_at.iso8601],
|
||||
|
@ -115,7 +117,7 @@ describe "Course Account Reports" do
|
|||
@course1.destroy
|
||||
parameters = {}
|
||||
parameters["enrollment_term_id"] = @default_term.id
|
||||
parsed = ReportSpecHelper.run_report(@account, @report, parameters, 1)
|
||||
parsed = read_report(@report,{params: parameters})
|
||||
|
||||
parsed[0].should == [@course2.id.to_s, "SIS_COURSE_ID_2", "MAT101",
|
||||
"Math 101", nil, nil]
|
||||
|
@ -124,7 +126,7 @@ describe "Course Account Reports" do
|
|||
|
||||
it "should run recently deleted courses report on sub account" do
|
||||
@course1.destroy
|
||||
parsed = ReportSpecHelper.run_report(@sub_account, @report, {}, 1)
|
||||
parsed = read_report(@report, {account: @sub_account})
|
||||
|
||||
parsed[0].should == [@course1.id.to_s, "SIS_COURSE_ID_1", "ENG101",
|
||||
"English 101", @course1.start_at.iso8601,
|
||||
|
@ -134,7 +136,7 @@ describe "Course Account Reports" do
|
|||
|
||||
it "should run recently deleted courses report" do
|
||||
@course1.destroy
|
||||
parsed = ReportSpecHelper.run_report(@account, @report, {}, 1)
|
||||
parsed = read_report(@report, {order: 1})
|
||||
parsed.length.should == 2
|
||||
|
||||
parsed[0].should == [@course1.id.to_s, "SIS_COURSE_ID_1", "ENG101",
|
||||
|
@ -163,7 +165,7 @@ describe "Course Account Reports" do
|
|||
@assignment.destroy
|
||||
@attachment.destroy
|
||||
|
||||
parsed = ReportSpecHelper.run_report(@account, @type, {}, 3)
|
||||
parsed = read_report(@type, {order: 3})
|
||||
parsed.length.should == 3
|
||||
|
||||
parsed[0].should == [@course1.id.to_s, "SIS_COURSE_ID_1", "ENG101",
|
||||
|
@ -181,7 +183,9 @@ describe "Course Account Reports" do
|
|||
@wiki_page = @course6.wiki.wiki_pages.create(
|
||||
:title => "Some random wiki page",
|
||||
:body => "wiki page content")
|
||||
parsed = ReportSpecHelper.run_report(@account, @type, {}, 3)
|
||||
report = run_report(@type)
|
||||
report.parameters["extra_text"].should == "Term: All Terms;"
|
||||
parsed = parse_report(report)
|
||||
parsed.length.should == 0
|
||||
end
|
||||
|
||||
|
@ -194,7 +198,7 @@ describe "Course Account Reports" do
|
|||
@course6.save
|
||||
parameters = {}
|
||||
parameters["enrollment_term_id"] = @term1.id
|
||||
parsed = ReportSpecHelper.run_report(@account, @type, parameters, 3)
|
||||
parsed = read_report(@type, {params: parameters})
|
||||
parsed.length.should == 1
|
||||
|
||||
parsed[0].should == [@course6.id.to_s, nil, "THE01",
|
||||
|
@ -210,7 +214,7 @@ describe "Course Account Reports" do
|
|||
@course4.account = sub_account
|
||||
@course4.save
|
||||
@module.destroy
|
||||
parsed = ReportSpecHelper.run_report(sub_account, @type, {}, 3)
|
||||
parsed = read_report(@type, {account: sub_account})
|
||||
parsed.length.should == 1
|
||||
|
||||
parsed[0].should == [@course4.id.to_s, nil, "self",
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/report_spec_helper')
|
||||
|
||||
describe "Default Account Reports" do
|
||||
include ReportSpecHelper
|
||||
|
||||
before(:each) do
|
||||
Notification.find_or_create_by_name("Report Generated")
|
||||
Notification.find_or_create_by_name("Report Generation Failed")
|
||||
|
@ -81,7 +83,7 @@ describe "Default Account Reports" do
|
|||
|
||||
parameters = {}
|
||||
parameters["enrollment_term"] = @term1.id
|
||||
parsed = ReportSpecHelper.run_report(@account, 'grade_export_csv', parameters, 13)
|
||||
parsed = read_report('grade_export_csv', {order: 13, params: parameters})
|
||||
parsed.length.should == 3
|
||||
|
||||
parsed[0].should == ["John St. Clair", @user1.id.to_s, "user_sis_id_01", "English 101", @course1.id.to_s,
|
||||
|
@ -99,7 +101,7 @@ describe "Default Account Reports" do
|
|||
|
||||
parameters = {}
|
||||
parameters["enrollment_term"] = "sis_term_id:fall12"
|
||||
parsed = ReportSpecHelper.run_report(@account, 'grade_export_csv', parameters, 13)
|
||||
parsed = read_report('grade_export_csv', {order: 13, params: parameters})
|
||||
|
||||
parsed[0].should == ["John St. Clair", @user1.id.to_s, "user_sis_id_01", "English 101", @course1.id.to_s,
|
||||
"SIS_COURSE_ID_1", "English 101", @course1.course_sections.first.id.to_s, nil, "Fall",
|
||||
|
@ -114,7 +116,7 @@ describe "Default Account Reports" do
|
|||
|
||||
it "should run grade export with no parameters" do
|
||||
|
||||
parsed = ReportSpecHelper.run_report(@account, 'grade_export_csv', {}, 13)
|
||||
parsed = read_report('grade_export_csv', {order: 13})
|
||||
parsed.length.should == 5
|
||||
|
||||
parsed[0].should == ["John St. Clair", @user1.id.to_s, "user_sis_id_01", "English 101", @course1.id.to_s,
|
||||
|
@ -138,7 +140,7 @@ describe "Default Account Reports" do
|
|||
|
||||
parameters = {}
|
||||
parameters["enrollment_term"] = ""
|
||||
parsed = ReportSpecHelper.run_report(@account, 'grade_export_csv', parameters, 13)
|
||||
parsed = read_report('grade_export_csv', {order: 13, params: parameters})
|
||||
parsed.length.should == 5
|
||||
|
||||
parsed[0].should == ["John St. Clair", @user1.id.to_s, "user_sis_id_01", "English 101", @course1.id.to_s,
|
||||
|
@ -165,7 +167,7 @@ describe "Default Account Reports" do
|
|||
|
||||
parameters = {}
|
||||
parameters["include_deleted"] = true
|
||||
parsed = ReportSpecHelper.run_report(@account, 'grade_export_csv', parameters, 13)
|
||||
parsed = read_report('grade_export_csv', {order: 13, params: parameters})
|
||||
parsed.length.should == 5
|
||||
|
||||
parsed[0].should == ["John St. Clair", @user1.id.to_s, "user_sis_id_01", "English 101", @course1.id.to_s,
|
||||
|
@ -191,7 +193,7 @@ describe "Default Account Reports" do
|
|||
@course2.save!
|
||||
|
||||
parameters = {}
|
||||
parsed = ReportSpecHelper.run_report(sub_account, 'grade_export_csv', parameters, 13)
|
||||
parsed = read_report('grade_export_csv', {order: 13, account: sub_account, params: parameters})
|
||||
parsed.length.should == 2
|
||||
|
||||
parsed[0].should == ["Michael Bolton", @user2.id.to_s, "user_sis_id_02", "Math 101", @course2.id.to_s,
|
||||
|
@ -203,7 +205,4 @@ describe "Default Account Reports" do
|
|||
end
|
||||
end
|
||||
|
||||
it "should find the default module and configured reports" do
|
||||
ReportSpecHelper.find_account_module_and_reports('default')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/report_spec_helper')
|
||||
|
||||
describe "Outcom Reports" do
|
||||
include ReportSpecHelper
|
||||
|
||||
before(:each) do
|
||||
Notification.find_or_create_by_name("Report Generated")
|
||||
Notification.find_or_create_by_name("Report Generation Failed")
|
||||
|
@ -99,19 +101,19 @@ describe "Outcom Reports" do
|
|||
|
||||
it "should run the Student Competency report" do
|
||||
|
||||
parsed = ReportSpecHelper.run_report(@account, @type, {}, 1)
|
||||
parsed = read_report(@type)
|
||||
|
||||
parsed[0][0].should == @user1.sortable_name
|
||||
parsed[0][1].should == @user1.id.to_s
|
||||
parsed[0][2].should == "user_sis_id_01"
|
||||
parsed[0][0].should == @user2.sortable_name
|
||||
parsed[0][1].should == @user2.id.to_s
|
||||
parsed[0][2].should == "user_sis_id_02"
|
||||
parsed[0][3].should == @assignment.title
|
||||
parsed[0][4].should == @assignment.id.to_s
|
||||
parsed[0][5].should == @submission.submitted_at.iso8601
|
||||
parsed[0][6].should == @submission.grade.to_s
|
||||
parsed[0][5].should == nil
|
||||
parsed[0][6].should == nil
|
||||
parsed[0][7].should == @outcome.short_description
|
||||
parsed[0][8].should == @outcome.id.to_s
|
||||
parsed[0][9].should == '1'
|
||||
parsed[0][10].should == '2'
|
||||
parsed[0][9].should == nil
|
||||
parsed[0][10].should == nil
|
||||
parsed[0][11].should == @course1.name
|
||||
parsed[0][12].should == @course1.id.to_s
|
||||
parsed[0][13].should == @course1.sis_source_id
|
||||
|
@ -120,17 +122,17 @@ describe "Outcom Reports" do
|
|||
parsed[0][16].should == @section.sis_source_id
|
||||
parsed[0][17].should == "https://#{HostUrl.context_host(@course1)}/courses/#{@course1.id}/assignments/#{@assignment.id}"
|
||||
|
||||
parsed[1][0].should == @user2.sortable_name
|
||||
parsed[1][1].should == @user2.id.to_s
|
||||
parsed[1][2].should == "user_sis_id_02"
|
||||
parsed[1][0].should == @user1.sortable_name
|
||||
parsed[1][1].should == @user1.id.to_s
|
||||
parsed[1][2].should == "user_sis_id_01"
|
||||
parsed[1][3].should == @assignment.title
|
||||
parsed[1][4].should == @assignment.id.to_s
|
||||
parsed[1][5].should == nil
|
||||
parsed[1][6].should == nil
|
||||
parsed[1][5].should == @submission.submitted_at.iso8601
|
||||
parsed[1][6].should == @submission.grade.to_s
|
||||
parsed[1][7].should == @outcome.short_description
|
||||
parsed[1][8].should == @outcome.id.to_s
|
||||
parsed[1][9].should == nil
|
||||
parsed[1][10].should == nil
|
||||
parsed[1][9].should == '1'
|
||||
parsed[1][10].should == '2'
|
||||
parsed[1][11].should == @course1.name
|
||||
parsed[1][12].should == @course1.id.to_s
|
||||
parsed[1][13].should == @course1.sis_source_id
|
||||
|
@ -151,7 +153,7 @@ describe "Outcom Reports" do
|
|||
|
||||
parameters = {}
|
||||
parameters["enrollment_term"] = @term1.id
|
||||
parsed = ReportSpecHelper.run_report(@account, @type, parameters)
|
||||
parsed = read_report(@type, {params: parameters})
|
||||
parsed[0].should == ["No outcomes found"]
|
||||
parsed.length.should == 1
|
||||
|
||||
|
@ -161,7 +163,7 @@ describe "Outcom Reports" do
|
|||
sub_account = Account.create(:parent_account => @account, :name => 'English')
|
||||
|
||||
parameters = {}
|
||||
parsed = ReportSpecHelper.run_report(sub_account, @type, parameters)
|
||||
parsed = read_report(@type, {params: parameters, account: sub_account})
|
||||
parsed[0].should == ["No outcomes found"]
|
||||
parsed.length.should == 1
|
||||
|
||||
|
@ -177,8 +179,8 @@ describe "Outcom Reports" do
|
|||
outcome_group.add_outcome(@outcome)
|
||||
|
||||
param = {}
|
||||
parsed = ReportSpecHelper.run_report(sub_account, @type, param, 1)
|
||||
parsed[0].should == [@user1.sortable_name, @user1.id.to_s, "user_sis_id_01",
|
||||
parsed = read_report(@type, {params: param, account: sub_account})
|
||||
parsed[1].should == [@user1.sortable_name, @user1.id.to_s, "user_sis_id_01",
|
||||
@assignment.title, @assignment.id.to_s,
|
||||
@submission.submitted_at.iso8601, @submission.grade.to_s,
|
||||
@outcome.short_description, @outcome.id.to_s, '1', '2',
|
||||
|
@ -186,7 +188,7 @@ describe "Outcom Reports" do
|
|||
@section.name, @section.id.to_s, @section.sis_source_id,
|
||||
"https://#{HostUrl.context_host(@course1)}/courses/#{@course1.id}/assignments/#{@assignment.id}"]
|
||||
|
||||
parsed[1].should == [@user2.sortable_name, @user2.id.to_s, "user_sis_id_02",
|
||||
parsed[0].should == [@user2.sortable_name, @user2.id.to_s, "user_sis_id_02",
|
||||
@assignment.title, @assignment.id.to_s, nil, nil,
|
||||
@outcome.short_description, @outcome.id.to_s, nil, nil,
|
||||
@course1.name, @course1.id.to_s, @course1.sis_source_id,
|
||||
|
@ -201,9 +203,9 @@ describe "Outcom Reports" do
|
|||
|
||||
param = {}
|
||||
param["include_deleted"] = true
|
||||
parsed = ReportSpecHelper.run_report(@account, @type, param, 1)
|
||||
parsed = read_report(@type, {params: param})
|
||||
|
||||
parsed[0].should == [@user1.sortable_name, @user1.id.to_s, "user_sis_id_01",
|
||||
parsed[1].should == [@user1.sortable_name, @user1.id.to_s, "user_sis_id_01",
|
||||
@assignment.title, @assignment.id.to_s,
|
||||
@submission.submitted_at.iso8601, @submission.grade.to_s,
|
||||
@outcome.short_description, @outcome.id.to_s, '1', '2',
|
||||
|
@ -211,7 +213,7 @@ describe "Outcom Reports" do
|
|||
@section.name, @section.id.to_s, @section.sis_source_id,
|
||||
"https://#{HostUrl.context_host(@course1)}/courses/#{@course1.id}/assignments/#{@assignment.id}"]
|
||||
|
||||
parsed[1].should == [@user2.sortable_name, @user2.id.to_s, "user_sis_id_02",
|
||||
parsed[0].should == [@user2.sortable_name, @user2.id.to_s, "user_sis_id_02",
|
||||
@assignment.title, @assignment.id.to_s, nil, nil,
|
||||
@outcome.short_description, @outcome.id.to_s, nil, nil,
|
||||
@course1.name, @course1.id.to_s, @course1.sis_source_id,
|
||||
|
@ -231,7 +233,7 @@ describe "Outcom Reports" do
|
|||
lor.score = @submission.score
|
||||
lor.save!
|
||||
|
||||
parsed = ReportSpecHelper.run_report(@account, @type, {}, 1)
|
||||
parsed = read_report(@type)
|
||||
parsed.length.should == 2
|
||||
end
|
||||
end
|
||||
|
@ -242,7 +244,7 @@ describe "Outcom Reports" do
|
|||
end
|
||||
|
||||
it "should run the outcome result report" do
|
||||
parsed = ReportSpecHelper.run_report(@account, @type, {}, 1)
|
||||
parsed = read_report(@type)
|
||||
|
||||
parsed[0][0].should == @user1.sortable_name
|
||||
parsed[0][1].should == @user1.id.to_s
|
||||
|
@ -286,22 +288,40 @@ describe "Outcom Reports" do
|
|||
outcome.reload
|
||||
outcome_group.add_outcome(outcome)
|
||||
|
||||
parsed = ReportSpecHelper.run_report(@account, @type, {}, [1, 13])
|
||||
parsed = read_report(@type, {order: [0, 13]})
|
||||
|
||||
parsed[0][0].should == @user1.sortable_name
|
||||
parsed[0][1].should == @user1.id.to_s
|
||||
parsed[0][2].should == "user_sis_id_01"
|
||||
parsed[0][3].should == @assignment.title
|
||||
parsed[0][4].should == @assignment.id.to_s
|
||||
parsed[0][5].should == 'assignment'
|
||||
parsed[0][6].should == @submission.submitted_at.iso8601
|
||||
parsed[0][7].should == @submission.grade.to_s
|
||||
parsed[0][8].should == @outcome.short_description
|
||||
parsed[0][9].should == @outcome.id.to_s
|
||||
parsed[2][0].should == @user1.sortable_name
|
||||
parsed[2][1].should == @user1.id.to_s
|
||||
parsed[2][2].should == "user_sis_id_01"
|
||||
parsed[2][3].should == @assignment.title
|
||||
parsed[2][4].should == @assignment.id.to_s
|
||||
parsed[2][5].should == 'assignment'
|
||||
parsed[2][6].should == @submission.submitted_at.iso8601
|
||||
parsed[2][7].should == @submission.grade.to_s
|
||||
parsed[2][8].should == @outcome.short_description
|
||||
parsed[2][9].should == @outcome.id.to_s
|
||||
parsed[2][10].should == '1'
|
||||
parsed[2][11].should == '2'
|
||||
parsed[2][12].should == nil
|
||||
parsed[2][13].should == nil
|
||||
parsed[2][14].should == @course1.name
|
||||
parsed[2][15].should == @course1.id.to_s
|
||||
parsed[2][16].should == @course1.sis_source_id
|
||||
|
||||
parsed[0][0].should == @user2.sortable_name
|
||||
parsed[0][1].should == @user2.id.to_s
|
||||
parsed[0][2].should == "user_sis_id_02"
|
||||
parsed[0][3].should == quiz.title
|
||||
parsed[0][4].should == quiz.id.to_s
|
||||
parsed[0][5].should == 'quiz'
|
||||
parsed[0][6].should == sub.finished_at.iso8601
|
||||
parsed[0][7].should == sub.score.to_s
|
||||
parsed[0][8].should == outcome.short_description
|
||||
parsed[0][9].should == outcome.id.to_s
|
||||
parsed[0][10].should == '1'
|
||||
parsed[0][11].should == '2'
|
||||
parsed[0][12].should == nil
|
||||
parsed[0][13].should == nil
|
||||
parsed[0][11].should == '1'
|
||||
parsed[0][12].should == 'question 1'
|
||||
parsed[0][13].should == q1.assessment_question.id.to_s
|
||||
parsed[0][14].should == @course1.name
|
||||
parsed[0][15].should == @course1.id.to_s
|
||||
parsed[0][16].should == @course1.sis_source_id
|
||||
|
@ -317,31 +337,13 @@ describe "Outcom Reports" do
|
|||
parsed[1][8].should == outcome.short_description
|
||||
parsed[1][9].should == outcome.id.to_s
|
||||
parsed[1][10].should == '1'
|
||||
parsed[1][11].should == '1'
|
||||
parsed[1][12].should == 'question 1'
|
||||
parsed[1][13].should == q1.assessment_question.id.to_s
|
||||
parsed[1][11].should == '0'
|
||||
parsed[1][12].should == 'question 2'
|
||||
parsed[1][13].should == q2.assessment_question.id.to_s
|
||||
parsed[1][14].should == @course1.name
|
||||
parsed[1][15].should == @course1.id.to_s
|
||||
parsed[1][16].should == @course1.sis_source_id
|
||||
|
||||
parsed[2][0].should == @user2.sortable_name
|
||||
parsed[2][1].should == @user2.id.to_s
|
||||
parsed[2][2].should == "user_sis_id_02"
|
||||
parsed[2][3].should == quiz.title
|
||||
parsed[2][4].should == quiz.id.to_s
|
||||
parsed[2][5].should == 'quiz'
|
||||
parsed[2][6].should == sub.finished_at.iso8601
|
||||
parsed[2][7].should == sub.score.to_s
|
||||
parsed[2][8].should == outcome.short_description
|
||||
parsed[2][9].should == outcome.id.to_s
|
||||
parsed[2][10].should == '1'
|
||||
parsed[2][11].should == '0'
|
||||
parsed[2][12].should == 'question 2'
|
||||
parsed[2][13].should == q2.assessment_question.id.to_s
|
||||
parsed[2][14].should == @course1.name
|
||||
parsed[2][15].should == @course1.id.to_s
|
||||
parsed[2][16].should == @course1.sis_source_id
|
||||
|
||||
parsed.length.should == 3
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,12 +19,6 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../../../../spec/spec_helper')
|
||||
|
||||
module ReportSpecHelper
|
||||
def self.find_account_module_and_reports(account_id)
|
||||
Canvas::AccountReports::REPORTS.each do |(report_name, details)|
|
||||
details[:proc].should_not == nil
|
||||
end
|
||||
end
|
||||
|
||||
def read_report(type = @type, options = {})
|
||||
account_report = run_report(type, options)
|
||||
parse_report(account_report, options)
|
||||
|
@ -68,37 +62,4 @@ module ReportSpecHelper
|
|||
all_parsed
|
||||
end
|
||||
|
||||
def report(type = @type, options = {})
|
||||
account = options[:account] || @account
|
||||
parameters = options[:params] || {}
|
||||
account_report = AccountReport.new(:user => @admin || user,
|
||||
:account => account,
|
||||
:report_type => type)
|
||||
account_report.parameters = {}
|
||||
account_report.parameters = parameters
|
||||
account_report.save
|
||||
Canvas::AccountReports.for_account(account)[type][:proc].call(account_report)
|
||||
parse_report(account_report, options)
|
||||
end
|
||||
|
||||
def self.run_report(account, report_type, parameters = {}, sort_column_or_columns = [0, 1], headers = false, col_sep = ',')
|
||||
sort_columns = Array(sort_column_or_columns)
|
||||
account_report = AccountReport.new(:user => account_admin_user(account: account), :account => account, :report_type => report_type)
|
||||
account_report.parameters = {}
|
||||
account_report.parameters = parameters
|
||||
account_report.save!
|
||||
csv_report = Canvas::AccountReports.for_account(account)[report_type][:proc].call(account_report)
|
||||
row_range = headers ? (0..-1) : (1..-1)
|
||||
if csv_report.is_a? Hash
|
||||
csv_report.inject({}) do |result, (key, csv)|
|
||||
all_parsed = CSV.parse(csv).to_a
|
||||
all_parsed[row_range].sort_by { |r| r.values_at(*sort_columns).join }
|
||||
result[key] = all_parsed
|
||||
result
|
||||
end
|
||||
else
|
||||
all_parsed = CSV.parse(account_report.attachment.open, {:col_sep => col_sep}).to_a
|
||||
all_parsed[row_range].sort_by { |r| r.values_at(*sort_columns).join }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/report_spec_helper')
|
||||
|
||||
describe 'Student reports' do
|
||||
include ReportSpecHelper
|
||||
|
||||
before do
|
||||
Notification.find_or_create_by_name('Report Generated')
|
||||
Notification.find_or_create_by_name('Report Generation Failed')
|
||||
|
@ -87,7 +89,7 @@ describe 'Student reports' do
|
|||
it 'should find users that have not submitted anything after a date' do
|
||||
parameters = {}
|
||||
parameters['start_at'] = @start_at2
|
||||
parsed = ReportSpecHelper.run_report(@account,@type,parameters,[1,8])
|
||||
parsed = read_report(@type, {params: parameters, order: [1,8]})
|
||||
parsed.length.should == 4
|
||||
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01',
|
||||
|
@ -112,7 +114,7 @@ describe 'Student reports' do
|
|||
parameters = {}
|
||||
parameters['start_at'] = 45.days.ago
|
||||
parameters['end_at'] = 35.days.ago
|
||||
parsed = ReportSpecHelper.run_report(@account,@type,parameters,[1,8])
|
||||
parsed = read_report(@type, {params: parameters, order: 1})
|
||||
parsed.length.should == 2
|
||||
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01',
|
||||
|
@ -126,7 +128,7 @@ describe 'Student reports' do
|
|||
end
|
||||
|
||||
it 'should find users that have not submitted anything in the past 2 weeks' do
|
||||
parsed = ReportSpecHelper.run_report(@account,@type,{},[1,8])
|
||||
parsed = read_report(@type, {order: [1,8]})
|
||||
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01',
|
||||
@user1.sortable_name, @section1.id.to_s,
|
||||
|
@ -157,7 +159,7 @@ describe 'Student reports' do
|
|||
parameters['start_at'] = @start_at.to_s
|
||||
parameters['end_at'] = @end_at.to_s(:db)
|
||||
parameters['enrollment_term'] = @term1.id
|
||||
parsed = ReportSpecHelper.run_report(@account,@type,parameters,[1,8])
|
||||
parsed = read_report(@type, {params: parameters, order: 1})
|
||||
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01',
|
||||
@user1.sortable_name, @section1.id.to_s,
|
||||
|
@ -171,11 +173,11 @@ describe 'Student reports' do
|
|||
end
|
||||
|
||||
it 'should find users that have not submitted under a sub account' do
|
||||
@sub_account = Account.create(:parent_account => @account,
|
||||
sub_account = Account.create(:parent_account => @account,
|
||||
:name => 'English')
|
||||
@course2.account = @sub_account
|
||||
@course2.account = sub_account
|
||||
@course2.save
|
||||
parsed = ReportSpecHelper.run_report(@sub_account,@type,{},[1,5])
|
||||
parsed = read_report(@type, {account: sub_account, order: 1})
|
||||
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01',
|
||||
@user1.sortable_name, @section2.id.to_s,
|
||||
|
@ -192,7 +194,7 @@ describe 'Student reports' do
|
|||
it 'should find users that have not submitted for one course' do
|
||||
parameters = {}
|
||||
parameters['course'] = @course2.id
|
||||
parsed = ReportSpecHelper.run_report(@account,@type,parameters,[1,5])
|
||||
parsed = read_report(@type, {params: parameters, order: 1})
|
||||
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01',
|
||||
@user1.sortable_name, @section2.id.to_s,
|
||||
|
@ -235,7 +237,7 @@ describe 'Student reports' do
|
|||
it 'should run the zero activity report for course' do
|
||||
param = {}
|
||||
param['course'] = @course1.id
|
||||
parsed = ReportSpecHelper.run_report(@account,@type,param,[1,5])
|
||||
parsed = read_report(@type, {params: param, order: 1})
|
||||
parsed.length.should == 2
|
||||
parsed[0].should == [@user2.id.to_s, 'user_sis_id_02',
|
||||
'Bolton, Michael', @section1.id.to_s,
|
||||
|
@ -256,7 +258,7 @@ describe 'Student reports' do
|
|||
@course1.save
|
||||
param = {}
|
||||
param['enrollment_term'] = 'sis_term_id:fall12'
|
||||
parsed = ReportSpecHelper.run_report(@account,@type,param,[1,5])
|
||||
parsed = read_report(@type, {params: param, order: 1})
|
||||
parsed.length.should == 2
|
||||
parsed[0].should == [@user2.id.to_s, 'user_sis_id_02',
|
||||
'Bolton, Michael', @section1.id.to_s,
|
||||
|
@ -269,7 +271,7 @@ describe 'Student reports' do
|
|||
end
|
||||
|
||||
it 'should run the zero activity report with no params' do
|
||||
parsed = ReportSpecHelper.run_report(@account,@type,{},[1,5])
|
||||
parsed = read_report(@type, {order: 1})
|
||||
parsed.length.should == 3
|
||||
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01',
|
||||
|
@ -291,7 +293,7 @@ describe 'Student reports' do
|
|||
@course2.account = sub_account
|
||||
@course2.save!
|
||||
|
||||
parsed = ReportSpecHelper.run_report(sub_account,@type,{},[1,5])
|
||||
parsed = read_report(@type, {account: sub_account})
|
||||
parsed.length.should == 1
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01',
|
||||
@user1.sortable_name, @section2.id.to_s,
|
||||
|
@ -304,7 +306,7 @@ describe 'Student reports' do
|
|||
update_all(:updated_at => 6.days.ago)
|
||||
parameter = {}
|
||||
parameter['start_at'] = 3.days.ago
|
||||
parsed = ReportSpecHelper.run_report(@account,@type,parameter,[1,5])
|
||||
parsed = read_report(@type, {params: parameter, order: [1,5]})
|
||||
|
||||
parsed.length.should == 4
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01',
|
||||
|
@ -346,7 +348,7 @@ describe 'Student reports' do
|
|||
end
|
||||
|
||||
it 'should run the last user access report' do
|
||||
parsed = ReportSpecHelper.run_report(@account,@type)
|
||||
parsed = read_report(@type, {order: 1})
|
||||
parsed.length.should == 3
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01', 'Clair, John St.', @last_login_time2.iso8601, @p1.current_login_ip]
|
||||
parsed[1].should == [@user2.id.to_s, 'user_sis_id_02', 'Bolton, Michael', @last_login_time.iso8601, @p2.current_login_ip]
|
||||
|
@ -361,7 +363,7 @@ describe 'Student reports' do
|
|||
@course1.save
|
||||
param = {}
|
||||
param['enrollment_term'] = @term1.id
|
||||
parsed = ReportSpecHelper.run_report(@account,@type,param)
|
||||
parsed = read_report(@type, {params: param, order: 1})
|
||||
parsed.length.should == 2
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01', 'Clair, John St.', @last_login_time2.iso8601, @p1.current_login_ip]
|
||||
parsed[1].should == [@user2.id.to_s, 'user_sis_id_02', 'Bolton, Michael', @last_login_time.iso8601, @p2.current_login_ip]
|
||||
|
@ -370,7 +372,7 @@ describe 'Student reports' do
|
|||
it 'should run the last user access report for a course' do
|
||||
param = {}
|
||||
param['course'] = @course.id
|
||||
parsed = ReportSpecHelper.run_report(@account,@type,param)
|
||||
parsed = read_report(@type, {params: param, order: 1})
|
||||
parsed.length.should == 2
|
||||
parsed[0].should == [@user1.id.to_s, 'user_sis_id_01', 'Clair, John St.', @last_login_time2.iso8601, @p1.current_login_ip]
|
||||
parsed[1].should == [@user2.id.to_s, 'user_sis_id_02', 'Bolton, Michael', @last_login_time.iso8601, @p2.current_login_ip]
|
||||
|
|
Loading…
Reference in New Issue