Skip to content

Commit

Permalink
quality: add unit test for code submissions with long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ublefo committed Apr 20, 2024
1 parent 9773079 commit cf6a2fa
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/models/task_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'test_helper'
require 'pdf-reader'

#
# Contains tests for Task model objects - not accessed via API
Expand Down Expand Up @@ -362,4 +363,54 @@ def test_ipynb_to_pdf
unit.destroy!
end

def test_code_submission_with_long_lines
unit = FactoryBot.create(:unit, student_count: 1, task_count: 0)
td = TaskDefinition.new({
unit_id: unit.id,
tutorial_stream: unit.tutorial_streams.first,
name: 'Task with super ling lines in code submission',
description: 'Code task',
weighting: 4,
target_grade: 0,
start_date: unit.start_date + 1.week,
target_date: unit.start_date + 2.weeks,
abbreviation: 'Long',
restrict_status_updates: false,
upload_requirements: [ { "key" => 'file0', "name" => 'long.py', "type" => 'code' } ],
plagiarism_warn_pct: 0.8,
is_graded: false,
max_quality_pts: 0
})
td.save!

data_to_post = {
trigger: 'ready_for_feedback'
}

data_to_post = with_file('test_files/submissions/long.py', 'application/json', data_to_post)

project = unit.active_projects.first

add_auth_header_for user: unit.main_convenor_user

post "/api/projects/#{project.id}/task_def_id/#{td.id}/submission", data_to_post

assert_equal 201, last_response.status, last_response_body

# test submission generation
task = project.task_for_task_definition(td)
assert task.convert_submission_to_pdf
path = task.zip_file_path_for_done_task
assert path
assert File.exist? path
assert File.exist? task.final_pdf_path

# ensure the notice is included when rendered files are truncated
reader = PDF::Reader.new(task.final_pdf_path)
assert reader.pages[1].text.include? "This file has additional line breaks applied"

td.destroy
assert_not File.exist? path
unit.destroy!
end
end
3 changes: 3 additions & 0 deletions test_files/submissions/long.py

Large diffs are not rendered by default.

0 comments on commit cf6a2fa

Please sign in to comment.