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

fix: Fix autopublish grading by auto grader #1188

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion lib/cadet/jobs/autograder/result_store_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ defmodule Cadet.Autograder.ResultStoreWorker do
assessment = Repo.get(Assessment, submission.assessment_id)
assessment_config = Repo.get_by(AssessmentConfig, id: assessment.config_id)
is_grading_auto_published = assessment_config.is_grading_auto_published
is_manually_graded = assessment_config.is_manually_graded

if Assessments.is_fully_autograded?(submission_id) and is_grading_auto_published do
if Assessments.is_fully_autograded?(submission_id) and is_grading_auto_published and
not is_manually_graded do
Assessments.publish_grading(submission_id)
end

Expand Down
50 changes: 49 additions & 1 deletion test/cadet/jobs/autograder/result_store_worker_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,55 @@ defmodule Cadet.Autograder.ResultStoreWorkerTest do
end

describe "#perform, valid answer_id" do
test "before manual grading and grading auto published", %{answer: answer, results: results} do
test "before manual grading, grading auto published and manual grading required", %{
answer: answer,
results: results
} do
for result <- results do
ResultStoreWorker.perform(%{answer_id: answer.id, result: result})

answer =
Answer
|> join(:inner, [a], q in assoc(a, :question))
|> preload([_, q], question: q)
|> Repo.get(answer.id)

errors_string_keys =
Enum.map(result.result, fn err ->
Enum.reduce(err, %{}, fn {k, v}, acc ->
Map.put(acc, "#{k}", v)
end)
end)

if result.max_score == 0 do
assert answer.xp == 0
else
assert answer.xp ==
Integer.floor_div(
answer.question.max_xp * result.score,
result.max_score
)
end

submission = Repo.get(Submission, answer.submission_id)

assert submission.is_grading_published == false
assert answer.autograding_status == result.status
assert answer.autograding_results == errors_string_keys
end
end

test "before manual grading, grading auto published and manual grading not required", %{
results: results
} do
assessment_config =
insert(:assessment_config, %{is_grading_auto_published: true, is_manually_graded: false})

assessment = insert(:assessment, %{config: assessment_config})
question = insert(:question, %{assessment: assessment})
submission = insert(:submission, %{status: :submitted, assessment: assessment})
answer = insert(:answer, %{question: question, submission: submission})

for result <- results do
ResultStoreWorker.perform(%{answer_id: answer.id, result: result})

Expand Down
Loading