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

Autotester Token Generation Time #7127

Merged
merged 16 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion app/controllers/automated_tests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,26 @@ def student_interface
@student = current_role
@grouping = @student.accepted_grouping_for(@assignment.id)

unless @grouping.nil?
if @grouping.nil?
@next_token_generation_time = nil
else
@grouping.refresh_test_tokens
@authorized = flash_allowance(:notice,
allowance_to(:run_tests?,
current_role,
context: { assignment: @assignment, grouping: @grouping })).value

if @assignment.enable_student_tests
# Calculate the next token generation time
token_period = @assignment.token_period
last_generated = @grouping.test_runs.first&.created_at || Time.zone.now
@next_token_generation_time = last_generated + token_period.hours
umututku03 marked this conversation as resolved.
Show resolved Hide resolved

# Format the next token generation time for display
@next_token_generation_time = @next_token_generation_time.strftime('%A, %B %d, %Y %I:%M:%S %p %Z')
umututku03 marked this conversation as resolved.
Show resolved Hide resolved
else
@next_token_generation_time = nil
umututku03 marked this conversation as resolved.
Show resolved Hide resolved
end
end

render layout: 'assignment_content'
Expand Down
2 changes: 2 additions & 0 deletions app/models/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Assignment < Assessment
before_save :reset_collection_time
after_create :update_parent_assignment, if: :is_peer_review?

delegate :enable_student_tests, :token_period, to: :assignment_properties
umututku03 marked this conversation as resolved.
Show resolved Hide resolved

# Add assignment_properties to default scope because we almost always want to load an assignment with its properties
default_scope { includes(:assignment_properties) }

Expand Down
11 changes: 9 additions & 2 deletions app/views/automated_tests/student_interface.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<%= javascript_include_tag 'result', nonce: true %>
<%= javascript_include_tag 'Results/main', nonce: true %>

<% if @assignment.enable_student_tests && !@grouping.nil? %>
<% if @assignment.enable_student_tests && @grouping.present? %>
umututku03 marked this conversation as resolved.
Show resolved Hide resolved
<p>
<strong><%= Assignment.human_attribute_name(:token_start_date) %>:</strong>
<%= l(@assignment.token_start_date) %>
</p>

<p>
<strong><%= Assignment.human_attribute_name(:token_end_date) %>:</strong>
<%= l(@assignment.token_end_date) %>
<%= @assignment.token_end_date.present? ? l(@assignment.token_end_date) : '-' %>
umututku03 marked this conversation as resolved.
Show resolved Hide resolved
</p>

<% unless @assignment.unlimited_tokens || @assignment.non_regenerating_tokens %>
Expand All @@ -31,6 +31,13 @@
<% end %>
</p>

<% unless @assignment.unlimited_tokens || @assignment.non_regenerating_tokens %>
umututku03 marked this conversation as resolved.
Show resolved Hide resolved
<p>
<strong><%= t('automated_tests.next_token_generation') %>:</strong>
<%= @next_token_generation_time %>
</p>
<% end %>

<p>
<%= t('automated_tests.need_one_file') %>
</p>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ en:
submission_file:
error:
no_access: 'No access to submission file with id #%{submission_file_id}.'
automated_tests:
next_token_generation: "Next Token Generation Time"
need_one_file: "You must submit at least one file to run tests."
78 changes: 75 additions & 3 deletions spec/controllers/automated_tests_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require 'rails_helper'
umututku03 marked this conversation as resolved.
Show resolved Hide resolved

describe AutomatedTestsController do
include AutomatedTestsHelper

# TODO: add 'role is from a different course' shared tests to each route test below
umututku03 marked this conversation as resolved.
Show resolved Hide resolved
let(:assignment) { create(:assignment) }
let(:params) { { course_id: assignment.course.id, assignment_id: assignment.id } }

Expand Down Expand Up @@ -548,8 +549,79 @@
let(:role) { create(:student) }

context 'GET student_interface' do
before { get_as role, :student_interface, params: params }
# TODO: write tests
let(:assignment) do
create(:assignment,
assignment_properties_attributes: {
enable_student_tests: true,
tokens_per_period: 5,
token_start_date: 1.day.ago,
token_period: 24
})
end
let(:grouping) { create(:grouping, assignment: assignment) }
let(:student) { create(:student) }
let(:role) { student }
let(:params) { { course_id: assignment.course.id, assignment_id: assignment.id } }

before do
allow_any_instance_of(AutotestSetting).to(
umututku03 marked this conversation as resolved.
Show resolved Hide resolved
receive(:send_request!).and_return(OpenStruct.new(body: { api_key: 'someapikey' }.to_json))
)
create(:student_membership, role: student, grouping: grouping, membership_status: 'accepted')
sign_in student
end

context 'when student tests are enabled and the student has a grouping' do
before do
get_as student, :student_interface, params: params
end

it 'should calculate the next token generation time' do
expect(assigns(:next_token_generation_time)).not_to be_nil
umututku03 marked this conversation as resolved.
Show resolved Hide resolved
end

it 'should respond with success' do
expect(response).to have_http_status(:ok)
end

it 'should render the assignment_content layout' do
expect(response).to render_template('layouts/assignment_content')
end
end

context 'when student tests are disabled' do
before do
assignment.assignment_properties.update!(enable_student_tests: false)
get_as student, :student_interface, params: params
end

it 'should not calculate the next token generation time' do
expect(assigns(:next_token_generation_time)).to be_nil
end

it 'should respond with success' do
expect(response).to have_http_status(:ok)
end

it 'should render the assignment_content layout' do
expect(response).to render_template('layouts/assignment_content')
end
end

context 'when the student does not have a grouping' do
before do
grouping.update!(inviter: nil)
get_as student, :student_interface, params: params
end

it 'should respond with success' do
expect(response).to have_http_status(:ok)
end

it 'should render the assignment_content layout' do
expect(response).to render_template('layouts/assignment_content')
end
end
end

context 'POST execute_test_run' do
Expand Down
Loading