set proglang based on exenv
try to guess exenv based on proglang
This commit is contained in:
@ -23,7 +23,7 @@ module ProformaService
|
|||||||
title: @exercise.title,
|
title: @exercise.title,
|
||||||
description: @exercise.description,
|
description: @exercise.description,
|
||||||
internal_description: nil,
|
internal_description: nil,
|
||||||
# proglang: proglang, where can we get this information?
|
proglang: proglang,
|
||||||
files: task_files,
|
files: task_files,
|
||||||
tests: tests,
|
tests: tests,
|
||||||
uuid: uuid,
|
uuid: uuid,
|
||||||
@ -44,6 +44,12 @@ module ProformaService
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def proglang
|
||||||
|
regex = %r{^openhpi/co_execenv_(?<language>[^:]*):(?<version>[^-]*)(?>-.*)?$}
|
||||||
|
match = regex.match @exercise.execution_environment.docker_image
|
||||||
|
match ? {name: match[:language], version: match[:version]} : nil
|
||||||
|
end
|
||||||
|
|
||||||
def uuid
|
def uuid
|
||||||
@exercise.update(uuid: SecureRandom.uuid) if @exercise.uuid.nil?
|
@exercise.update(uuid: SecureRandom.uuid) if @exercise.uuid.nil?
|
||||||
@exercise.uuid
|
@exercise.uuid
|
||||||
|
@ -26,12 +26,26 @@ module ProformaService
|
|||||||
allow_file_creation: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_file_creation)),
|
allow_file_creation: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_file_creation)),
|
||||||
allow_auto_completion: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_auto_completion)),
|
allow_auto_completion: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_auto_completion)),
|
||||||
expected_difficulty: @task.meta_data[:CodeOcean]&.dig(:expected_difficulty),
|
expected_difficulty: @task.meta_data[:CodeOcean]&.dig(:expected_difficulty),
|
||||||
execution_environment_id: @task.meta_data[:CodeOcean]&.dig(:execution_environment_id),
|
execution_environment_id: execution_environment_id,
|
||||||
|
|
||||||
files: files
|
files: files
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def execution_environment_id
|
||||||
|
from_meta_data = @task.meta_data[:CodeOcean]&.dig(:execution_environment_id)
|
||||||
|
return from_meta_data if from_meta_data
|
||||||
|
return nil unless @task.proglang
|
||||||
|
|
||||||
|
ex_envs_with_name_and_version = ExecutionEnvironment.where('docker_image ilike ?', "%#{@task.proglang[:name]}%#{@task.proglang[:version]}%")
|
||||||
|
return ex_envs_with_name_and_version.first.id if ex_envs_with_name_and_version.any?
|
||||||
|
|
||||||
|
ex_envs_with_name = ExecutionEnvironment.where('docker_image like ?', "%#{@task.proglang[:name]}%")
|
||||||
|
return ex_envs_with_name.first.id if ex_envs_with_name.any?
|
||||||
|
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def string_to_bool(str)
|
def string_to_bool(str)
|
||||||
return true if str == 'true'
|
return true if str == 'true'
|
||||||
return false if str == 'false'
|
return false if str == 'false'
|
||||||
|
@ -19,22 +19,19 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
let(:convert_to_task) { described_class.new(exercise: exercise) }
|
let(:convert_to_task) { described_class.new(exercise: exercise) }
|
||||||
let(:exercise) do
|
let(:exercise) do
|
||||||
create(:dummy,
|
create(:dummy,
|
||||||
|
execution_environment: execution_environment,
|
||||||
instructions: 'instruction',
|
instructions: 'instruction',
|
||||||
uuid: SecureRandom.uuid,
|
uuid: SecureRandom.uuid,
|
||||||
files: files + tests)
|
files: files + tests)
|
||||||
end
|
end
|
||||||
let(:files) { [] }
|
let(:files) { [] }
|
||||||
let(:tests) { [] }
|
let(:tests) { [] }
|
||||||
|
let(:execution_environment) { create(:java) }
|
||||||
|
|
||||||
it 'creates a task with all basic attributes' do
|
it 'creates a task with all basic attributes' do
|
||||||
expect(task).to have_attributes(
|
expect(task).to have_attributes(
|
||||||
title: exercise.title,
|
title: exercise.title,
|
||||||
description: exercise.description,
|
description: exercise.description,
|
||||||
# internal_description: exercise.instructions,
|
|
||||||
# proglang: {
|
|
||||||
# name: exercise.execution_environment.language,
|
|
||||||
# version: exercise.execution_environment.version
|
|
||||||
# },
|
|
||||||
uuid: exercise.uuid,
|
uuid: exercise.uuid,
|
||||||
language: described_class::DEFAULT_LANGUAGE,
|
language: described_class::DEFAULT_LANGUAGE,
|
||||||
meta_data: {
|
meta_data: {
|
||||||
@ -48,13 +45,18 @@ RSpec.describe ProformaService::ConvertExerciseToTask do
|
|||||||
files: {},
|
files: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
# parent_uuid: exercise.clone_relations.first&.origin&.uuid,
|
|
||||||
files: [],
|
files: [],
|
||||||
tests: [],
|
tests: [],
|
||||||
model_solutions: []
|
model_solutions: []
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when exercise has execution_environment with correct docker-image name' do
|
||||||
|
it 'creates a task with the correct proglang attribute' do
|
||||||
|
expect(task).to have_attributes(proglang: {name: 'java', version: '8'})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when exercise has a mainfile' do
|
context 'when exercise has a mainfile' do
|
||||||
let(:files) { [file] }
|
let(:files) { [file] }
|
||||||
let(:file) { build(:file) }
|
let(:file) { build(:file) }
|
||||||
|
@ -32,7 +32,7 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
Proforma::Task.new(
|
Proforma::Task.new(
|
||||||
title: 'title',
|
title: 'title',
|
||||||
description: 'description',
|
description: 'description',
|
||||||
# proglang: {name: 'proglang-name', version: 'proglang-version'},
|
proglang: {name: 'python', version: '3.4'},
|
||||||
uuid: 'uuid',
|
uuid: 'uuid',
|
||||||
parent_uuid: 'parent_uuid',
|
parent_uuid: 'parent_uuid',
|
||||||
language: 'language',
|
language: 'language',
|
||||||
@ -57,7 +57,7 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
allow_file_creation: allow_file_creation,
|
allow_file_creation: allow_file_creation,
|
||||||
allow_auto_completion: allow_auto_completion,
|
allow_auto_completion: allow_auto_completion,
|
||||||
expected_difficulty: expected_difficulty,
|
expected_difficulty: expected_difficulty,
|
||||||
execution_environment_id: execution_environment.id,
|
execution_environment_id: execution_environment&.id,
|
||||||
files: files_meta_data,
|
files: files_meta_data,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -87,6 +87,16 @@ describe ProformaService::ConvertTaskToExercise do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when execution environment is not set in meta_data' do
|
||||||
|
let(:execution_environment) { nil }
|
||||||
|
|
||||||
|
before { create(:python) }
|
||||||
|
|
||||||
|
it 'sets the execution_environment based on proglang name and value' do
|
||||||
|
expect(convert_to_exercise_service).to have_attributes(execution_environment: have_attributes(name: 'Python 3.4'))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when task has a file' do
|
context 'when task has a file' do
|
||||||
let(:files) { [file] }
|
let(:files) { [file] }
|
||||||
let(:file) do
|
let(:file) do
|
||||||
|
Reference in New Issue
Block a user