From 245c3dba8c2f7c11726782fc883fbcf801ba3122 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Wed, 23 Aug 2023 00:10:11 +0200 Subject: [PATCH] Update from proforma to proformaxml --- Gemfile | 3 +- Gemfile.lock | 29 +++++----------- app/controllers/exercises_controller.rb | 4 +-- .../exercise_not_owned.rb | 2 +- .../convert_exercise_to_task.rb | 8 ++--- app/services/proforma_service/export_task.rb | 2 +- app/services/proforma_service/import.rb | 6 ++-- config/initializers/inflections.rb | 1 + spec/controllers/exercises_controller_spec.rb | 4 +-- .../convert_task_to_exercise_spec.rb | 34 +++++++++---------- .../proforma_service/export_task_spec.rb | 6 ++-- spec/services/proforma_service/import_spec.rb | 2 +- 12 files changed, 45 insertions(+), 56 deletions(-) rename app/errors/{proforma => proformaxml}/exercise_not_owned.rb (81%) diff --git a/Gemfile b/Gemfile index 9f1a2f09..3f41314a 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,6 @@ gem 'bcrypt' gem 'bootstrap-will_paginate' gem 'carrierwave' gem 'charlock_holmes', require: 'charlock_holmes/string' -gem 'dachsfisch', github: 'openHPI/dachsfisch' gem 'docker-api', require: 'docker' gem 'eventmachine' gem 'factory_bot_rails' @@ -31,7 +30,7 @@ gem 'net-smtp', require: false gem 'nokogiri' gem 'pagedown-bootstrap-rails' gem 'pg' -gem 'proforma', github: 'openHPI/proforma', tag: 'v0.9.1' +gem 'proformaxml' gem 'prometheus_exporter' gem 'puma' gem 'pundit' diff --git a/Gemfile.lock b/Gemfile.lock index 6a93185f..106f426a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,21 +1,3 @@ -GIT - remote: https://github.com/openHPI/dachsfisch.git - revision: c74d5a3d74685a0838d369fe3dcbbb9166d50a5b - specs: - dachsfisch (0.1.0) - nokogiri (>= 1.14.1, < 2.0.0) - -GIT - remote: https://github.com/openHPI/proforma.git - revision: 10642d8d4ec27e0bdaa27482dac6b6c7e47bc660 - tag: v0.9.1 - specs: - proforma (0.9.1) - activemodel (>= 5.2.3, < 8.0.0) - activesupport (>= 5.2.3, < 8.0.0) - nokogiri (>= 1.10.2, < 2.0.0) - rubyzip (>= 1.2.2, < 3.0.0) - GEM remote: https://rubygems.org/ specs: @@ -134,6 +116,8 @@ GEM crack (0.4.5) rexml crass (1.0.6) + dachsfisch (0.1.0) + nokogiri (>= 1.14.1, < 2.0.0) database_cleaner (2.0.2) database_cleaner-active_record (>= 2, < 3) database_cleaner-active_record (2.1.0) @@ -285,6 +269,12 @@ GEM ast (~> 2.4.1) racc pg (1.5.3) + proformaxml (0.10.0) + activemodel (>= 5.2.3, < 8.0.0) + activesupport (>= 5.2.3, < 8.0.0) + dachsfisch (>= 0.1.0, < 1.0.0) + nokogiri (>= 1.10.2, < 2.0.0) + rubyzip (>= 1.2.2, < 3.0.0) prometheus_exporter (2.0.8) webrick pry (0.14.2) @@ -547,7 +537,6 @@ DEPENDENCIES capybara carrierwave charlock_holmes - dachsfisch! database_cleaner docker-api eventmachine @@ -578,7 +567,7 @@ DEPENDENCIES nyan-cat-formatter pagedown-bootstrap-rails pg - proforma! + proformaxml prometheus_exporter pry-byebug pry-rails diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 3729ec32..32575cfd 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -166,9 +166,9 @@ class ExercisesController < ApplicationController exercise.save! render json: {}, status: :created end - rescue Proforma::ExerciseNotOwned + rescue ProformaXML::ExerciseNotOwned render json: {}, status: :unauthorized - rescue Proforma::ProformaError + rescue ProformaXML::ProformaError render json: t('exercises.import_codeharbor.import_errors.invalid'), status: :bad_request rescue StandardError => e Sentry.capture_exception(e) diff --git a/app/errors/proforma/exercise_not_owned.rb b/app/errors/proformaxml/exercise_not_owned.rb similarity index 81% rename from app/errors/proforma/exercise_not_owned.rb rename to app/errors/proformaxml/exercise_not_owned.rb index afe96364..d27043eb 100644 --- a/app/errors/proforma/exercise_not_owned.rb +++ b/app/errors/proformaxml/exercise_not_owned.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -module Proforma +module ProformaXML class ExerciseNotOwned < StandardError; end end diff --git a/app/services/proforma_service/convert_exercise_to_task.rb b/app/services/proforma_service/convert_exercise_to_task.rb index 76b1c053..571bac7c 100644 --- a/app/services/proforma_service/convert_exercise_to_task.rb +++ b/app/services/proforma_service/convert_exercise_to_task.rb @@ -18,7 +18,7 @@ module ProformaService private def create_task - Proforma::Task.new( + ProformaXML::Task.new( { title: @exercise.title, description: @exercise.description, @@ -57,7 +57,7 @@ module ProformaService def model_solutions @exercise.files.filter {|file| file.role == 'reference_implementation' }.map do |file| - Proforma::ModelSolution.new( + ProformaXML::ModelSolution.new( id: "ms-#{file.id}", files: model_solution_file(file) ) @@ -75,7 +75,7 @@ module ProformaService def tests @exercise.files.filter(&:teacher_defined_assessment?).map do |file| - Proforma::Test.new( + ProformaXML::Test.new( id: file.id, title: file.name, files: test_file(file), @@ -122,7 +122,7 @@ module ProformaService end def task_file(file) - task_file = Proforma::TaskFile.new( + task_file = ProformaXML::TaskFile.new( id: file.id, filename: filename(file), usage_by_lms: file.read_only ? 'display' : 'edit', diff --git a/app/services/proforma_service/export_task.rb b/app/services/proforma_service/export_task.rb index ca97f1c7..467accd0 100644 --- a/app/services/proforma_service/export_task.rb +++ b/app/services/proforma_service/export_task.rb @@ -10,7 +10,7 @@ module ProformaService def execute @task = ConvertExerciseToTask.call(exercise: @exercise) namespaces = [{prefix: 'CodeOcean', uri: 'codeocean.openhpi.de'}] - exporter = Proforma::Exporter.new(task: @task, custom_namespaces: namespaces) + exporter = ProformaXML::Exporter.new(task: @task, custom_namespaces: namespaces) exporter.perform end end diff --git a/app/services/proforma_service/import.rb b/app/services/proforma_service/import.rb index b9598e26..eaefe0dc 100644 --- a/app/services/proforma_service/import.rb +++ b/app/services/proforma_service/import.rb @@ -10,7 +10,7 @@ module ProformaService def execute if single_task? - importer = Proforma::Importer.new(zip: @zip) + importer = ProformaXML::Importer.new(zip: @zip) import_result = importer.perform @task = import_result[:task] @@ -31,7 +31,7 @@ module ProformaService def base_exercise exercise = Exercise.find_by(uuid: @task.uuid) if exercise - raise Proforma::ExerciseNotOwned unless ExercisePolicy.new(@user, exercise).update? + raise ProformaXML::ExerciseNotOwned unless ExercisePolicy.new(@user, exercise).update? exercise else @@ -69,7 +69,7 @@ module ProformaService filenames.any? {|f| f[/\.xml$/] } rescue Zip::Error - raise Proforma::InvalidZip + raise ProformaXML::InvalidZip end end end diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index aff5032b..ada99edc 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -14,4 +14,5 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.acronym 'IO' + inflect.acronym 'ProformaXML' end diff --git a/spec/controllers/exercises_controller_spec.rb b/spec/controllers/exercises_controller_spec.rb index 9cc5b0a5..1383c1be 100644 --- a/spec/controllers/exercises_controller_spec.rb +++ b/spec/controllers/exercises_controller_spec.rb @@ -563,7 +563,7 @@ describe ExercisesController do end context 'when import fails with ProformaError' do - before { allow(ProformaService::Import).to receive(:call).and_raise(Proforma::PreImportValidationError) } + before { allow(ProformaService::Import).to receive(:call).and_raise(ProformaXML::PreImportValidationError) } it 'responds with correct status code' do post_request @@ -572,7 +572,7 @@ describe ExercisesController do end context 'when import fails with ExerciseNotOwned' do - before { allow(ProformaService::Import).to receive(:call).and_raise(Proforma::ExerciseNotOwned) } + before { allow(ProformaService::Import).to receive(:call).and_raise(ProformaXML::ExerciseNotOwned) } it 'responds with correct status code' do post_request diff --git a/spec/services/proforma_service/convert_task_to_exercise_spec.rb b/spec/services/proforma_service/convert_task_to_exercise_spec.rb index e8273cc0..44d4a645 100644 --- a/spec/services/proforma_service/convert_task_to_exercise_spec.rb +++ b/spec/services/proforma_service/convert_task_to_exercise_spec.rb @@ -6,7 +6,7 @@ describe ProformaService::ConvertTaskToExercise do describe '.new' do subject(:convert_to_exercise_service) { described_class.new(task:, user:, exercise:) } - let(:task) { Proforma::Task.new } + let(:task) { ProformaXML::Task.new } let(:user) { build(:teacher) } let(:exercise) { build(:dummy) } @@ -29,7 +29,7 @@ describe ProformaService::ConvertTaskToExercise do before { create(:dot_txt) } let(:task) do - Proforma::Task.new( + ProformaXML::Task.new( title: 'title', description: 'description', proglang: {name: 'python', version: '3.4'}, @@ -123,7 +123,7 @@ describe ProformaService::ConvertTaskToExercise do context 'when task has a file' do let(:files) { [file] } let(:file) do - Proforma::TaskFile.new( + ProformaXML::TaskFile.new( id: 'id', content:, filename:, @@ -232,7 +232,7 @@ describe ProformaService::ConvertTaskToExercise do end context 'when file is a model-solution-placeholder (needed by proforma until issue #5 is resolved)' do - let(:file) { Proforma::TaskFile.new(id: 'ms-placeholder-file') } + let(:file) { ProformaXML::TaskFile.new(id: 'ms-placeholder-file') } it 'leaves exercise_files empty' do expect(convert_to_exercise_service.files).to be_empty @@ -269,14 +269,14 @@ describe ProformaService::ConvertTaskToExercise do context 'when task has a model-solution' do let(:model_solutions) { [model_solution] } let(:model_solution) do - Proforma::ModelSolution.new( + ProformaXML::ModelSolution.new( id: 'ms-id', files: ms_files ) end let(:ms_files) { [ms_file] } let(:ms_file) do - Proforma::TaskFile.new( + ProformaXML::TaskFile.new( id: 'ms-file', content: 'content', filename: 'filename.txt', @@ -296,14 +296,14 @@ describe ProformaService::ConvertTaskToExercise do context 'when task has two model-solutions' do let(:model_solutions) { [model_solution, model_solution2] } let(:model_solution2) do - Proforma::ModelSolution.new( + ProformaXML::ModelSolution.new( id: 'ms-id-2', files: ms_files2 ) end let(:ms_files2) { [ms_file2] } let(:ms_file2) do - Proforma::TaskFile.new( + ProformaXML::TaskFile.new( id: 'ms-file-2', content: 'content', filename: 'filename.txt', @@ -324,7 +324,7 @@ describe ProformaService::ConvertTaskToExercise do context 'when task has a test' do let(:tests) { [test] } let(:test) do - Proforma::Test.new( + ProformaXML::Test.new( id: 'test-id', title: 'title', description: 'description', @@ -342,7 +342,7 @@ describe ProformaService::ConvertTaskToExercise do let(:test_files) { [test_file] } let(:test_file) do - Proforma::TaskFile.new( + ProformaXML::TaskFile.new( id: 'test_file_id', content: 'testfile-content', filename: 'testfile.txt', @@ -388,7 +388,7 @@ describe ProformaService::ConvertTaskToExercise do context 'when task has multiple tests' do let(:tests) { [test, test2] } let(:test2) do - Proforma::Test.new( + ProformaXML::Test.new( files: test_files2, meta_data: { CodeOcean: { @@ -401,7 +401,7 @@ describe ProformaService::ConvertTaskToExercise do end let(:test_files2) { [test_file2] } let(:test_file2) do - Proforma::TaskFile.new( + ProformaXML::TaskFile.new( id: 'test_file_id2', content: 'testfile-content', filename: 'testfile.txt', @@ -450,7 +450,7 @@ describe ProformaService::ConvertTaskToExercise do context 'with file, model solution and test' do let(:files) { [file] } let(:file) do - Proforma::TaskFile.new( + ProformaXML::TaskFile.new( id: 'id', content: 'content', filename: 'filename.txt', @@ -462,7 +462,7 @@ describe ProformaService::ConvertTaskToExercise do end let(:tests) { [test] } let(:test) do - Proforma::Test.new( + ProformaXML::Test.new( id: 'test-id', title: 'title', description: 'description', @@ -479,7 +479,7 @@ describe ProformaService::ConvertTaskToExercise do end let(:test_files) { [test_file] } let(:test_file) do - Proforma::TaskFile.new( + ProformaXML::TaskFile.new( id: 'test_file_id', content: 'testfile-content', filename: 'testfile.txt', @@ -492,14 +492,14 @@ describe ProformaService::ConvertTaskToExercise do end let(:model_solutions) { [model_solution] } let(:model_solution) do - Proforma::ModelSolution.new( + ProformaXML::ModelSolution.new( id: 'ms-id', files: ms_files ) end let(:ms_files) { [ms_file] } let(:ms_file) do - Proforma::TaskFile.new( + ProformaXML::TaskFile.new( id: 'ms-file', content: 'ms-content', filename: 'filename.txt', diff --git a/spec/services/proforma_service/export_task_spec.rb b/spec/services/proforma_service/export_task_spec.rb index 662a2462..0b26f70b 100644 --- a/spec/services/proforma_service/export_task_spec.rb +++ b/spec/services/proforma_service/export_task_spec.rb @@ -24,13 +24,13 @@ describe ProformaService::ExportTask do describe '#execute' do subject(:export_task) { described_class.call(exercise:) } - let(:task) { Proforma::Task.new } + let(:task) { ProformaXML::Task.new } let(:exercise) { build(:dummy) } - let(:exporter) { instance_double(Proforma::Exporter, perform: 'zip') } + let(:exporter) { instance_double(ProformaXML::Exporter, perform: 'zip') } before do allow(ProformaService::ConvertExerciseToTask).to receive(:call).with(exercise:).and_return(task) - allow(Proforma::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:, custom_namespaces: [{prefix: 'CodeOcean', uri: 'codeocean.openhpi.de'}]).and_return(exporter) end it do diff --git a/spec/services/proforma_service/import_spec.rb b/spec/services/proforma_service/import_spec.rb index 3297ffd6..ce1df2a2 100644 --- a/spec/services/proforma_service/import_spec.rb +++ b/spec/services/proforma_service/import_spec.rb @@ -160,7 +160,7 @@ describe ProformaService::Import do let(:import_user) { create(:teacher) } it 'raises a proforma error' do - expect { imported_exercise.save! }.to raise_error Proforma::ExerciseNotOwned + expect { imported_exercise.save! }.to raise_error ProformaXML::ExerciseNotOwned end end end