Skip to content

Commit

Permalink
Merge pull request #5235 from dodona-edu/fix/pythia-renderer-bug
Browse files Browse the repository at this point in the history
Fix broken pythia submission if data is not present in group
  • Loading branch information
jorg-vr authored Dec 13, 2023
2 parents b3177b8 + 401cef0 commit aab9b02
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/helpers/renderers/pythia_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ def parse
def show_code_tab
return true unless @result[:groups]

@result[:groups].none? { |t| t[:data][:source_annotations] }
@result[:groups].none? { |t| t[:data] && t[:data][:source_annotations] }
end

def tab_content(t, i)
if t[:data][:source_annotations]
if t[:data] && t[:data][:source_annotations]
linting(t[:data][:source_annotations], @code)
else
super
end
end

def diff(t)
if t[:data][:diff]
if t[:data] && t[:data][:diff]
pythia_diff(t[:data][:diff])
else
super
end
end

def test_accepted(t)
if t[:data][:diff]
if t[:data] && t[:data][:diff]
@builder.div(class: 'test-accepted') do
@builder.span(class: 'output') do
html = t[:data][:diff].map do |l|
Expand Down Expand Up @@ -227,7 +227,7 @@ def convert_lint_message(message)
end

def determine_diff_type(test)
if test[:data][:diff]
if test[:data] && test[:data][:diff]
test[:data][:diff].each do |diff_line|
# Not perfect, since there might be html in the diff_line items
return 'unified' if !diff_line[2].nil? && strip_outer_html(diff_line[2]).length >= 55
Expand Down
24 changes: 24 additions & 0 deletions test/controllers/submissions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,28 @@ def expected_score_string(*args)
assert_equal least_recent.id, response.parsed_body.first['id']
assert_equal most_recent.id, response.parsed_body.second['id']
end

test 'rendering pythia submission should not crash' do
stub_git(Judge.any_instance)
judge = create :judge, name: 'pythia', renderer: PythiaRenderer
exercise = create :exercise, judge: judge
submission = create :submission, :wrong, exercise: exercise
submission.result = '{
"accepted": false,
"status": "wrong",
"description": "Onverwachte uitvoer",
"annotations": [],
"groups": [
{
"description": "maximum",
"badgeCount": 6,
"groups": []
}
],
"messages": []
}'
get submission_path(submission)

assert_response :ok
end
end

0 comments on commit aab9b02

Please sign in to comment.