Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle case where no test groups are runnable by students #7003

Merged
Merged
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Allow instructors to configure an end date until which students can run automated tests (#6992)
- Gave TAs read-only access to starter file information under assignment settings (#6996)
- Allow inactive groups in the submissions table to be toggled for display (#7000)
- Display error message for student-run tests when no test groups are runnable (#7003)

## [v2.4.8]
- Validate user-provided paths (#7025)
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/automated_tests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ def student_interface

def execute_test_run
assignment = Assignment.find(params[:assignment_id])

# If no test groups can be run by students, flash appropriate message and return early
test_group_categories = assignment.test_groups.pluck(:autotest_settings).pluck('category')
student_runnable = test_group_categories.any? { |category| category.include? 'student' }
unless student_runnable
flash_now(:info, I18n.t('automated_tests.no_student_runnable_tests'))
return
end

grouping = current_role.accepted_grouping_for(assignment.id)
grouping.refresh_test_tokens
allowed = flash_allowance(:error, allowance_to(:run_tests?,
Expand Down
1 change: 1 addition & 0 deletions config/locales/views/automated_tests/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ en:
no_autotest_settings: No automated tester settings exist for this course. Please update the automated tester settings and try again.
no_criteria: Unable to find a criterion with name "%{name}".
no_results: No test results to display
no_student_runnable_tests: No tests are available for students to run.
results:
extra_malformed: "Malformed results discarded by server: \n%{extra}\n"
extra_stderr: "Messages on stderr: \n%{extra}\n"
Expand Down
14 changes: 11 additions & 3 deletions spec/controllers/automated_tests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,17 @@
token_start_date: 1.day.ago,
remote_autotest_settings_id: 1)
end

it 'enqueues an AutotestRunJob' do
expect { post_as role, :execute_test_run, params: params }.to have_enqueued_job(AutotestRunJob)
context 'and at least one test-group can be run by students' do
let(:assignment) { create :assignment_with_test_groups_student_runnable } # overwrites current assignment
it 'enqueues an AutotestRunJob' do
expect { post_as role, :execute_test_run, params: params }.to have_enqueued_job(AutotestRunJob)
end
end
context 'and no test-groups can be run by students' do
let(:assignment) { create :assignment_with_test_groups_not_student_runnable }
it 'does not enqueue an AutotestRunJob if NO test-groups can be run by students' do
expect { post_as role, :execute_test_run, params: params }.not_to have_enqueued_job(AutotestRunJob)
end
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/factories/assignments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,17 @@
evaluator.assignment_properties_attributes = properties.merge(evaluator.assignment_properties_attributes)
end
end

factory :assignment_with_test_groups_student_runnable, parent: :assignment do
after(:create) do |a|
create(:test_group_student_runnable, assignment: a)
2.times { create(:test_group, assignment: a) }
end
end

factory :assignment_with_test_groups_not_student_runnable, parent: :assignment do
after(:create) do |a|
3.times { create(:test_group, assignment: a) }
end
end
end
11 changes: 10 additions & 1 deletion spec/factories/test_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
criterion { nil }

after :create do |test_group|
test_group.update!(autotest_settings: { 'extra_info' => { 'test_group_id' => test_group.id } })
test_group.update!(autotest_settings: {
'extra_info' => { 'test_group_id' => test_group.id },
'category' => []
})
end
end

factory :test_group_student_runnable, parent: :test_group do
after :create do |test_group|
test_group.update!(autotest_settings: { 'category' => ['student'] })
end
end
end