update converters and im-/exporters to accommodate for changes in proforma gem
This commit is contained in:
@ -34,17 +34,37 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
description: exercise.description,
|
||||
uuid: exercise.uuid,
|
||||
language: described_class::DEFAULT_LANGUAGE,
|
||||
meta_data: {
|
||||
CodeOcean: {
|
||||
allow_auto_completion: exercise.allow_auto_completion,
|
||||
allow_file_creation: exercise.allow_file_creation,
|
||||
execution_environment_id: exercise.execution_environment_id,
|
||||
expected_difficulty: exercise.expected_difficulty,
|
||||
hide_file_tree: exercise.hide_file_tree,
|
||||
public: exercise.public,
|
||||
files: {},
|
||||
meta_data:
|
||||
{
|
||||
'@@order' => ['meta-data'], 'meta-data' =>
|
||||
{'@@order' => %w[CodeOcean:public CodeOcean:hide_file_tree CodeOcean:allow_file_creation CodeOcean:allow_auto_completion CodeOcean:expected_difficulty CodeOcean:execution_environment_id CodeOcean:files],
|
||||
'@xmlns' => {'CodeOcean' => 'codeocean.openhpi.de'},
|
||||
'CodeOcean:allow_auto_completion' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => exercise.allow_auto_completion,
|
||||
},
|
||||
'CodeOcean:allow_file_creation' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => exercise.allow_file_creation,
|
||||
},
|
||||
'CodeOcean:execution_environment_id' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => exercise.execution_environment_id,
|
||||
},
|
||||
'CodeOcean:expected_difficulty' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => exercise.expected_difficulty,
|
||||
},
|
||||
'CodeOcean:files' => {'@@order' => []},
|
||||
'CodeOcean:hide_file_tree' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => exercise.hide_file_tree,
|
||||
},
|
||||
'CodeOcean:public' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => exercise.public,
|
||||
}}
|
||||
},
|
||||
},
|
||||
files: [],
|
||||
tests: [],
|
||||
model_solutions: []
|
||||
@ -76,9 +96,17 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
|
||||
it 'adds the file\'s role to the file hash in task-meta_data' do
|
||||
expect(task).to have_attributes(
|
||||
meta_data: {
|
||||
CodeOcean: a_hash_including(files: {"CO-#{file.id}" => {role: 'main_file'}}),
|
||||
}
|
||||
meta_data: a_hash_including(
|
||||
'meta-data' => a_hash_including(
|
||||
'CodeOcean:files' => {
|
||||
'@@order' => ["CodeOcean:CO-#{file.id}"],
|
||||
"CodeOcean:CO-#{file.id}" => {
|
||||
'@@order' => ['CodeOcean:role'],
|
||||
'CodeOcean:role' => {'$1' => 'main_file', '@@order' => ['$1']},
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
@ -104,9 +132,17 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
|
||||
it 'adds the file\'s role to the file hash in task-meta_data' do
|
||||
expect(task).to have_attributes(
|
||||
meta_data: {
|
||||
CodeOcean: a_hash_including(files: {"CO-#{file.id}" => {role: 'regular_file'}}),
|
||||
}
|
||||
meta_data: a_hash_including(
|
||||
'meta-data' => a_hash_including(
|
||||
'CodeOcean:files' => {
|
||||
'@@order' => ["CodeOcean:CO-#{file.id}"],
|
||||
"CodeOcean:CO-#{file.id}" => {
|
||||
'@@order' => ['CodeOcean:role'],
|
||||
'CodeOcean:role' => {'$1' => 'regular_file', '@@order' => ['$1']},
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
@ -190,12 +226,12 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
||||
id: test_file.id,
|
||||
title: test_file.name,
|
||||
files: have(1).item,
|
||||
meta_data: {
|
||||
CodeOcean: {
|
||||
'feedback-message': 'feedback_message',
|
||||
weight: test_file.weight,
|
||||
},
|
||||
}
|
||||
meta_data: a_hash_including(
|
||||
'test-meta-data' => a_hash_including(
|
||||
'CodeOcean:feedback-message' => {'$1' => 'feedback_message', '@@order' => ['$1']},
|
||||
'CodeOcean:weight' => {'$1' => test_file.weight, '@@order' => ['$1']}
|
||||
)
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -79,15 +79,34 @@ RSpec.describe ProformaService::ConvertTaskToExercise do
|
||||
context 'when meta_data is set' do
|
||||
let(:meta_data) do
|
||||
{
|
||||
CodeOcean: {
|
||||
public:,
|
||||
hide_file_tree:,
|
||||
allow_file_creation:,
|
||||
allow_auto_completion:,
|
||||
expected_difficulty:,
|
||||
execution_environment_id: execution_environment&.id,
|
||||
files: files_meta_data,
|
||||
},
|
||||
'@@order' => ['meta-data'], 'meta-data' =>
|
||||
{'@@order' => %w[CodeOcean:public CodeOcean:hide_file_tree CodeOcean:allow_file_creation CodeOcean:allow_auto_completion CodeOcean:expected_difficulty CodeOcean:execution_environment_id CodeOcean:files],
|
||||
'@xmlns' => {'CodeOcean' => 'codeocean.openhpi.de'},
|
||||
'CodeOcean:allow_auto_completion' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => allow_auto_completion,
|
||||
},
|
||||
'CodeOcean:allow_file_creation' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => allow_file_creation,
|
||||
},
|
||||
'CodeOcean:execution_environment_id' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => execution_environment.id,
|
||||
},
|
||||
'CodeOcean:expected_difficulty' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => expected_difficulty,
|
||||
},
|
||||
'CodeOcean:files' => {'@@order' => []},
|
||||
'CodeOcean:hide_file_tree' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => hide_file_tree,
|
||||
},
|
||||
'CodeOcean:public' => {
|
||||
'@@order' => ['$1'],
|
||||
'$1' => public,
|
||||
}}
|
||||
}
|
||||
end
|
||||
let(:files_meta_data) { {} }
|
||||
@ -178,12 +197,22 @@ RSpec.describe ProformaService::ConvertTaskToExercise do
|
||||
context 'when file is a main_file' do
|
||||
let(:meta_data) do
|
||||
{
|
||||
CodeOcean: {
|
||||
files: files_meta_data,
|
||||
'@@order' => ['meta-data'], 'meta-data' => {
|
||||
'@@order' => %w[CodeOcean:files],
|
||||
'@xmlns' => {'CodeOcean' => 'codeocean.openhpi.de'},
|
||||
'CodeOcean:files' => files_meta_data,
|
||||
}
|
||||
}
|
||||
end
|
||||
let(:files_meta_data) do
|
||||
{
|
||||
'@@order' => ["CodeOcean:CO-#{file.id}"],
|
||||
"CodeOcean:CO-#{file.id}" => {
|
||||
'@@order' => ['CodeOcean:role'],
|
||||
'CodeOcean:role' => {'$1' => 'main_file', '@@order' => ['$1']},
|
||||
},
|
||||
}
|
||||
end
|
||||
let(:files_meta_data) { {"CO-#{file.id}".to_sym => {role: 'main_file'}} }
|
||||
|
||||
it 'creates an exercise with a file that has the correct attributes' do
|
||||
expect(convert_to_exercise_service.files.first).to have_attributes(role: 'main_file')
|
||||
@ -331,10 +360,10 @@ RSpec.describe ProformaService::ConvertTaskToExercise do
|
||||
test_type: 'test_type',
|
||||
files: test_files,
|
||||
meta_data: {
|
||||
CodeOcean: {
|
||||
'feedback-message': 'feedback-message',
|
||||
'testing-framework': 'testing-framework',
|
||||
'testing-framework-version': 'testing-framework-version',
|
||||
'test-meta-data' => {
|
||||
'@@order' => %w[CodeOcean:feedback-message CodeOcean:weight],
|
||||
'CodeOcean:feedback-message' => {'$1' => 'feedback-message', '@@order' => ['$1']},
|
||||
'CodeOcean:weight' => {'$1' => '0.7', '@@order' => ['$1']},
|
||||
},
|
||||
}
|
||||
)
|
||||
@ -361,6 +390,7 @@ RSpec.describe ProformaService::ConvertTaskToExercise do
|
||||
it 'creates an exercise with a test with correct attributes' do
|
||||
expect(convert_to_exercise_service.files.find {|file| file.role == 'teacher_defined_test' }).to have_attributes(
|
||||
feedback_message: 'feedback-message',
|
||||
weight: 0.7,
|
||||
content: 'testfile-content',
|
||||
name: 'testfile',
|
||||
role: 'teacher_defined_test',
|
||||
@ -373,12 +403,22 @@ RSpec.describe ProformaService::ConvertTaskToExercise do
|
||||
context 'when test file is a teacher_defined_linter' do
|
||||
let(:meta_data) do
|
||||
{
|
||||
CodeOcean: {
|
||||
files: files_meta_data,
|
||||
'@@order' => ['meta-data'], 'meta-data' => {
|
||||
'@@order' => %w[CodeOcean:files],
|
||||
'@xmlns' => {'CodeOcean' => 'codeocean.openhpi.de'},
|
||||
'CodeOcean:files' => files_meta_data,
|
||||
}
|
||||
}
|
||||
end
|
||||
let(:files_meta_data) do
|
||||
{
|
||||
'@@order' => ["CodeOcean:CO-#{test_file.id}"],
|
||||
"CodeOcean:CO-#{test_file.id}" => {
|
||||
'@@order' => ['CodeOcean:role'],
|
||||
'CodeOcean:role' => {'$1' => 'teacher_defined_linter', '@@order' => ['$1']},
|
||||
},
|
||||
}
|
||||
end
|
||||
let(:files_meta_data) { {"CO-#{test_file.id}".to_sym => {role: 'teacher_defined_linter'}} }
|
||||
|
||||
it 'creates an exercise with a test' do
|
||||
expect(convert_to_exercise_service.files.select {|file| file.role == 'teacher_defined_linter' }).to have(1).item
|
||||
@ -388,16 +428,7 @@ RSpec.describe ProformaService::ConvertTaskToExercise do
|
||||
context 'when task has multiple tests' do
|
||||
let(:tests) { [test, test2] }
|
||||
let(:test2) do
|
||||
ProformaXML::Test.new(
|
||||
files: test_files2,
|
||||
meta_data: {
|
||||
CodeOcean: {
|
||||
'feedback-message': 'feedback-message',
|
||||
'testing-framework': 'testing-framework',
|
||||
'testing-framework-version': 'testing-framework-version',
|
||||
},
|
||||
}
|
||||
)
|
||||
ProformaXML::Test.new(files: test_files2)
|
||||
end
|
||||
let(:test_files2) { [test_file2] }
|
||||
let(:test_file2) do
|
||||
@ -467,14 +498,7 @@ RSpec.describe ProformaService::ConvertTaskToExercise do
|
||||
title: 'title',
|
||||
description: 'description',
|
||||
test_type: 'test_type',
|
||||
files: test_files,
|
||||
meta_data: {
|
||||
CodeOcean: {
|
||||
'feedback-message': 'feedback-message',
|
||||
'testing-framework': 'testing-framework',
|
||||
'testing-framework-version': 'testing-framework-version',
|
||||
},
|
||||
}
|
||||
files: test_files
|
||||
)
|
||||
end
|
||||
let(:test_files) { [test_file] }
|
||||
|
@ -30,7 +30,7 @@ RSpec.describe ProformaService::ExportTask do
|
||||
|
||||
before do
|
||||
allow(ProformaService::ConvertExerciseToTask).to receive(:call).with(exercise:).and_return(task)
|
||||
allow(ProformaXML::Exporter).to receive(:new).with(task:, custom_namespaces: [{prefix: 'CodeOcean', uri: 'codeocean.openhpi.de'}]).and_return(exporter)
|
||||
allow(ProformaXML::Exporter).to receive(:new).with(task:).and_return(exporter)
|
||||
end
|
||||
|
||||
it do
|
||||
|
Reference in New Issue
Block a user